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

Last change on this file since 1203 was 1203, checked in by srkline, 3 years ago

Corrected attenuator table for VSANS to include the range 4.52->19. Patching of the attenuation factor is disabled since the factor is always calculated rather than read from the file.

Added a few help links in preparation for the full help file integration

Added a "super" white beam distribution definition and a single model function for testing of this new mode. Still need the normalization and mean wavelength for the distribution + a way to identify it in the file metadata.

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