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

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

changes for combining of 1D data sets

File size: 13.8 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        //kill these waves before starting, or the new concatenation will be added to the old
225        KillWaves/Z tmp_q,tmp_i,tmp_s
226       
227        if(binType == 1)       
228                Wave/Z q_fb = qBin_qxqy_FB
229                Wave/Z q_ft = qBin_qxqy_FT
230                Wave/Z q_fl = qBin_qxqy_FL
231                Wave/Z q_fr = qBin_qxqy_FR
232                Wave/Z q_mb = qBin_qxqy_MB
233                Wave/Z q_mt = qBin_qxqy_MT
234                Wave/Z q_ml = qBin_qxqy_ML
235                Wave/Z q_mr = qBin_qxqy_MR
236                Wave/Z q_b = qBin_qxqy_B
237       
238                Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
239               
240                Wave/Z i_fb = iBin_qxqy_FB
241                Wave/Z i_ft = iBin_qxqy_FT
242                Wave/Z i_fl = iBin_qxqy_FL
243                Wave/Z i_fr = iBin_qxqy_FR
244                Wave/Z i_mb = iBin_qxqy_MB
245                Wave/Z i_mt = iBin_qxqy_MT
246                Wave/Z i_ml = iBin_qxqy_ML
247                Wave/Z i_mr = iBin_qxqy_MR
248                Wave/Z i_b = iBin_qxqy_B
249               
250                Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
251       
252                Wave/Z s_fb = eBin_qxqy_FB
253                Wave/Z s_ft = eBin_qxqy_FT
254                Wave/Z s_fl = eBin_qxqy_FL
255                Wave/Z s_fr = eBin_qxqy_FR
256                Wave/Z s_mb = eBin_qxqy_MB
257                Wave/Z s_mt = eBin_qxqy_MT
258                Wave/Z s_ml = eBin_qxqy_ML
259                Wave/Z s_mr = eBin_qxqy_MR
260                Wave/Z s_b = eBin_qxqy_B
261               
262                Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
263        endif
264
265        if(binType == 2)       
266                Wave/Z q_ftb = qBin_qxqy_FTB
267                Wave/Z q_flr = qBin_qxqy_FLR
268                Wave/Z q_mtb = qBin_qxqy_MTB
269                Wave/Z q_mlr = qBin_qxqy_MLR
270                Wave/Z q_b = qBin_qxqy_B
271       
272                Concatenate/NP {q_ftb,q_flr,q_mtb,q_mlr,q_b}, tmp_q
273               
274                Wave/Z i_ftb = iBin_qxqy_FTB
275                Wave/Z i_flr = iBin_qxqy_FLR
276                Wave/Z i_mtb = iBin_qxqy_MTB
277                Wave/Z i_mlr = iBin_qxqy_MLR
278                Wave/Z i_b = iBin_qxqy_B
279               
280                Concatenate/NP {i_ftb,i_flr,i_mtb,i_mlr,i_b}, tmp_i
281       
282                Wave/Z s_ftb = eBin_qxqy_FTB
283                Wave/Z s_flr = eBin_qxqy_FLR
284                Wave/Z s_mtb = eBin_qxqy_MTB
285                Wave/Z s_mlr = eBin_qxqy_MLR
286                Wave/Z s_b = eBin_qxqy_B
287               
288                Concatenate/NP {s_ftb,s_flr,s_mtb,s_mlr,s_b}, tmp_s
289        endif
290
291        if(binType == 3)       
292                Wave/Z q_flrtb = qBin_qxqy_FLRTB
293                Wave/Z q_mlrtb = qBin_qxqy_MLRTB
294                Wave/Z q_b = qBin_qxqy_B
295       
296                Concatenate/NP {q_flrtb,q_mlrtb,q_b}, tmp_q
297               
298                Wave/Z i_flrtb = iBin_qxqy_FLRTB
299                Wave/Z i_mlrtb = iBin_qxqy_MLRTB
300                Wave/Z i_b = iBin_qxqy_B
301               
302                Concatenate/NP {i_flrtb,i_mlrtb,i_b}, tmp_i
303       
304                Wave/Z s_flrtb = eBin_qxqy_FLRTB
305                Wave/Z s_mlrtb = eBin_qxqy_MLRTB
306                Wave/Z s_b = eBin_qxqy_B
307               
308                Concatenate/NP {s_flrtb,s_mlrtb,s_b}, tmp_s
309        endif
310
311// TODO - This is the identical set of waves as for the case of binType = 1.
312// they have the same names, but are averaged differently since it's slit mode.
313// I have separated this, since in practice the TB panels are probably best to ignore
314// and NOT include in the averaging since the Qy range is so limited.
315        if(binType == 4)       
316                Wave/Z q_fb = qBin_qxqy_FB
317                Wave/Z q_ft = qBin_qxqy_FT
318                Wave/Z q_fl = qBin_qxqy_FL
319                Wave/Z q_fr = qBin_qxqy_FR
320                Wave/Z q_mb = qBin_qxqy_MB
321                Wave/Z q_mt = qBin_qxqy_MT
322                Wave/Z q_ml = qBin_qxqy_ML
323                Wave/Z q_mr = qBin_qxqy_MR
324                Wave/Z q_b = qBin_qxqy_B
325       
326                Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
327               
328                Wave/Z i_fb = iBin_qxqy_FB
329                Wave/Z i_ft = iBin_qxqy_FT
330                Wave/Z i_fl = iBin_qxqy_FL
331                Wave/Z i_fr = iBin_qxqy_FR
332                Wave/Z i_mb = iBin_qxqy_MB
333                Wave/Z i_mt = iBin_qxqy_MT
334                Wave/Z i_ml = iBin_qxqy_ML
335                Wave/Z i_mr = iBin_qxqy_MR
336                Wave/Z i_b = iBin_qxqy_B
337               
338                Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
339       
340                Wave/Z s_fb = eBin_qxqy_FB
341                Wave/Z s_ft = eBin_qxqy_FT
342                Wave/Z s_fl = eBin_qxqy_FL
343                Wave/Z s_fr = eBin_qxqy_FR
344                Wave/Z s_mb = eBin_qxqy_MB
345                Wave/Z s_mt = eBin_qxqy_MT
346                Wave/Z s_ml = eBin_qxqy_ML
347                Wave/Z s_mr = eBin_qxqy_MR
348                Wave/Z s_b = eBin_qxqy_B
349               
350                Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
351        endif
352
353
354
355
356// Can't kill here, since they are still needed to sort and write out!
357//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
358       
359        SetDataFolder root:
360       
361        return(0)               
362End
363
364// TODO:
365// -- resolution waves are ignored, since they don't exist (yet)
366// -- only a sort is done, no rescaling of data sets
367//    (it's too late now anyways, since the data was concatenated)
368//
369// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
370// how to combine the resolution waves (they also need to be concatenated, which is currently not done)
371//
372Function V_TmpSort1D(folderStr)
373        String folderStr
374       
375        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
376
377        Wave qw = tmp_q
378        Wave iw = tmp_i
379        Wave sw = tmp_s
380       
381//      Sort qw, qw,iw,sw,res0,res1,res2,res3
382
383        Sort qw, qw,iw,sw
384
385
386        SetDataFolder root:
387        return(0)
388End
389
390
391// TODO
392// -- currently, this function is NOT called by anything
393// needs:
394// -- trim the beamstop out (based on shadow)
395// -- trim out zero q from the file (bad actor in analysis functions)
396// -- trim num from the highQ end or lowQ end?
397// -- splits the res wave into individual waves in anticipation of concatenation
398//   -- or -- deal with the res wave after?
399//
400//
401//
402Function V_Trim1DData(folderStr,nEnd)
403        String folderStr
404        Variable nEnd
405
406        if(DataFolderExists("root:"+folderStr)  == 0)
407                return(0)
408        endif
409               
410        SetDataFolder $("root:"+folderStr)
411       
412        Wave qw = $(folderStr + "_q")
413        Wave iw = $(folderStr + "_i")
414        Wave sw = $(folderStr + "_s")
415        Wave res = $(folderStr + "_res")
416       
417        variable num,ii
418       
419        num=numpnts(qw)
420        //Break out resolution wave into separate waves
421        Make/O/D/N=(num) res0 = res[p][0]               // sigQ
422        Make/O/D/N=(num) res1 = res[p][1]               // qBar
423        Make/O/D/N=(num) res2 = res[p][2]               // fshad
424        Make/O/D/N=(num) res3 = res[p][3]               // qvals
425       
426        // trim off the last nEnd points from everything
427        DeletePoints num-nEnd,nEnd, qw,iw,sw,res0,res1,res2,res3
428       
429        // delete all points where the shadow is < 0.98
430        num=numpnts(qw)
431        for(ii=0;ii<num;ii+=1)
432                if(res2[ii] < 0.98)
433                        DeletePoints ii,1, qw,iw,sw,res0,res1,res2,res3
434                        num -= 1
435                        ii -= 1
436                endif
437        endfor
438       
439////Put resolution contents back???
440//              reswave[][0] = res0[p]
441//              reswave[][1] = res1[p]
442//              reswave[][2] = res2[p]
443//              reswave[][3] = res3[p]
444//             
445                       
446        SetDataFolder root:
447        return(0)
448end
449
450
451
452// TODO:
453// -- this is a temporary solution before a real writer is created
454// -- resolution is not handled here (and it shouldn't be) since resolution is not known yet.
455//
456// this will bypass save dialogs
457// -- AND WILL OVERWITE DATA WITH THE SAME NAME
458//
459Function V_Write1DData(folderStr,saveName)
460        String folderStr,saveName
461       
462        String formatStr="",fullpath=""
463        Variable refnum,dialog=1
464
465        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
466
467        Wave qw = tmp_q
468        Wave iw = tmp_i
469        Wave sw = tmp_s
470       
471        String dataSetFolderParent,basestr
472       
473        // ParseFilePath to get path without folder name
474//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
475        // ParseFilePath to get basestr
476//      basestr = ParseFilePath(0,folderStr,":",1,0)
477       
478        //make sure the waves exist
479       
480        if(WaveExists(qw) == 0)
481                Abort "q is missing"
482        endif
483        if(WaveExists(iw) == 0)
484                Abort "i is missing"
485        endif
486        if(WaveExists(sw) == 0)
487                Abort "s is missing"
488        endif
489//      if(WaveExists(resw) == 0)
490//              Abort "Resolution information is missing."
491//      endif
492       
493//      Duplicate/O qw qbar,sigQ,fs
494//      if(dimsize(resW,1) > 4)
495//              //it's USANS put -dQv back in the last 3 columns
496//              NVAR/Z dQv = USANS_dQv
497//              if(NVAR_Exists(dQv) == 0)
498//                      SetDataFolder root:
499//                      Abort "It's USANS data, and I don't know what the slit height is."
500//              endif
501//              sigQ = -dQv
502//              qbar = -dQv
503//              fs = -dQv
504//      else
505//              //it's SANS
506//              sigQ = resw[p][0]
507//              qbar = resw[p][1]
508//              fs = resw[p][2]
509//      endif
510//     
511
512        PathInfo catPathName
513        fullPath = S_Path + saveName
514
515        Open refnum as fullpath
516
517        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
518
519// TODO -- make this work for 6-columns
520//      formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
521//      fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
522//      wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
523
524        //currently, only three columns
525        formatStr = "%15.4g %15.4g %15.4g\r\n" 
526        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
527
528        wfprintf refnum,formatStr,qw,iw,sw
529        Close refnum
530       
531//      KillWaves/Z sigQ,qbar,fs
532       
533        SetDataFolder root:
534        return(0)
535End
Note: See TracBrowser for help on using the repository browser.