source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Attenuation.ipf @ 1113

Last change on this file since 1113 was 1113, checked in by srkline, 4 years ago

minor changes

File size: 7.0 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6// 7-NOV-2017
7//
8// The attenuator tables are more complex now - since there are more ways to select wavelength
9// - there is the standard velocity selector (no tilt)
10// - a white beam mode (with a non-symmetric distribution)
11// - a graphite monochromator, allowing wavelength selection
12//
13// To accomodate this, I have chosen to alter the table to allow all of the wavelength "modes"
14// to be in the same table for interpolation, by use of the "correct" input wavelength
15// velocity_selector lambda is input as is
16// white beam lambda = (lambda * 1e3)
17// graphite crystal lambda = (lambda * 1e6)
18//
19// in this way, the interpolation will work just fine. Otherwise, the only solution I could see was to
20// have separate tables stored in the header for each of the "modes".
21//
22//
23
24//
25// functions to calculate attenuator values from the tables
26//
27// V_CalculateAttenuationFactor(fname)
28// V_CalculateAttenuationError(fname)
29//
30// interpolate if necessary
31//
32
33//
34// patch entire tables if necessary
35//
36//
37// attenuator tables are currently /N=(n,17)
38
39
40Proc V_LoadCSVAttenTable()
41
42        // this load command will:
43        // load CSV data into a matrix
44        // skip a one-line header
45        // name it "atten0"
46        // prompt for file
47        LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0}                            //will prompt for the file, auto name
48       
49        Rename atten0, atten_values
50
51End
52
53Proc V_LoadCSVAttenErrTable()
54
55        // this load command will:
56        // load CSV data into a matrix
57        // skip a one-line header
58        // name it "atten0"
59        // prompt for file
60        LoadWave/J/M/D/A=atten/E=1/K=1/L={0,1,0,0,0}                            //will prompt for the file, auto name
61       
62        Rename atten0, atten_err
63
64End
65
66// V_writeAttenIndex_table(fname,inW)
67//
68// V_writeAttenIndex_table_err(fname,inW)
69//
70
71Proc V_WriteCSVAttenTable(lo,hi,atten_values)
72        Variable lo,hi
73        String atten_values="atten_values"
74
75        V_fPatchAttenValueTable(lo,hi,$atten_values)
76End
77
78Proc V_WriteCSVAttenErrTable(lo,hi,atten_err)
79        Variable lo,hi
80        String atten_err="atten_err"
81
82        V_fPatchAttenErrTable(lo,hi,$atten_err)
83End
84
85
86// simple utility to patch the attenuator table wave in the file headers
87// lo is the first file number
88// hi is the last file number (inclusive)
89//
90Function V_fPatchAttenValueTable(lo,hi,attenW)
91        Variable lo,hi
92        Wave attenW
93       
94        Variable ii
95        String fname
96       
97//      // check the dimensions of the attenW (8,17)
98//      if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 )
99//              Abort "attenuator wave is not of proper dimension (8,17)"
100//      endif
101       
102        //loop over all files
103        for(ii=lo;ii<=hi;ii+=1)
104                fname = V_FindFileFromRunNumber(ii)
105                if(strlen(fname) != 0)
106                        V_writeAttenIndex_table(fname,attenW)                   
107                else
108                        printf "run number %d not found\r",ii
109                endif
110        endfor
111       
112        return(0)
113End
114
115// simple utility to patch the attenuator error (std dev) wave in the file headers
116// lo is the first file number
117// hi is the last file number (inclusive)
118//
119Function V_fPatchAttenErrTable(lo,hi,attenW)
120        Variable lo,hi
121        Wave attenW
122       
123        Variable ii
124        String fname
125       
126//      // check the dimensions of the attenW (8,17)
127//      if (DimSize(attenW, 0) != 8 || DimSize(attenW, 1) != 17 )
128//              Abort "attenuator wave is not of proper dimension (8,17)"
129//      endif
130       
131        //loop over all files
132        for(ii=lo;ii<=hi;ii+=1)
133                fname = V_FindFileFromRunNumber(ii)
134                if(strlen(fname) != 0)
135                        V_writeAttenIndex_table_err(fname,attenW)                       
136                else
137                        printf "run number %d not found\r",ii
138                endif
139        endfor
140       
141        return(0)
142End
143
144
145
146//////////////////////
147//
148// function to calculate the attenuation factor from the table in the file
149//
150// fill in a "dummy" wavelength for White Beam and graphite
151// *= 1e3 for White Beam
152// *= 1e6 for graphite (***NO***) Per John, we can use the VS calibration for HOPG
153// use these dummy values just for the lookup table
154//
155// TODO -- need the enumerated values for the monochromator type
156// TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE
157// TODO -- determine the dimensions of the wave, don't hard-wire
158// TODO -- update to use separate tables for each monochromator mode
159// TODO -- (same updates for the error table)
160//
161Function V_CalculateAttenuationFactor(fname)
162        String fname
163       
164        Variable val,lambda,numAtt
165        String monoType
166       
167        numAtt = V_getAtten_number(fname)
168        lambda = V_getWavelength(fname)
169       
170        // TODO -- need to switch on "type"
171        //  == velocity_selector || ?? for white beam || graphite
172//      monoType = V_getMonochromatorType(fname)
173
174        monoType = V_DeduceMonochromatorType(fname)
175        print monoType
176
177        // set a fake wavelength for the interpolation or get out
178        strswitch(monoType)     // string switch
179                case "velocity_selector":       // execute if case matches expression
180                        // use lambda as-is
181                        break           // exit from switch
182                case "white_beam":      // execute if case matches expression
183                        lambda *= 1e3
184                        break
185                case "crystal":
186
187//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
188
189                        break
190                default:                        // optional default expression executed
191                        Abort "Monochromator type could not be determined in V_CalculateAttenuationFactor"              // when no case matches
192        endswitch
193       
194       
195        Wave w = V_getAttenIndex_table(fname)           // N=(x,17)
196        Variable num = DimSize(w,0)
197        Make/O/D/N=(num) tmpVal,tmpLam                                         
198       
199        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
200        tmpLam = w[p][0]
201        val = interp(lambda, tmpLam, tmpVal )
202        Print "Calculated Atten = ",val
203       
204        //killwaves/Z tmpVal,tmpLam
205        return(val)
206       
207End
208
209//////////////////////
210//
211// function to calculate the attenuation error from the table in the file
212//
213// fill in a "dummy" wavelength for White Beam and graphite
214// *= 1e3 for White Beam
215// *= 1e6 for graphite (***NO***) Per John, we can use the VS calibration for HOPG
216// use these dummy values just for the lookup table
217//
218// TODO -- need the enumerated values for the monochromator type
219// TODO -- V_getMonochromatorType(fname) is NOT written correctly by NICE
220//
221//
222Function V_CalculateAttenuationError(fname)
223        String fname
224       
225        Variable val,lambda,numAtt
226        String monoType
227       
228        numAtt = V_getAtten_number(fname)
229        lambda = V_getWavelength(fname)
230       
231        // TODO -- need to switch on "type"
232        //  == velocity_selector || ?? for white beam || crystal
233//      monoType = V_getMonochromatorType(fname)
234       
235        monoType = V_DeduceMonochromatorType(fname)
236        print monoType
237        // set a fake wavelength for the interpolation or get out
238        strswitch(monoType)     // string switch
239                case "velocity_selector":       // execute if case matches expression
240                        // use lambda as-is
241                        break           // exit from switch
242                case "white_beam":      // execute if case matches expression
243                        lambda *= 1e3
244                        break
245                case "crystal":
246
247//                      lambda *= 1e6           // as of July 2018, use the velocity selector tables for the graphite
248
249                        break
250                default:                        // optional default expression executed
251                        Abort "Monochromator type could not be determined in V_CalculateAttenuationError"               // when no case matches
252        endswitch       
253       
254        Wave w = V_getAttenIndex_error_table(fname)             // N=(x,17)
255        Variable num = DimSize(w,0)
256        Make/O/D/N=(num) tmpVal,tmpLam
257       
258        tmpVal = w[p][numAtt+1]         // offset by one, 1st column is wavelength
259        tmpLam = w[p][0]
260        val = interp(lambda, tmpLam, tmpVal )
261       
262        //killwaves/Z tmpVal,tmpLam
263        return(val)
264       
265End
266
Note: See TracBrowser for help on using the repository browser.