source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DIVUtils.ipf @ 1075

Last change on this file since 1075 was 1075, checked in by srkline, 5 years ago

changes here are mostly to facilitate the generation and display of DIV files. Set up a simple sequence to normalize DIV data sets and copy the normalized panels to the temporary folder for saving. Made a simple panel to display the 4 panels from a carriage, and to do simple subtract or divide comparison to track changes in DIV over time.

For mask drawing, made the overlay semi-transparent so that the original data can be seen through it - but kept the toggle. log/lin scaling is now based on the VSANS preference.

Adjusted the mouse tracking of the pixel on the RAW data display to properly track the T/B panels with their half-size pixels.

File size: 26.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3//
4// ********
5// TODO -- this is an incomplete DIV file. need to identify how to generate a real DIV file
6//     for the different detectors, and how to fill it into a file.
7//    Not sure how it will be measured in practice on VSANS.
8//
9//   JAN 2017
10//
11// TODO:
12// -- complete the description of the steps needed...
13// Data needs to be reduced to the "COR" level - that means that the
14// PLEX data has been added to work files, and the empty and blocked beam have been
15// subtracted off.
16// -- but what detector corrections should/ should not be done?
17// -- non-linear corrections are not needed, since this will strictly be a per-pixel correction
18// -- solid angle?
19// -- dead time?
20// -- efficiency?
21// -- large angle transmission?
22//
23// we may need to think more carefully about some of these since the front carriage may need to be
24// closer than the nominal 4m distance on SANS that was deemed far enough back to be "safe" from
25// the high angle issues.
26//
27// x- what about the T/B panels? Since a large chunk of these detectors may be obscured,
28//   the normalization will be way off -- and the "active" area will end up much larger
29//   than it should be - since the wings of the detector are mostly zero...
30//   ? Can I apply a mask, or will the detectors be set in a different configuration?
31//
32//
33
34
35/// TODO:
36// -- need a way to view the DIV data (each panel) and see the stats on the values
37//  (maybe a simple panel viewer, one-at-a-time, or all 4 as individuals, not on the same scale)
38
39// x- this is the basic renormalization that is done in PRODIV. see that file for all of the
40//    details of how it's used
41// x- update to VSANS file locations and data reads
42// x- expand this to do a basic renormalization of all 9 panels, and move the data into the
43//    appropriate locations for saving as a DIV file.
44// x- (YES, done) what about error propogation? Can I store the error in the data file?
45//    Makes a difference if the DIV is not collected for long "enough".
46// x- then I need to be able to read the error in (done)
47
48
49
50// Basic function:
51// -- Setup_VSANS_DIV_Struct()
52// -- then, reduce the data (to the COR level?)
53// -- next, V_NormalizeDIV() (one panel at a time, using the mask)
54// -- next, V_CopyDIVToSave() -or- V_CopyDIVToSave_OnePanel()
55// -- last, Save_VSANS_DIV_Nexus()
56//
57
58
59
60
61
62
63
64Proc V_NormalizeDIV_proc(type,detStr)
65        String type,detStr
66        V_NormalizeDIV_onePanel(type,detStr)
67end
68
69// Normalizes a single panel
70// then copies that panel over to the DIV_Struct for later saving
71//
72// type is the work folder where the (? corrected) data is currently
73//
74// TODO
75// x- data should be copied to some alternate work folder before this step
76// x- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
77//    How to handle? A mask?
78// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
79//    standard reduction has been used, but now the normalization step is a multiplication
80//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
81//    what is done in SANS)
82//
83Function V_NormalizeDIV_onePanel(type,detStr)
84        String type,detStr
85
86        Variable ii,totCts,pixelX,pixelY
87
88
89        Wave w = V_getDetectorDataW(type,detStr)
90        Wave w_err = V_getDetectorDataErrW(type,detStr)
91//      pixelX = V_getDet_pixel_num_x(type,detStr)
92//      pixelY = V_getDet_pixel_num_y(type,detStr)
93
94        // get the mask data
95        // 1== mask, 0 == no mask
96        Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
97
98// work on a copy of the data and error
99        Duplicate/O w w_copy
100        Duplicate/O w_err w_err_copy
101       
102        w_copy = (maskW == 1) ? NaN : w_copy   
103        WaveStats/Q/M=1 w_copy
104        totCts = V_npnts*V_avg          // does not count the NaN values
105
106
107        w_copy /= totCts
108        w_copy *= V_npnts
109
110        w_err_copy /= totCts
111        w_err_copy *= V_npnts
112
113// TODO:
114// -- do I want to replace the NaN values with 1 for the DIV (the user will mask the data as
115//    needed, and the NaN values may be an issue later...
116        w_copy = (numtype(w_copy) == 2) ? 1 : w_copy                    //turns 2==NaN into 1
117       
118
119// copy the normalized data to the folder to save
120        Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data")
121        Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error")
122               
123        w_norm = w_copy
124        w_norm_err = w_err_copy
125
126
127        KillWaves/Z w_copy,w_err_copy
128       
129        return(0)
130End
131
132
133//
134// Normalizes each panel independently
135// Normalizes in-place, replacing whatever was there
136//
137// type is the work folder where the (? corrected) data is currently
138//
139// TODO
140// -- data should be copied to some alternate work folder before this step
141// -- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
142//    How to handle? A mask?
143// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
144//    standard reduction has been used, but now the normalization step is a multiplication
145//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
146//    what is done in SANS)
147//
148Function V_NormalizeDIV(type)
149        String type
150
151        Variable ii,totCts,pixelX,pixelY
152        String detStr
153
154        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
155                detStr = StringFromList(ii, ksDetectorListAll, ";")
156                Wave w = V_getDetectorDataW(type,detStr)
157                Wave w_err = V_getDetectorDataErrW(type,detStr)
158                pixelX = V_getDet_pixel_num_x(type,detStr)
159                pixelY = V_getDet_pixel_num_y(type,detStr)
160
161                totCts = sum(w,Inf,-Inf)                //sum all of the data
162               
163                w /= totCts
164                w *= pixelX*pixelY
165
166                w_err /= totCts
167                w_err *= pixelX*pixelY
168               
169        endfor
170       
171        return(0)
172End
173
174
175// copies an entire work folder, all 9 detectors (at COR level)
176// to the DIV structure to write out
177//
178Function V_CopyDIVToSave(type)
179        String type
180       
181        Variable ii,totCts,pixelX,pixelY
182        String detStr
183        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
184        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
185       
186       
187        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
188                detStr = StringFromList(ii, ksDetectorListAll, ";")
189
190                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
191                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
192               
193        endfor
194       
195        return(0)
196End
197
198//
199// copies only the specified panel from a work folder, (at COR level)
200// to the DIV structure to write out
201//
202// used to replace a single panel, or to fill in carriage by carriage.
203//
204Function V_CopyDIVToSave_OnePanel(type,detStr)
205        String type,detStr
206       
207        Variable ii,totCts,pixelX,pixelY
208        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
209        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
210       
211       
212                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
213                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
214                       
215        return(0)
216End
217
218
219
220
221// TODO
222// currently, there are no dummy fill values or attributes for the fake DIV file
223//
224Proc Setup_VSANS_DIV_Struct()
225
226        // lays out the tree and fills with dummy values
227        H_Setup_VSANS_DIV_Structure()
228       
229        // writes in the attributes
230//      H_Fill_VSANS_Attributes()
231       
232        // fill in with VCALC simulation bits
233//      H_Fill_VSANS_wSim()
234       
235End
236
237Proc Save_VSANS_DIV_Nexus(fileName)
238        String fileName="Test_VSANS_DIV_file"
239
240        // save as HDF5 (no attributes saved yet)
241        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
242       
243//      // read in a data file using the gateway-- reads from the home path
244//      H_HDF5Gate_Read_Raw(fileName+".h5")
245//     
246//      // after reading in a "partial" file using the gateway (to generate the xref)
247//      // Save the xref to disk (for later use)
248//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
249//     
250//      // after you've generated the HDF5___xref, load it in and copy it
251//      // to the necessary folder location.
252//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
253//     
254//      // writes out the contents of a data folder using the gateway
255//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
256//
257//      // re-load the data file using the gateway-- reads from the home path
258//      // now with attributes
259//      H_HDF5Gate_Read_Raw(fileName+".h5")
260       
261End
262
263////////////// fake DIV file tests
264//
265//
266//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
267//
268// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
269// file header. nothing more is needed (possibly)
270//
271// TODO -- I want to re-visit the propagation of errors in the DIV file. No errors are ever calculated/saved
272//   during the generation of the file, but there's no reason it couldn't. the idea is that the plex
273//   is counted so long that the errors are insignificant compared to the data errors, but that may not
274//   always be the case. A bit of math may prove this. or not. Plus, the situation for VSANS may be different.
275//
276//
277// TODO -- make the number of pixels GLOBAL
278//
279Proc H_Setup_VSANS_DIV_Structure()
280       
281        NewDataFolder/O/S root:VSANS_DIV_file           
282
283        NewDataFolder/O/S root:VSANS_DIV_file:entry     
284                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
285                Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
286                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
287                        Make/O/T/N=1    name    = "NG3_VSANS"
288                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
289                        Make/O/D/N=(150,150)    data    = 1
290                        Make/O/D/N=(150,150)    linear_data_error       = 0.01
291                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
292                        Make/O/D/N=(48,128)     data = 1
293                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
294                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
295                        Make/O/D/N=(48,128)     data = 1
296                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
297                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
298                        Make/O/D/N=(128,48)     data    = 1
299                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
300                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
301                        Make/O/D/N=(128,48)     data    = 1
302                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
303                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
304                        Make/O/D/N=(48,128)     data = 1
305                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
306                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
307                        Make/O/D/N=(48,128)     data = 1
308                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
309                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
310                        Make/O/D/N=(128,48)     data    = 1
311                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
312                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
313                        Make/O/D/N=(128,48)     data    = 1
314                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
315
316//
317// version that is NOT perfect, LR detectors are "striped"
318//
319//      NewDataFolder/O/S root:VSANS_DIV_file:entry     
320//              Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
321//              Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
322//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
323//                      Make/O/T/N=1    name    = "NG3_VSANS"
324//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
325//                      Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
326//                      Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
327//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
328//                      Make/O/D/N=(48,128)     data
329//                      data[][0] = 1+enoise(0.1)
330//                      data[][] = data[p][0]
331//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
332//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
333//                      Make/O/D/N=(48,128)     data
334//                      data[][0] = 1+enoise(0.1)
335//                      data[][] = data[p][0]
336//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
337//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
338//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
339//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
340//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
341//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
342//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
343//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
344//                      Make/O/D/N=(48,128)     data
345//                      data[][0] = 1+enoise(0.1)
346//                      data[][] = data[p][0]
347//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
348//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
349//                      Make/O/D/N=(48,128)     data
350//                      data[][0] = 1+enoise(0.1)
351//                      data[][] = data[p][0]
352//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
353//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
354//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
355//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
356//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
357//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
358//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
359               
360               
361                // fake, empty folders so that the generic loaders can be used
362                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
363                NewDataFolder/O root:VSANS_DIV_file:entry:control
364                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
365                NewDataFolder/O root:VSANS_DIV_file:entry:sample
366                NewDataFolder/O root:VSANS_DIV_file:entry:user
367
368                       
369        SetDataFolder root:
370
371End
372
373
374
375//
376// simple panel to display the 4 detector panels
377//
378// TODO:
379// -- label panels, axes
380// x- any manipulations, stats ?
381// x- add an "update" button (to update the status of the data - this may be automatic with an operation)
382// -- add a "load DIV" button
383// -- add a "copy" button
384// x- add a "ratio" button
385// x- add a "difference" button
386// -- propagate the error in the arithmetic (see WorkFileMath)
387// -- un hard-wire the Front carriage from the panel proc
388
389Proc V_Display_DIV_Panels()
390        PauseUpdate; Silent 1           // building window...
391        NewPanel /W=(720,45,1530,570)/N=VSANS_DIVPanels/K=1
392        DoWindow/C VSANS_DIVPanels
393//      ModifyPanel fixedSize=1,noEdit =1
394
395
396        PopupMenu popup0,pos={17.00,10.00},size={77.00,23.00},proc=V_DispCarriagePopMenuProc,title="Carriage"
397        PopupMenu popup0,mode=1,value= #"\"F;M;\""
398        PopupMenu popup1,pos={134.00,10.00},size={68.00,23.00},proc=V_DispFolderPopMenuProc,title="Folder"
399        PopupMenu popup1,mode=1,popvalue="RAW",value= #"\"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;MSK;ADJ;\""
400        PopupMenu popup2,pos={246.00,10.00},size={83.00,23.00},proc=V_DispOperationPopMenuProc,title="Operation"
401        PopupMenu popup2,mode=1,value= #"\"none;ADJ=STO-SUB;ADJ=STO/SUB;\""
402        Button button0,pos={440.00,10.00},size={70.00,20.00},proc=V_DispUpdateButtonProc,title="Update"
403
404
405//      Display/W=(745,45,945,425)/HOST=#
406        Display/W=(10,45,210,425)/HOST=#
407        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
408        ModifyImage data ctab= {*,*,ColdWarm,0}
409        ModifyImage data ctabAutoscale=3
410        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
411        ModifyGraph mirror=2
412        ModifyGraph nticks=4
413        ModifyGraph minor=1
414        ModifyGraph fSize=9
415        ModifyGraph standoff=0
416        ModifyGraph tkLblRot(left)=90
417        ModifyGraph btLen=3
418        ModifyGraph tlOffset=-2
419        RenameWindow #,Panel_L
420        SetActiveSubwindow ##
421
422//      Display/W=(1300,45,1500,425)/HOST=#
423        Display/W=(565,45,765,425)/HOST=#
424        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FR:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
425        ModifyImage data ctab= {*,*,ColdWarm,0}
426        ModifyImage data ctabAutoscale=3
427        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
428        ModifyGraph mirror=2
429        ModifyGraph nticks=4
430        ModifyGraph minor=1
431        ModifyGraph fSize=9
432        ModifyGraph standoff=0
433        ModifyGraph tkLblRot(left)=90
434        ModifyGraph btLen=3
435        ModifyGraph tlOffset=-2
436        RenameWindow #,Panel_R
437        SetActiveSubwindow ##
438
439//      Display/W=(945,45,1300,235)/HOST=#
440        Display/W=(210,45,565,235)/HOST=#
441        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FT:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
442        ModifyImage data ctab= {*,*,ColdWarm,0}
443        ModifyImage data ctabAutoscale=3
444        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
445        ModifyGraph mirror=2
446        ModifyGraph nticks=4
447        ModifyGraph minor=1
448        ModifyGraph fSize=9
449        ModifyGraph standoff=0
450        ModifyGraph tkLblRot(left)=90
451        ModifyGraph btLen=3
452        ModifyGraph tlOffset=-2
453        RenameWindow #,Panel_T
454        SetActiveSubwindow ##
455
456//      Display/W=(945,235,1300,425)/HOST=#
457        Display/W=(210,235,565,425)/HOST=#
458        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
459        ModifyImage data ctab= {*,*,ColdWarm,0}
460        ModifyImage data ctabAutoscale=3
461        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
462        ModifyGraph mirror=2
463        ModifyGraph nticks=4
464        ModifyGraph minor=1
465        ModifyGraph fSize=9
466        ModifyGraph standoff=0
467        ModifyGraph tkLblRot(left)=90
468        ModifyGraph btLen=3
469        ModifyGraph tlOffset=-2
470        RenameWindow #,Panel_B
471        SetActiveSubwindow ##
472//
473
474        String/G root:Packages:NIST:VSANS:Globals:gDIVstr0 = "this is the title box0\rwith two lines"
475        String/G root:Packages:NIST:VSANS:Globals:gDIVstr1 = "this is the title box1\rwith two lines"
476        String/G root:Packages:NIST:VSANS:Globals:gDIVstr2 = "this is the title box2\rwith two lines"
477        String/G root:Packages:NIST:VSANS:Globals:gDIVstr3 = "this is the title box3\rwith two lines"
478       
479       
480        TitleBox title0 pos={15,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr0,fSize=11
481        TitleBox title1 pos={300,433},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr1,fSize=11
482        TitleBox title2 pos={300,482},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr2,fSize=11
483        TitleBox title3 pos={580,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr3,fSize=11
484
485
486        V_UpdateDIVStrings()
487End
488
489
490// called by the "update" button
491Proc V_UpdatePanelDisp()
492
493        ControlInfo popup0
494        String carrStr = S_value
495       
496        ControlInfo popup1
497        String folder = S_Value
498       
499        // remove the image
500        // append the new image
501        RemoveImage/Z/W=VSANS_DIVPanels#Panel_L data
502        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")               
503        SetActiveSubwindow VSANS_DIVPanels#Panel_L
504        ModifyImage data ctab= {*,*,ColdWarm,0}
505        ModifyImage data ctabAutoscale=3
506        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
507        ModifyGraph mirror=2
508        ModifyGraph nticks=4
509        ModifyGraph minor=1
510        ModifyGraph fSize=9
511        ModifyGraph standoff=0
512        ModifyGraph tkLblRot(left)=90
513        ModifyGraph btLen=3
514        ModifyGraph tlOffset=-2
515        SetActiveSubwindow ##
516
517
518        RemoveImage/Z/W=VSANS_DIVPanels#Panel_T data
519        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")               
520        SetActiveSubwindow VSANS_DIVPanels#Panel_T
521        ModifyImage data ctab= {*,*,ColdWarm,0}
522        ModifyImage data ctabAutoscale=3
523        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
524        ModifyGraph mirror=2
525        ModifyGraph nticks=4
526        ModifyGraph minor=1
527        ModifyGraph fSize=9
528        ModifyGraph standoff=0
529        ModifyGraph tkLblRot(left)=90
530        ModifyGraph btLen=3
531        ModifyGraph tlOffset=-2
532        SetActiveSubwindow ##
533       
534        RemoveImage/Z/W=VSANS_DIVPanels#Panel_B data
535        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")               
536        SetActiveSubwindow VSANS_DIVPanels#Panel_B
537        ModifyImage data ctab= {*,*,ColdWarm,0}
538        ModifyImage data ctabAutoscale=3
539        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
540        ModifyGraph mirror=2
541        ModifyGraph nticks=4
542        ModifyGraph minor=1
543        ModifyGraph fSize=9
544        ModifyGraph standoff=0
545        ModifyGraph tkLblRot(left)=90
546        ModifyGraph btLen=3
547        ModifyGraph tlOffset=-2
548        SetActiveSubwindow ##
549
550        RemoveImage/Z/W=VSANS_DIVPanels#Panel_R data
551        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")               
552        SetActiveSubwindow VSANS_DIVPanels#Panel_R
553        ModifyImage data ctab= {*,*,ColdWarm,0}
554        ModifyImage data ctabAutoscale=3
555        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
556        ModifyGraph mirror=2
557        ModifyGraph nticks=4
558        ModifyGraph minor=1
559        ModifyGraph fSize=9
560        ModifyGraph standoff=0
561        ModifyGraph tkLblRot(left)=90
562        ModifyGraph btLen=3
563        ModifyGraph tlOffset=-2
564        SetActiveSubwindow ##
565
566End
567
568
569
570
571Function V_DispFolderPopMenuProc(pa) : PopupMenuControl
572        STRUCT WMPopupAction &pa
573
574        switch( pa.eventCode )
575                case 2: // mouse up
576                        Variable popNum = pa.popNum
577                        String popStr = pa.popStr
578                        break
579                case -1: // control being killed
580                        break
581        endswitch
582
583        return 0
584End
585
586Function V_DispCarriagePopMenuProc(pa) : PopupMenuControl
587        STRUCT WMPopupAction &pa
588
589        switch( pa.eventCode )
590                case 2: // mouse up
591                        Variable popNum = pa.popNum
592                        String popStr = pa.popStr
593                        break
594                case -1: // control being killed
595                        break
596        endswitch
597
598        return 0
599End
600
601Function V_DispOperationPopMenuProc(pa) : PopupMenuControl
602        STRUCT WMPopupAction &pa
603
604        switch( pa.eventCode )
605                case 2: // mouse up
606                        Variable popNum = pa.popNum
607                        String popStr = pa.popStr
608                        break
609                case -1: // control being killed
610                        break
611        endswitch
612
613        return 0
614End
615
616Function V_DispUpdateButtonProc(ba) : ButtonControl
617        STRUCT WMButtonAction &ba
618
619        switch( ba.eventCode )
620                case 2: // mouse up
621                        // click code here
622                       
623                        // if there is an operation, do it
624                        V_DoDIVOperation()
625                       
626                        // update the data that is displayed
627                        Execute "V_UpdatePanelDisp()"
628                       
629                       
630                        // update the global strings
631                        V_UpdateDIVStrings()
632
633                       
634                        break
635                case -1: // control being killed
636                        break
637        endswitch
638
639        return 0
640End
641
642Function V_UpdateDIVStrings()
643
644        SVAR gDIVstr0 = root:Packages:NIST:VSANS:Globals:gDIVstr0
645        SVAR gDIVstr1 = root:Packages:NIST:VSANS:Globals:gDIVstr1
646        SVAR gDIVstr2 = root:Packages:NIST:VSANS:Globals:gDIVstr2
647        SVAR gDIVstr3 = root:Packages:NIST:VSANS:Globals:gDIVstr3
648       
649        ControlInfo popup0
650        String carrStr = S_value
651       
652        ControlInfo popup1
653        String folder = S_Value
654       
655        String  formatStr="Avg = %g +/- %g\rMin = %g, Max = %g"
656       
657        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")
658        sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
659       
660        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")
661        sprintf gDIVstr1,formatStr,V_avg,V_sdev,V_min,V_max
662       
663        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")
664        sprintf gDIVstr2,formatStr,V_avg,V_sdev,V_min,V_max
665       
666        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")
667        sprintf gDIVstr3,formatStr,V_avg,V_sdev,V_min,V_max
668
669        TitleBox title0 title=gDIVstr0
670        TitleBox title1 title=gDIVstr1
671        TitleBox title2 title=gDIVstr2
672        TitleBox title3 title=gDIVstr3
673                       
674        return(0)
675end
676
677// if there is a simple operation called, do it
678Function V_DoDIVOperation()
679
680        ControlInfo popup2
681        String opStr = S_value
682       
683        if(cmpstr(opStr,"none")==0)
684                return(0)
685        endif
686       
687        ControlInfo popup0
688        String carrStr = S_value
689        // an operation is desired
690        // hard-wired use of STO and SUB, copy results to ADJ
691       
692        // make sure that something is in ADJ
693        // TODO -- reset the values of the data in ADJ, or it will look like the wrong calculation was done
694        //V_CopyWorkFolder("STO","ADJ")         // this is a macro, use the function instead
695        V_CopyHDFToWorkFolder("STO","ADJ")
696
697        WAVE w_sto_L = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"L:data")
698        WAVE w_sub_L = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"L:data")
699        Duplicate/O w_sto_L $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
700        WAVE w_adj_L = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
701
702        WAVE w_sto_R = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"R:data")
703        WAVE w_sub_R = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"R:data")
704        Duplicate/O w_sto_R $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
705        WAVE w_adj_R = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
706
707        WAVE w_sto_T = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"T:data")
708        WAVE w_sub_T = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"T:data")
709        Duplicate/O w_sto_T $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
710        WAVE w_adj_T = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
711
712        WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"B:data")
713        WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"B:data")
714        Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
715        WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
716
717       
718        if(cmpstr(opStr,"ADJ=STO/SUB")==0)
719                w_adj_L = w_sto_L/w_sub_L
720                w_adj_R = w_sto_R/w_sub_R
721                w_adj_T = w_sto_T/w_sub_T
722                w_adj_B = w_sto_B/w_sub_B
723        else
724                w_adj_L = w_sto_L - w_sub_L
725                w_adj_R = w_sto_R - w_sub_R
726                w_adj_T = w_sto_T - w_sub_T
727                w_adj_B = w_sto_B - w_sub_B
728        endif
729
730        return(0)
731end
732
733
734//
735// Simple panel to walk through the steps of generating a DIV file
736//
737
738
739
740
741Proc DIV_Setup_Panel() : Panel
742        PauseUpdate; Silent 1           // building window...
743        NewPanel /W=(1207,593,1444,953)/N=DIV_Setup_Panel/K=1
744        DoWindow/C DIV_Setup_Panel
745        Button button0,pos={54.00,10.00},size={120.00,20.00},proc=V_DIVSetupButtonProc,title="Setup Folder"
746        Button button1,pos={54.00,100.00},size={120.00,20.00},proc=V_DIVNormalizeButtonProc,title="Normalize"
747        Button button2,pos={54.00,200.00},size={120.00,20.00},proc=V_DIVSaveButtonProc,title="Save DIV"
748EndMacro
749
750// set up the folder structure for the DIV file to fill in
751Function V_DIVSetupButtonProc(ba) : ButtonControl
752        STRUCT WMButtonAction &ba
753
754        switch( ba.eventCode )
755                case 2: // mouse up
756                        // click code here
757                        Execute "Setup_VSANS_DIV_Struct()"
758                        break
759                case -1: // control being killed
760                        break
761        endswitch
762
763        return 0
764End
765
766
767Function V_DIVNormalizeButtonProc(ba) : ButtonControl
768        STRUCT WMButtonAction &ba
769
770        switch( ba.eventCode )
771                case 2: // mouse up
772                        // click code here
773                        Execute "V_NormalizeDIV_proc()"
774                        break
775                case -1: // control being killed
776                        break
777        endswitch
778
779        return 0
780End
781
782Function V_DIVSaveButtonProc(ba) : ButtonControl
783        STRUCT WMButtonAction &ba
784
785        switch( ba.eventCode )
786                case 2: // mouse up
787                        // click code here
788                        Execute "Save_VSANS_DIV_Nexus()"
789                        break
790                case -1: // control being killed
791                        break
792        endswitch
793
794        return 0
795End
Note: See TracBrowser for help on using the repository browser.