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

Last change on this file since 1002 was 1002, checked in by srkline, 6 years ago

main changes here are the addition of a first pass at the file catalog, and patch panel. each of these is based on the old SANS file (for now) and has been updated to at least compile.

Much more work needs to be done to get the functionality to be what VSANS needs, both in what is important to report in the file catalog, and how to best present the patch GUI for different situations

File size: 11.0 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
101Proc 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        // remove the q=0 point from the back detector, if it's there
110        V_RemoveQ0_B(type)
111
112
113// concatenate the data sets
114        // clear the old tmp waves first, if they still exist
115        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
116        Killwaves/Z tmp_q,tmp_i,tmp_s
117        setDataFolder root:
118        V_1DConcatenate(type)
119       
120// sort the data set
121        V_TmpSort1D(type)
122       
123// write out the data set to a file
124        String/G saveName=""
125        V_GetNameForSave("")
126        V_Write1DData(type,saveName)
127
128End
129
130Proc V_GetNameForSave(str)
131        String str
132        String/G saveName=str
133End
134
135
136// blindly assumes that there is only one zero at the top of the wave
137// could be more sophisticated in the future...
138Function V_RemoveQ0_B(type)
139        String type
140       
141        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
142
143        WAVE/Z qBin = qBin_qxqy_B
144        WAVE/Z iBin = iBin_qxqy_B
145        WAVE/Z eBin = eBin_qxqy_B
146        WAVE/Z nBin = nBin_qxqy_B
147        WAVE/Z iBin2 = iBin2_qxqy_B
148
149        if(qBin[0] == 0)
150                DeletePoints 0, 1, qBin,iBin,eBin,nBin,iBin2
151        endif
152       
153        SetDataFolder root:
154        return(0)
155end
156
157
158// concatentate data in folderStr
159//
160// TODO:
161// -- this currently assumes that all of the waves exist
162// -- need robust error checking for wave existence
163// -- wave names are hard-wired and their name and location may be different in the future
164// -- if different averaging options were chosen (bin type of 2, 4 etc) then
165//    although waves may exist, they may not be the right ones to use. There
166//    will be a somewhat complex selection process
167// x- detector B is currently skipped
168//
169// this seems like a lot of extra work to do something so simple...
170//
171//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
172Function V_1DConcatenate(folderStr)
173        String folderStr
174       
175        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
176       
177        Wave/Z q_fb = qBin_qxqy_FB
178        Wave/Z q_ft = qBin_qxqy_FT
179        Wave/Z q_fl = qBin_qxqy_FL
180        Wave/Z q_fr = qBin_qxqy_FR
181        Wave/Z q_mb = qBin_qxqy_MB
182        Wave/Z q_mt = qBin_qxqy_MT
183        Wave/Z q_ml = qBin_qxqy_ML
184        Wave/Z q_mr = qBin_qxqy_MR
185        Wave/Z q_b = qBin_qxqy_B
186
187        Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
188       
189        Wave/Z i_fb = iBin_qxqy_FB
190        Wave/Z i_ft = iBin_qxqy_FT
191        Wave/Z i_fl = iBin_qxqy_FL
192        Wave/Z i_fr = iBin_qxqy_FR
193        Wave/Z i_mb = iBin_qxqy_MB
194        Wave/Z i_mt = iBin_qxqy_MT
195        Wave/Z i_ml = iBin_qxqy_ML
196        Wave/Z i_mr = iBin_qxqy_MR
197        Wave/Z i_b = iBin_qxqy_B
198       
199        Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
200
201        Wave/Z s_fb = eBin_qxqy_FB
202        Wave/Z s_ft = eBin_qxqy_FT
203        Wave/Z s_fl = eBin_qxqy_FL
204        Wave/Z s_fr = eBin_qxqy_FR
205        Wave/Z s_mb = eBin_qxqy_MB
206        Wave/Z s_mt = eBin_qxqy_MT
207        Wave/Z s_ml = eBin_qxqy_ML
208        Wave/Z s_mr = eBin_qxqy_MR
209        Wave/Z s_b = eBin_qxqy_B
210       
211        Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
212               
213//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_q"),$("root:"+folder2+":"+folder2+"_q")},tmp_q
214//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_i"),$("root:"+folder2+":"+folder2+"_i")},tmp_i
215//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_s"),$("root:"+folder2+":"+folder2+"_s")},tmp_s
216//      Concatenate/NP {$("root:"+folder1+":res0"),$("root:"+folder2+":res0")},tmp_res0
217//      Concatenate/NP {$("root:"+folder1+":res1"),$("root:"+folder2+":res1")},tmp_res1
218//      Concatenate/NP {$("root:"+folder1+":res2"),$("root:"+folder2+":res2")},tmp_res2
219//      Concatenate/NP {$("root:"+folder1+":res3"),$("root:"+folder2+":res3")},tmp_res3
220       
221//// move the concatenated result into the destination folder (killing the old stuff first)
222//      KillWaves/Z $("root:"+folder2+":"+folder2+"_q")
223//      KillWaves/Z $("root:"+folder2+":"+folder2+"_i")
224//      KillWaves/Z $("root:"+folder2+":"+folder2+"_s")
225//      KillWaves/Z $("root:"+folder2+":res0")
226//      KillWaves/Z $("root:"+folder2+":res1")
227//      KillWaves/Z $("root:"+folder2+":res2")
228//      KillWaves/Z $("root:"+folder2+":res3")
229       
230//      Duplicate/O tmp_q $("root:"+folder2+":"+folder2+"_q")
231//      Duplicate/O tmp_i $("root:"+folder2+":"+folder2+"_i")
232//      Duplicate/O tmp_s $("root:"+folder2+":"+folder2+"_s")
233//      Duplicate/O tmp_res0 $("root:"+folder2+":res0")
234//      Duplicate/O tmp_res1 $("root:"+folder2+":res1")
235//      Duplicate/O tmp_res2 $("root:"+folder2+":res2")
236//      Duplicate/O tmp_res3 $("root:"+folder2+":res3")
237
238// Can't kill here, since they are still needed to sort and write out!
239//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
240       
241        SetDataFolder root:
242       
243        return(0)               
244End
245
246// TODO:
247// -- resolution waves are ignored, since they don't exist (yet)
248// -- only a sort is done, no rescaling of data sets
249//    (it's too late now anyways, since the data was concatenated
250//
251// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
252// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
253//
254Function V_TmpSort1D(folderStr)
255        String folderStr
256       
257        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
258
259        Wave qw = tmp_q
260        Wave iw = tmp_i
261        Wave sw = tmp_s
262       
263//      Sort qw, qw,iw,sw,res0,res1,res2,res3
264
265        Sort qw, qw,iw,sw
266
267
268        SetDataFolder root:
269        return(0)
270End
271
272
273// TODO
274// -- currently, this function is NOT called by anything
275// needs:
276// -- trim the beamstop out (based on shadow)
277// -- trim out zero q from the file (bad actor in analysis functions)
278// -- trim num from the highQ end or lowQ end?
279// -- splits the res wave into individual waves in anticipation of concatenation
280//   -- or -- deal with the res wave after?
281//
282//
283//
284Function V_Trim1DData(folderStr,nEnd)
285        String folderStr
286        Variable nEnd
287
288        if(DataFolderExists("root:"+folderStr)  == 0)
289                return(0)
290        endif
291               
292        SetDataFolder $("root:"+folderStr)
293       
294        Wave qw = $(folderStr + "_q")
295        Wave iw = $(folderStr + "_i")
296        Wave sw = $(folderStr + "_s")
297        Wave res = $(folderStr + "_res")
298       
299        variable num,ii
300       
301        num=numpnts(qw)
302        //Break out resolution wave into separate waves
303        Make/O/D/N=(num) res0 = res[p][0]               // sigQ
304        Make/O/D/N=(num) res1 = res[p][1]               // qBar
305        Make/O/D/N=(num) res2 = res[p][2]               // fshad
306        Make/O/D/N=(num) res3 = res[p][3]               // qvals
307       
308        // trim off the last nEnd points from everything
309        DeletePoints num-nEnd,nEnd, qw,iw,sw,res0,res1,res2,res3
310       
311        // delete all points where the shadow is < 0.98
312        num=numpnts(qw)
313        for(ii=0;ii<num;ii+=1)
314                if(res2[ii] < 0.98)
315                        DeletePoints ii,1, qw,iw,sw,res0,res1,res2,res3
316                        num -= 1
317                        ii -= 1
318                endif
319        endfor
320       
321////Put resolution contents back???
322//              reswave[][0] = res0[p]
323//              reswave[][1] = res1[p]
324//              reswave[][2] = res2[p]
325//              reswave[][3] = res3[p]
326//             
327                       
328        SetDataFolder root:
329        return(0)
330end
331
332
333
334// TODO:
335// -- this is a temporary solution before a real writer is created
336// -- resolution is not handled here (and it shouldn't be) since resolution is not known yet.
337//
338// this will bypass save dialogs
339// -- AND WILL OVERWITE DATA WITH THE SAME NAME
340//
341Function V_Write1DData(folderStr,saveName)
342        String folderStr,saveName
343       
344        String formatStr="",fullpath=""
345        Variable refnum,dialog=1
346
347        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
348
349        Wave qw = tmp_q
350        Wave iw = tmp_i
351        Wave sw = tmp_s
352       
353        String dataSetFolderParent,basestr
354       
355        // ParseFilePath to get path without folder name
356//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
357        // ParseFilePath to get basestr
358//      basestr = ParseFilePath(0,folderStr,":",1,0)
359       
360        //make sure the waves exist
361       
362        if(WaveExists(qw) == 0)
363                Abort "q is missing"
364        endif
365        if(WaveExists(iw) == 0)
366                Abort "i is missing"
367        endif
368        if(WaveExists(sw) == 0)
369                Abort "s is missing"
370        endif
371//      if(WaveExists(resw) == 0)
372//              Abort "Resolution information is missing."
373//      endif
374       
375//      Duplicate/O qw qbar,sigQ,fs
376//      if(dimsize(resW,1) > 4)
377//              //it's USANS put -dQv back in the last 3 columns
378//              NVAR/Z dQv = USANS_dQv
379//              if(NVAR_Exists(dQv) == 0)
380//                      SetDataFolder root:
381//                      Abort "It's USANS data, and I don't know what the slit height is."
382//              endif
383//              sigQ = -dQv
384//              qbar = -dQv
385//              fs = -dQv
386//      else
387//              //it's SANS
388//              sigQ = resw[p][0]
389//              qbar = resw[p][1]
390//              fs = resw[p][2]
391//      endif
392//     
393
394        PathInfo catPathName
395        fullPath = S_Path + saveName
396
397        Open refnum as fullpath
398
399        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
400
401// TODO -- make this work for 6-columns
402//      formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
403//      fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
404//      wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
405
406        //currently, only three columns
407        formatStr = "%15.4g %15.4g %15.4g\r\n" 
408        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
409
410        wfprintf refnum,formatStr,qw,iw,sw
411        Close refnum
412       
413//      KillWaves/Z sigQ,qbar,fs
414       
415        SetDataFolder root:
416        return(0)
417End
Note: See TracBrowser for help on using the repository browser.