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

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

adding to the functionality of the data reduction protocol

getting the 1D plotting to work both as a standalone plot and part of the reduction protocol (where the choices are all made and fed in)

added log/lin toggle to 1D display. abc exponent scaling is fundamentally more messy, and has been shelved for now. Revisit if demand is there.

fixed bug in how raw data files are identified, to prevent .abs files from being incorrectly identified as raw (if same name before extension). Works correctly now, but may need tweak in future if naming scheme changes.

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