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

Last change on this file since 1111 was 1111, checked in by srkline, 4 years ago

two significant changes:

1- in the averaging, before the data is finally written out, duplicate q-values (within 0.1%) are averaged so that duplicate q-values do not appear in the data file. This has a very bad effect on the calculation of the smearing matrix (dq=0).

2-for the data from the back (high res) detector, two steps have been added to the processing at the point where the data is converted to WORK. First, a constant read noise value of 200 cts/pixel is subtracted (found from average of multiple runs with beam off) Second, a 3x3 median filter is applied to the whole image to eliminate the stray bright pixels. Some are saturatd, some are simply outliers. Very effective.

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