source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_IQ_Utilities.ipf @ 999

Last change on this file since 999 was 999, checked in by srkline, 7 years ago

changes to a few analysis models to make these Igor 7-ready

adding mask editing utilities

many changes to event mode for easier processing of split lists

updated event mode help file

+ lots more!

File size: 10.1 KB
Line 
1#pragma TextEncoding = "MacRoman"               // For details execute DisplayHelpTopic "The TextEncoding Pragma"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6//
7// does no scaling, only the basic (default) trim of the ends, concatenate, sort, and save
8//
9// TODO:
10// -- fill in all of the details...
11//
12
13
14//
15// see the VCALC BinAllMiddlePanels() for an example of this
16// see the binning routines in VC_DetectorBinning_Utils.ipf for the details
17//
18// TODO
19// x- detector "B" is currently skipped since the calibration waves are not faked
20//    when the raw data is loaded. Then the qxqyqz waves are not generated.
21//
22// -- REDO the logic here. It's a mess, and will get the calculation wrong
23//
24// -- figure out the binning type (where is it set for VSANS?)
25// -- don't know, so currently VSANS binning type is HARD-WIRED
26// -- figure out when this needs to be called to (force) re-calculate I vs Q
27//
28Function V_QBinAllPanels(folderStr)
29        String folderStr
30
31        // do the back, middle, and front separately
32       
33//      figure out the binning type (where is it set?)
34        Variable binType,ii,delQ
35        String detStr
36        binType = 1
37       
38       
39
40//// TODO:
41// x- currently the "B" detector is skipped - it was skipped in
42//       previous functions where q values are calculated       
43//     
44        delQ = SetDeltaQ(folderStr,"B")
45       
46        // dispatch based on binning type
47        if(binType == 1)
48                VC_fDoBinning_QxQy2D(folderStr, "B")            //normal binning, nothing to combine
49        endif
50
51// TODO -- this is only a temporary fix for slit mode   
52        if(binType == 4)
53                /// this is for a tall, narrow slit mode       
54                VC_fBinDetector_byRows(folderStr,"B")
55        endif   
56
57
58
59// these are the binning types where detectors are not combined
60// other combined binning is below the loop
61        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
62                detStr = StringFromList(ii, ksDetectorListNoB, ";")
63               
64                // set delta Q for binning
65                delQ = SetDeltaQ(folderStr,detStr)
66               
67                // dispatch based on binning type
68                if(binType==1)
69                        VC_fDoBinning_QxQy2D(folderStr,detStr)
70                endif
71               
72                // TODO -- this is only a temporary fix for slit mode   
73                if(binType == 4)
74                        /// this is for a tall, narrow slit mode       
75                        VC_fBinDetector_byRows(folderStr,detStr)
76                endif   
77               
78        endfor
79       
80        // bin in pairs
81        if(binType == 2)
82                VC_fDoBinning_QxQy2D(folderStr,"MLR")
83                VC_fDoBinning_QxQy2D(folderStr,"MTB")
84                VC_fDoBinning_QxQy2D(folderStr,"FLR")
85                VC_fDoBinning_QxQy2D(folderStr,"FTB")   
86        endif
87       
88        // bin everything on front or middle together
89        if(binType == 3)
90                VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
91                VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
92        endif
93
94        return(0)
95End
96
97
98
99
100
101Macro V_Combine1DData()
102
103// get the current display type
104        String type = root:Packages:NIST:VSANS:Globals:gCurDispType
105
106// figure out which binning was used
107
108// trim the data if needed
109
110// concatenate the data sets
111        V_1DConcatenate(type)
112       
113// sort the data set
114        V_TmpSort1D(type)
115       
116// write out the data set to a file
117        String/G saveName=""
118        V_GetNameForSave("")
119        V_Write1DData(type,saveName)
120
121End
122
123Proc V_GetNameForSave(str)
124        String str
125        String/G saveName=str
126End
127
128
129// concatentate data in folderStr
130//
131// TODO:
132// -- this currently assumes that all of the waves exist
133// -- need robust error checking for wave existence
134// -- wave names are hard-wired and their name and location may be different in the future
135// -- if different averaging options were chosen (bin type of 2, 4 etc) then
136//    although waves may exist, they may not be the right ones to use. There
137//    will be a somewhat complex selection process
138// -- detector B is currently skipped
139//
140// this seems like a lot of extra work to do something so simple...
141//
142//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
143Function V_1DConcatenate(folderStr)
144        String folderStr
145       
146        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
147       
148        Wave/Z q_fb = qBin_qxqy_FB
149        Wave/Z q_ft = qBin_qxqy_FT
150        Wave/Z q_fl = qBin_qxqy_FL
151        Wave/Z q_fr = qBin_qxqy_FR
152        Wave/Z q_mb = qBin_qxqy_MB
153        Wave/Z q_mt = qBin_qxqy_MT
154        Wave/Z q_ml = qBin_qxqy_ML
155        Wave/Z q_mr = qBin_qxqy_MR
156        Wave/Z q_b = qBin_qxqy_B
157
158        Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
159       
160        Wave/Z i_fb = iBin_qxqy_FB
161        Wave/Z i_ft = iBin_qxqy_FT
162        Wave/Z i_fl = iBin_qxqy_FL
163        Wave/Z i_fr = iBin_qxqy_FR
164        Wave/Z i_mb = iBin_qxqy_MB
165        Wave/Z i_mt = iBin_qxqy_MT
166        Wave/Z i_ml = iBin_qxqy_ML
167        Wave/Z i_mr = iBin_qxqy_MR
168        Wave/Z i_b = iBin_qxqy_B
169       
170        Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
171
172        Wave/Z s_fb = eBin_qxqy_FB
173        Wave/Z s_ft = eBin_qxqy_FT
174        Wave/Z s_fl = eBin_qxqy_FL
175        Wave/Z s_fr = eBin_qxqy_FR
176        Wave/Z s_mb = eBin_qxqy_MB
177        Wave/Z s_mt = eBin_qxqy_MT
178        Wave/Z s_ml = eBin_qxqy_ML
179        Wave/Z s_mr = eBin_qxqy_MR
180        Wave/Z s_b = eBin_qxqy_B
181       
182        Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
183               
184//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_q"),$("root:"+folder2+":"+folder2+"_q")},tmp_q
185//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_i"),$("root:"+folder2+":"+folder2+"_i")},tmp_i
186//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_s"),$("root:"+folder2+":"+folder2+"_s")},tmp_s
187//      Concatenate/NP {$("root:"+folder1+":res0"),$("root:"+folder2+":res0")},tmp_res0
188//      Concatenate/NP {$("root:"+folder1+":res1"),$("root:"+folder2+":res1")},tmp_res1
189//      Concatenate/NP {$("root:"+folder1+":res2"),$("root:"+folder2+":res2")},tmp_res2
190//      Concatenate/NP {$("root:"+folder1+":res3"),$("root:"+folder2+":res3")},tmp_res3
191       
192//// move the concatenated result into the destination folder (killing the old stuff first)
193//      KillWaves/Z $("root:"+folder2+":"+folder2+"_q")
194//      KillWaves/Z $("root:"+folder2+":"+folder2+"_i")
195//      KillWaves/Z $("root:"+folder2+":"+folder2+"_s")
196//      KillWaves/Z $("root:"+folder2+":res0")
197//      KillWaves/Z $("root:"+folder2+":res1")
198//      KillWaves/Z $("root:"+folder2+":res2")
199//      KillWaves/Z $("root:"+folder2+":res3")
200       
201//      Duplicate/O tmp_q $("root:"+folder2+":"+folder2+"_q")
202//      Duplicate/O tmp_i $("root:"+folder2+":"+folder2+"_i")
203//      Duplicate/O tmp_s $("root:"+folder2+":"+folder2+"_s")
204//      Duplicate/O tmp_res0 $("root:"+folder2+":res0")
205//      Duplicate/O tmp_res1 $("root:"+folder2+":res1")
206//      Duplicate/O tmp_res2 $("root:"+folder2+":res2")
207//      Duplicate/O tmp_res3 $("root:"+folder2+":res3")
208
209//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
210       
211        SetDataFolder root:
212       
213        return(0)               
214End
215
216// TODO:
217// -- resolution waves are ignored
218// -- only a sort is done, no rescaling of data sets
219//    (it's too late now anyways, since the data was concatenated
220//
221// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
222// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
223//
224Function V_TmpSort1D(folderStr)
225        String folderStr
226       
227        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
228
229        Wave qw = tmp_q
230        Wave iw = tmp_i
231        Wave sw = tmp_s
232       
233//      Sort qw, qw,iw,sw,res0,res1,res2,res3
234
235        Sort qw, qw,iw,sw
236
237
238        SetDataFolder root:
239        return(0)
240End
241
242
243// trims the beamstop out (based on shadow)
244// trims num from the highQ end
245// splits the res wave into individual waves in anticipation of concatenation
246//
247Function V_Trim1DData(folderStr,nEnd)
248        String folderStr
249        Variable nEnd
250
251        if(DataFolderExists("root:"+folderStr)  == 0)
252                return(0)
253        endif
254               
255        SetDataFolder $("root:"+folderStr)
256       
257        Wave qw = $(folderStr + "_q")
258        Wave iw = $(folderStr + "_i")
259        Wave sw = $(folderStr + "_s")
260        Wave res = $(folderStr + "_res")
261       
262        variable num,ii
263       
264        num=numpnts(qw)
265        //Break out resolution wave into separate waves
266        Make/O/D/N=(num) res0 = res[p][0]               // sigQ
267        Make/O/D/N=(num) res1 = res[p][1]               // qBar
268        Make/O/D/N=(num) res2 = res[p][2]               // fshad
269        Make/O/D/N=(num) res3 = res[p][3]               // qvals
270       
271        // trim off the last nEnd points from everything
272        DeletePoints num-nEnd,nEnd, qw,iw,sw,res0,res1,res2,res3
273       
274        // delete all points where the shadow is < 0.98
275        num=numpnts(qw)
276        for(ii=0;ii<num;ii+=1)
277                if(res2[ii] < 0.98)
278                        DeletePoints ii,1, qw,iw,sw,res0,res1,res2,res3
279                        num -= 1
280                        ii -= 1
281                endif
282        endfor
283       
284////Put resolution contents back???
285//              reswave[][0] = res0[p]
286//              reswave[][1] = res1[p]
287//              reswave[][2] = res2[p]
288//              reswave[][3] = res3[p]
289//             
290                       
291        SetDataFolder root:
292        return(0)
293end
294
295
296
297// TODO:
298// -- this is a temporary solution before a real writer is created
299// -- resolution is not handled here (and it shouldn't be) since resolution is not known yet.
300//
301// this will bypass save dialogs
302// -- AND WILL OVERWITE DATA WITH THE SAME NAME
303//
304Function V_Write1DData(folderStr,saveName)
305        String folderStr,saveName
306       
307        String formatStr="",fullpath=""
308        Variable refnum,dialog=1
309
310        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
311
312        Wave qw = tmp_q
313        Wave iw = tmp_i
314        Wave sw = tmp_s
315       
316        String dataSetFolderParent,basestr
317       
318        // ParseFilePath to get path without folder name
319//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
320        // ParseFilePath to get basestr
321//      basestr = ParseFilePath(0,folderStr,":",1,0)
322       
323        //make sure the waves exist
324       
325        if(WaveExists(qw) == 0)
326                Abort "q is missing"
327        endif
328        if(WaveExists(iw) == 0)
329                Abort "i is missing"
330        endif
331        if(WaveExists(sw) == 0)
332                Abort "s is missing"
333        endif
334//      if(WaveExists(resw) == 0)
335//              Abort "Resolution information is missing."
336//      endif
337       
338//      Duplicate/O qw qbar,sigQ,fs
339//      if(dimsize(resW,1) > 4)
340//              //it's USANS put -dQv back in the last 3 columns
341//              NVAR/Z dQv = USANS_dQv
342//              if(NVAR_Exists(dQv) == 0)
343//                      SetDataFolder root:
344//                      Abort "It's USANS data, and I don't know what the slit height is."
345//              endif
346//              sigQ = -dQv
347//              qbar = -dQv
348//              fs = -dQv
349//      else
350//              //it's SANS
351//              sigQ = resw[p][0]
352//              qbar = resw[p][1]
353//              fs = resw[p][2]
354//      endif
355//     
356
357        PathInfo catPathName
358        fullPath = S_Path + saveName
359
360        Open refnum as fullpath
361
362        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
363
364// TODO -- make this work for 6-columns
365//      formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
366//      fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
367//      wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
368
369        //currently, only three columns
370        formatStr = "%15.4g %15.4g %15.4g\r\n" 
371        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
372
373        wfprintf refnum,formatStr,qw,iw,sw
374        Close refnum
375       
376//      KillWaves/Z sigQ,qbar,fs
377       
378        SetDataFolder root:
379        return(0)
380End
Note: See TracBrowser for help on using the repository browser.