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

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

First pass at routines to interactively combine and mask VSANS 1-D data sets. Based on masking as done in the USANS Desmearing panel.

File size: 13.7 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// Operation does no scaling, only the basic (default) trim of the ends, concatenate, sort, and save
7// -- if data has been converted to WORK and the solid angle correction was done, then the data
8//   is per unit solid angle, and matches up - at least the simulated data does...
9//   It should match up in real VSANS data since the flux conditions are identical for
10//   all panels, only the geometry is different.
11//
12//
13// V_DataPlotting.ipf is where the I(q) panel is drawn and the binning is set
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
19// TODO
20//
21// -- verify the binning for slit mode. Looks correct, but verify
22// -- DOCUMENT
23//
24// x- detector "B" is currently skipped since the calibration waves are not faked
25//    when the raw data is loaded. Then the qxqyqz waves are not generated.
26//
27// x- REDO the logic here. It's a mess, and will get the calculation wrong
28//
29// x- figure out the binning type (where is it set for VSANS?)
30// x- don't know, so currently VSANS binning type is HARD-WIRED
31// x- figure out when this needs to be called to (force) re-calculate I vs Q
32//
33
34
35Function V_QBinAllPanels(folderStr,binType)
36        String folderStr
37        Variable binType
38
39        // do the back, middle, and front separately
40       
41//      figure out the binning type (where is it set?)
42        Variable ii,delQ
43        String detStr
44
45//      binType = V_GetBinningPopMode()
46
47//// TODO:
48//
49//     
50        delQ = SetDeltaQ(folderStr,"B")
51       
52        // dispatch based on binning type
53        if(binType == 1 || binType == 2 || binType == 3)
54                VC_fDoBinning_QxQy2D(folderStr, "B")            //normal binning, nothing to combine
55        endif
56
57// TODO -- this is only a temporary fix for slit mode   
58        if(binType == 4)
59                /// this is for a tall, narrow slit mode       
60                VC_fBinDetector_byRows(folderStr,"B")
61        endif   
62
63
64
65// these are the binning types where detectors are not combined
66// other combined binning is below the loop
67        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
68                detStr = StringFromList(ii, ksDetectorListNoB, ";")
69               
70                // set delta Q for binning
71                delQ = SetDeltaQ(folderStr,detStr)
72               
73                // dispatch based on binning type
74                if(binType==1)
75                        VC_fDoBinning_QxQy2D(folderStr,detStr)
76                endif
77               
78                // TODO -- this is only a temporary fix for slit mode   
79                if(binType == 4)
80                        /// this is for a tall, narrow slit mode       
81                        VC_fBinDetector_byRows(folderStr,detStr)
82                endif   
83               
84        endfor
85       
86        // bin in pairs
87        if(binType == 2)
88                VC_fDoBinning_QxQy2D(folderStr,"MLR")
89                VC_fDoBinning_QxQy2D(folderStr,"MTB")
90                VC_fDoBinning_QxQy2D(folderStr,"FLR")
91                VC_fDoBinning_QxQy2D(folderStr,"FTB")   
92        endif
93       
94        // bin everything on front or middle together
95        if(binType == 3)
96                VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
97                VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
98        endif
99
100        return(0)
101End
102
103// concatenates and sorts the 1D data in "type" WORK folder
104// uses the current display if type==""
105//
106Function V_ConcatenateForSave(type,binType)
107        String type
108        Variable binType
109       
110// get the current display type, if null string passed in
111        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
112       
113        if(strlen(type)==0)
114                type = curType
115        endif
116
117// trim the data if needed
118        // remove the q=0 point from the back detector, if it's there
119        // does not need to know binType
120        V_RemoveQ0_B(type)
121
122// concatenate the data sets
123// TODO x- figure out which binning was used (this is done in V_1DConcatenate())
124        // clear the old tmp waves first, if they still exist
125        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
126        Killwaves/Z tmp_q,tmp_i,tmp_s
127        setDataFolder root:
128        V_1DConcatenate(type,binType)
129       
130// sort the data set
131        V_TmpSort1D(type)
132       
133        return(0)
134End
135
136//
137// this is only called from the button on the data panel
138// so the type is the currently displayed type, and the binning is from the panel
139//
140Function V_SimpleSave1DData(type,saveName)
141        String type,saveName
142
143//
144// get the current display type, if null string passed in
145        SVAR curtype = root:Packages:NIST:VSANS:Globals:gCurDispType
146        Variable binType = V_GetBinningPopMode()
147       
148        V_ConcatenateForSave(curType,binType)
149       
150// write out the data set to a file
151        if(strlen(saveName)==0)
152                Execute "V_GetNameForSave()"
153                SVAR newName = root:saveName
154                saveName = newName
155        endif
156       
157        V_Write1DData(type,saveName)
158
159End
160
161
162Proc V_GetNameForSave(str)
163        String str
164        String/G root:saveName=str
165End
166
167
168// blindly assumes that there is only one zero at the top of the wave
169// could be more sophisticated in the future...
170Function V_RemoveQ0_B(type)
171        String type
172       
173        SetDataFolder $("root:Packages:NIST:VSANS:"+type)
174
175        WAVE/Z qBin = qBin_qxqy_B
176        WAVE/Z iBin = iBin_qxqy_B
177        WAVE/Z eBin = eBin_qxqy_B
178        WAVE/Z nBin = nBin_qxqy_B
179        WAVE/Z iBin2 = iBin2_qxqy_B
180
181        if(qBin[0] == 0)
182                DeletePoints 0, 1, qBin,iBin,eBin,nBin,iBin2
183        endif
184       
185        SetDataFolder root:
186        return(0)
187end
188
189
190// concatentate data in folderStr
191//
192// TODO:
193// x- this currently ignores the binning type (one, two, etc. )
194// -- this currently assumes that all of the waves exist
195// -- need robust error checking for wave existence
196// -- wave names are hard-wired and their name and location may be different in the future
197// x- if different averaging options were chosen (bin type of 2, 4 etc) then
198//    although waves may exist, they may not be the right ones to use. There
199//    will be a somewhat complex selection process
200// x- detector B is currently skipped
201//
202// this seems like a lot of extra work to do something so simple...but it's better than a loop
203//
204//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
205//
206// binType = 1 = one
207// binType = 2 = two
208// binType = 3 = four
209// binType = 4 = Slit Mode
210//
211// if binType is passed in as -9999, get the binning mode from the popup
212// otherwise the value is assumed good (from a protocol)
213//
214Function V_1DConcatenate(folderStr,binType)
215        String folderStr
216        Variable binType
217       
218        if(binType==-9999)
219                binType = V_GetBinningPopMode()
220        endif   
221       
222        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
223
224        if(binType == 1)       
225                Wave/Z q_fb = qBin_qxqy_FB
226                Wave/Z q_ft = qBin_qxqy_FT
227                Wave/Z q_fl = qBin_qxqy_FL
228                Wave/Z q_fr = qBin_qxqy_FR
229                Wave/Z q_mb = qBin_qxqy_MB
230                Wave/Z q_mt = qBin_qxqy_MT
231                Wave/Z q_ml = qBin_qxqy_ML
232                Wave/Z q_mr = qBin_qxqy_MR
233                Wave/Z q_b = qBin_qxqy_B
234       
235                Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
236               
237                Wave/Z i_fb = iBin_qxqy_FB
238                Wave/Z i_ft = iBin_qxqy_FT
239                Wave/Z i_fl = iBin_qxqy_FL
240                Wave/Z i_fr = iBin_qxqy_FR
241                Wave/Z i_mb = iBin_qxqy_MB
242                Wave/Z i_mt = iBin_qxqy_MT
243                Wave/Z i_ml = iBin_qxqy_ML
244                Wave/Z i_mr = iBin_qxqy_MR
245                Wave/Z i_b = iBin_qxqy_B
246               
247                Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
248       
249                Wave/Z s_fb = eBin_qxqy_FB
250                Wave/Z s_ft = eBin_qxqy_FT
251                Wave/Z s_fl = eBin_qxqy_FL
252                Wave/Z s_fr = eBin_qxqy_FR
253                Wave/Z s_mb = eBin_qxqy_MB
254                Wave/Z s_mt = eBin_qxqy_MT
255                Wave/Z s_ml = eBin_qxqy_ML
256                Wave/Z s_mr = eBin_qxqy_MR
257                Wave/Z s_b = eBin_qxqy_B
258               
259                Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
260        endif
261
262        if(binType == 2)       
263                Wave/Z q_ftb = qBin_qxqy_FTB
264                Wave/Z q_flr = qBin_qxqy_FLR
265                Wave/Z q_mtb = qBin_qxqy_MTB
266                Wave/Z q_mlr = qBin_qxqy_MLR
267                Wave/Z q_b = qBin_qxqy_B
268       
269                Concatenate/NP {q_ftb,q_flr,q_mtb,q_mlr,q_b}, tmp_q
270               
271                Wave/Z i_ftb = iBin_qxqy_FTB
272                Wave/Z i_flr = iBin_qxqy_FLR
273                Wave/Z i_mtb = iBin_qxqy_MTB
274                Wave/Z i_mlr = iBin_qxqy_MLR
275                Wave/Z i_b = iBin_qxqy_B
276               
277                Concatenate/NP {i_ftb,i_flr,i_mtb,i_mlr,i_b}, tmp_i
278       
279                Wave/Z s_ftb = eBin_qxqy_FTB
280                Wave/Z s_flr = eBin_qxqy_FLR
281                Wave/Z s_mtb = eBin_qxqy_MTB
282                Wave/Z s_mlr = eBin_qxqy_MLR
283                Wave/Z s_b = eBin_qxqy_B
284               
285                Concatenate/NP {s_ftb,s_flr,s_mtb,s_mlr,s_b}, tmp_s
286        endif
287
288        if(binType == 3)       
289                Wave/Z q_flrtb = qBin_qxqy_FLRTB
290                Wave/Z q_mlrtb = qBin_qxqy_MLRTB
291                Wave/Z q_b = qBin_qxqy_B
292       
293                Concatenate/NP {q_flrtb,q_mlrtb,q_b}, tmp_q
294               
295                Wave/Z i_flrtb = iBin_qxqy_FLRTB
296                Wave/Z i_mlrtb = iBin_qxqy_MLRTB
297                Wave/Z i_b = iBin_qxqy_B
298               
299                Concatenate/NP {i_flrtb,i_mlrtb,i_b}, tmp_i
300       
301                Wave/Z s_flrtb = eBin_qxqy_FLRTB
302                Wave/Z s_mlrtb = eBin_qxqy_MLRTB
303                Wave/Z s_b = eBin_qxqy_B
304               
305                Concatenate/NP {s_flrtb,s_mlrtb,s_b}, tmp_s
306        endif
307
308// TODO - This is the identical set of waves as for the case of binType = 1.
309// they have the same names, but are averaged differently since it's slit mode.
310// I have separated this, since in practice the TB panels are probably best to ignore
311// and NOT include in the averaging since the Qy range is so limited.
312        if(binType == 4)       
313                Wave/Z q_fb = qBin_qxqy_FB
314                Wave/Z q_ft = qBin_qxqy_FT
315                Wave/Z q_fl = qBin_qxqy_FL
316                Wave/Z q_fr = qBin_qxqy_FR
317                Wave/Z q_mb = qBin_qxqy_MB
318                Wave/Z q_mt = qBin_qxqy_MT
319                Wave/Z q_ml = qBin_qxqy_ML
320                Wave/Z q_mr = qBin_qxqy_MR
321                Wave/Z q_b = qBin_qxqy_B
322       
323                Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
324               
325                Wave/Z i_fb = iBin_qxqy_FB
326                Wave/Z i_ft = iBin_qxqy_FT
327                Wave/Z i_fl = iBin_qxqy_FL
328                Wave/Z i_fr = iBin_qxqy_FR
329                Wave/Z i_mb = iBin_qxqy_MB
330                Wave/Z i_mt = iBin_qxqy_MT
331                Wave/Z i_ml = iBin_qxqy_ML
332                Wave/Z i_mr = iBin_qxqy_MR
333                Wave/Z i_b = iBin_qxqy_B
334               
335                Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
336       
337                Wave/Z s_fb = eBin_qxqy_FB
338                Wave/Z s_ft = eBin_qxqy_FT
339                Wave/Z s_fl = eBin_qxqy_FL
340                Wave/Z s_fr = eBin_qxqy_FR
341                Wave/Z s_mb = eBin_qxqy_MB
342                Wave/Z s_mt = eBin_qxqy_MT
343                Wave/Z s_ml = eBin_qxqy_ML
344                Wave/Z s_mr = eBin_qxqy_MR
345                Wave/Z s_b = eBin_qxqy_B
346               
347                Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
348        endif
349
350
351
352
353// Can't kill here, since they are still needed to sort and write out!
354//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
355       
356        SetDataFolder root:
357       
358        return(0)               
359End
360
361// TODO:
362// -- resolution waves are ignored, since they don't exist (yet)
363// -- only a sort is done, no rescaling of data sets
364//    (it's too late now anyways, since the data was concatenated)
365//
366// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
367// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
368//
369Function V_TmpSort1D(folderStr)
370        String folderStr
371       
372        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
373
374        Wave qw = tmp_q
375        Wave iw = tmp_i
376        Wave sw = tmp_s
377       
378//      Sort qw, qw,iw,sw,res0,res1,res2,res3
379
380        Sort qw, qw,iw,sw
381
382
383        SetDataFolder root:
384        return(0)
385End
386
387
388// TODO
389// -- currently, this function is NOT called by anything
390// needs:
391// -- trim the beamstop out (based on shadow)
392// -- trim out zero q from the file (bad actor in analysis functions)
393// -- trim num from the highQ end or lowQ end?
394// -- splits the res wave into individual waves in anticipation of concatenation
395//   -- or -- deal with the res wave after?
396//
397//
398//
399Function V_Trim1DData(folderStr,nEnd)
400        String folderStr
401        Variable nEnd
402
403        if(DataFolderExists("root:"+folderStr)  == 0)
404                return(0)
405        endif
406               
407        SetDataFolder $("root:"+folderStr)
408       
409        Wave qw = $(folderStr + "_q")
410        Wave iw = $(folderStr + "_i")
411        Wave sw = $(folderStr + "_s")
412        Wave res = $(folderStr + "_res")
413       
414        variable num,ii
415       
416        num=numpnts(qw)
417        //Break out resolution wave into separate waves
418        Make/O/D/N=(num) res0 = res[p][0]               // sigQ
419        Make/O/D/N=(num) res1 = res[p][1]               // qBar
420        Make/O/D/N=(num) res2 = res[p][2]               // fshad
421        Make/O/D/N=(num) res3 = res[p][3]               // qvals
422       
423        // trim off the last nEnd points from everything
424        DeletePoints num-nEnd,nEnd, qw,iw,sw,res0,res1,res2,res3
425       
426        // delete all points where the shadow is < 0.98
427        num=numpnts(qw)
428        for(ii=0;ii<num;ii+=1)
429                if(res2[ii] < 0.98)
430                        DeletePoints ii,1, qw,iw,sw,res0,res1,res2,res3
431                        num -= 1
432                        ii -= 1
433                endif
434        endfor
435       
436////Put resolution contents back???
437//              reswave[][0] = res0[p]
438//              reswave[][1] = res1[p]
439//              reswave[][2] = res2[p]
440//              reswave[][3] = res3[p]
441//             
442                       
443        SetDataFolder root:
444        return(0)
445end
446
447
448
449// TODO:
450// -- this is a temporary solution before a real writer is created
451// -- resolution is not handled here (and it shouldn't be) since resolution is not known yet.
452//
453// this will bypass save dialogs
454// -- AND WILL OVERWITE DATA WITH THE SAME NAME
455//
456Function V_Write1DData(folderStr,saveName)
457        String folderStr,saveName
458       
459        String formatStr="",fullpath=""
460        Variable refnum,dialog=1
461
462        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
463
464        Wave qw = tmp_q
465        Wave iw = tmp_i
466        Wave sw = tmp_s
467       
468        String dataSetFolderParent,basestr
469       
470        // ParseFilePath to get path without folder name
471//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
472        // ParseFilePath to get basestr
473//      basestr = ParseFilePath(0,folderStr,":",1,0)
474       
475        //make sure the waves exist
476       
477        if(WaveExists(qw) == 0)
478                Abort "q is missing"
479        endif
480        if(WaveExists(iw) == 0)
481                Abort "i is missing"
482        endif
483        if(WaveExists(sw) == 0)
484                Abort "s is missing"
485        endif
486//      if(WaveExists(resw) == 0)
487//              Abort "Resolution information is missing."
488//      endif
489       
490//      Duplicate/O qw qbar,sigQ,fs
491//      if(dimsize(resW,1) > 4)
492//              //it's USANS put -dQv back in the last 3 columns
493//              NVAR/Z dQv = USANS_dQv
494//              if(NVAR_Exists(dQv) == 0)
495//                      SetDataFolder root:
496//                      Abort "It's USANS data, and I don't know what the slit height is."
497//              endif
498//              sigQ = -dQv
499//              qbar = -dQv
500//              fs = -dQv
501//      else
502//              //it's SANS
503//              sigQ = resw[p][0]
504//              qbar = resw[p][1]
505//              fs = resw[p][2]
506//      endif
507//     
508
509        PathInfo catPathName
510        fullPath = S_Path + saveName
511
512        Open refnum as fullpath
513
514        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
515
516// TODO -- make this work for 6-columns
517//      formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
518//      fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
519//      wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
520
521        //currently, only three columns
522        formatStr = "%15.4g %15.4g %15.4g\r\n" 
523        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
524
525        wfprintf refnum,formatStr,qw,iw,sw
526        Close refnum
527       
528//      KillWaves/Z sigQ,qbar,fs
529       
530        SetDataFolder root:
531        return(0)
532End
Note: See TracBrowser for help on using the repository browser.