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

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

ADDED:

included common NCNR procedures for the PlotManager?, to allow plotting of 1D data sets using a familiar interface

greatly expanded Patch functionality to include input in the multiple sections of the Nexus file, including separate panels to handle patching of waves to the file - needed for non-linear coefficients, dead time, and XY beam centers. All patch operations are expandable as more fields become necessary to patch.

removed bug of group_id being defined in /reduction and in /sample (removed R/W that referenced /reduction)

added panel to "isolate" a single detector panel, allowing the corrections to be applied/removed/recalculated as needed to directly see their effects.

linked new procedures to their appropriate action buttons

Added more data fields (label, intent, etc.) to the VCALC to Nexus data writer to get more realistic values into the fake data files for testing

Added VCALC simulation functions with EMP and BGD in anticipation of testing the CORRECT step

more little bug and documentation fixes which I can't remember, but they are all important...

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