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

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

many additions.

Moved unused igor/nexus testing files to Vx_ prefix since they're garbage. Pulled out the useful bits for mask and div R/W and moved those to theire appropriate procedures.

Testing the simple correction of data, only tested basic subtraction. All of it still needs to be verified since I don't have any real header numbers and units yet.

Adjusted the columns on the file catalog to be more appropriate, and added a hook to allow loading of raw data files directly from the table and a popup contextual menu. May add more functionality to it later.

Corrected how the 1D data is plotted so that it correctly uses the binning type. I(q) save now also uses the binning as specified.

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