source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Detector_Isolate.ipf @ 1070

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

changes to HDFLoadGroup to use the new R=2 flag to allow reading of duplicated groups in the data file (the temperature log). Requires Igor 7.05+ and HDF5XOP 1.24+

File size: 14.3 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5// Isolation of a single detector panel for inspection, verifying the corrections, troubleshooting, etc.
6
7
8// show:
9// graph (raw + corrected?)
10// all the fields pertinent to the detector
11// all of the tables of parameters (one at a time?)
12// + a way to edit them if possible? or leave this to patch?
13// way to toggle corrections on/off
14// draw arcs to show concentric rings around the beam center
15
16
17// TODO
18// -- verify the flow of operations - that is, what is the state of what is displayed? After doing
19//    the corrections, popping the detector panel will display from RAW, but really should display from ADJ
20// -- need labels on images to know what they are
21// -- does it mean anything to "not" do the non-linear correction. I think I always calculate it in the background
22//    when the RAW data is loaded, and always use the corrected real-space distances for the calculation of q-values
23//    (so there is no visible effect on pixels)...
24// -- interaction with the main data display will allow seeing the whole set of detectors. What is the benefit of
25//    this isolation? Should I make a bigger, more visible detector image?
26// x- link the function to the Isolate button on the main panel
27//
28// -- figure out how to (better?) re-plot the images when swapping between LR and TB panels
29// -- graphically show the beam center / radius of where it is in relation to the panel
30//
31// -- when selecting the detector, set the x/y pixel sizes -- un-do this?
32// -- The xPixels, yPixels axis labels are not correct. The axes are scaled to the beam center, through
33//    a call to V_RestorePanels() when the raw data is loaded. The BeamCenter panel removes this wave scaling
34//    so that the data can be presented (and fit) purely as pixels. On the isolate panel, the scaling has not
35//    been removed and is confusing, especially on T/B panels.
36// -- add a checkbox or button to remove/replace the wave scaling to the beam center. this is in a sense,
37//    a correction to toggle.
38//
39//
40
41
42Function V_DetectorIsolate()
43        DoWindow/F IsolateDetector
44        if(V_flag==0)
45       
46                Execute "VC_Initialize_Space()"         // initializes VCALC space, so that dummy values are present for MSK and DIV
47       
48                Execute "V_IsolateDetectorPanel()"
49        endif
50End
51
52
53//
54// TODO - may need to adjust the display for the different pixel dimensions
55//      ModifyGraph width={Plan,1,bottom,left}
56//
57Proc V_IsolateDetectorPanel() : Panel
58        PauseUpdate; Silent 1           // building window...
59
60
61        NewPanel /W=(662,418,1586,960)/N=IsolateDetector /K=1
62//      ShowTools/A
63       
64        PopupMenu popup_0,pos={169,18},size={109,20},proc=V_isoSetDetPanelPopMenuProc,title="Detector Panel"
65        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
66//      PopupMenu popup_1,pos={200,20},size={157,20},proc=DetModelPopMenuProc,title="Model Function"
67//      PopupMenu popup_1,mode=1,popvalue="BroadPeak",value= #"\"BroadPeak;other;\""
68        PopupMenu popup_2,pos={20,18},size={109,20},title="Data Source",proc=V_SetFldrPopMenuProc
69        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;SAM;EMP;BGD;DIV;MSK;\""
70               
71        Button button_0,pos={541,79},size={130,20},proc=V_isoCorrectButtonProc,title="Apply Corrections"
72//      Button button_1,pos={651,79},size={80,20},proc=V_isoDetFitGuessButtonProc,title="Guess"
73        Button button_2,pos={821,20},size={80,20},proc=V_isoHelpButtonProc,title="Help"
74
75
76
77        CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
78        CheckBox check_0,value= 0
79        CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
80        CheckBox check_1,value= 0
81        CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
82        CheckBox check_2,value= 0
83        CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
84        CheckBox check_3,value= 0
85        CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
86        CheckBox check_4,value= 0
87        CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
88        CheckBox check_5,value= 0
89        CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
90        CheckBox check_6,value= 0
91
92
93
94//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
95
96//      duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
97//      SetScale/P x 0,1, curDispPanel
98//      SetScale/P y 0,1, curDispPanel
99//      Duplicate/O curDispPanel correctedPanel
100
101//      SetDataFolder root:
102       
103        V_CopyHDFToWorkFolder("RAW","ADJ")
104       
105        // draw the correct images
106        V_isoDrawDetPanel("FL")
107
108       
109
110// edit the fit coefficients   
111//      Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
112//      ModifyTable width(Point)=0
113//      ModifyTable width(parameters_PeakPix2D)=120
114//      ModifyTable width(coef_PeakPix2D)=100
115//      RenameWindow #,T0
116//      SetActiveSubwindow ##
117
118       
119EndMacro
120
121
122//
123// function to choose which detector panel to display, and then to actually display it
124//
125Function V_isoSetDetPanelPopMenuProc(pa) : PopupMenuControl
126        STRUCT WMPopupAction &pa
127
128        switch( pa.eventCode )
129                case 2: // mouse up
130                        Variable popNum = pa.popNum
131                        String popStr = pa.popStr
132                                               
133                        // remove the old image (it may not be the right shape)
134                        // -- but make sure it exists first...
135                        String childList = ChildWindowList("IsolateDetector")
136                        Variable flag
137                       
138                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
139                        if(flag != -1)
140                                KillWindow IsolateDetector#DetData
141                        endif
142                       
143                        flag = WhichListItem("ModelData", ChildList)
144                        if(flag != -1)
145                                KillWindow IsolateDetector#ModelData
146                        endif
147       
148                        // draw the correct images
149                        V_isoDrawDetPanel(popStr)
150                       
151                        break
152                case -1: // control being killed
153                        break
154        endswitch
155
156        return 0
157End
158
159
160// TODO - currently is hard-wired for the simulation path!
161//     need to make it more generic, especially for RAW data
162//
163// -- need to adjust the size of the image subwindows to keep the model
164//    calculation from spilling over onto the table (maybe just move the table)
165// -- need to do something for panel "B". currently ignored
166// -- currently the pixel sizes for "real" data is incorrect in the file
167//     and this is why the plots are incorrectly sized
168// -- need to be able to display MASK and DIV data (or any data without a full set of metadata)
169//
170//
171// draw the selected panel and the model calculation, adjusting for the
172// orientation of the panel and the number of pixels, and pixel sizes
173//
174// str input is the panelStr ("FL" for example)
175Function V_isoDrawDetPanel(str)
176        String str
177       
178        // from the selection, find the path to the data
179
180
181        Variable xDim,yDim
182        Variable left,top,right,bottom
183        Variable height, width
184        Variable left2,top2,right2,bottom2
185        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
186
187
188//      Wave dispW=root:Packages:NIST:VSANS:Globals:Isolate:curDispPanel
189//      Wave corrW=root:Packages:NIST:VSANS:Globals:Isolate:correctedPanel
190
191        //plot it in the subwindow with the proper aspect and positioning
192        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
193        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
194       
195       
196        // using two switches -- one to set the panel-specific dimensions
197        // and the other to set the "common" values, some of which are based on the panel dimensions
198
199// set the source of the data. not always VCALC anymore
200        String folder
201        ControlInfo popup_2
202        folder = S_Value
203
204        Variable VC_nPix_X,VC_nPix_Y,VC_pixSize_X,VC_pixSize_Y
205        // TODO -- fix all of this mess
206        strswitch(folder)
207                case "VCALC":
208//                      VC_nPix_X = VCALC_get_nPix_X(str)
209//                      VC_nPix_Y = VCALC_get_nPix_Y(str)
210//                      VC_pixSize_X = VCALC_getPixSizeX(str)
211//                      VC_pixSize_Y = VCALC_getPixSizeY(str)
212//                      wave dispW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
213//                      nPix_X = VC_nPix_X
214//                      nPix_Y = VC_nPix_Y
215//                      pixSize_X = VC_pixSize_X
216//                      pixSize_Y = VC_pixSize_Y
217       
218                        break
219                       
220                case "DIV":
221                case "MSK":
222                // TODO
223                // -- this takes fake data from VCALC, which is very likely wrong for DIV data
224                        VC_nPix_X = VCALC_get_nPix_X(str)
225                        VC_nPix_Y = VCALC_get_nPix_Y(str)
226                        VC_pixSize_X = VCALC_getPixSizeX(str)
227                        VC_pixSize_Y = VCALC_getPixSizeY(str)
228                        wave dispW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
229                        nPix_X = VC_nPix_X
230                        nPix_Y = VC_nPix_Y
231                        pixSize_X = VC_pixSize_X
232                        pixSize_Y = VC_pixSize_Y
233                        break
234
235                case "RAW":
236                case "ADJ":
237                case "SAM":
238                case "EMP":
239                case "BGD":
240                        wave dispW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
241       
242                        nPix_X = V_getDet_pixel_num_x(folder,str)
243                        nPix_Y = V_getDet_pixel_num_Y(folder,str)
244                        pixSize_X = V_getDet_x_pixel_size(folder,str)/10
245                        pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
246                        break
247                               
248                default:
249                        return(0)
250        endswitch
251
252
253        // and the ADJusted wave to display     
254        wave corrW = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str+":data")
255
256        Variable scale = 5
257       
258        // common values (panel position, etc)
259        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
260        strswitch(str)
261                case "FL":
262                case "FR":
263                case "ML":
264                case "MR":
265                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
266                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
267                       
268                        left = 20
269                        top = 80
270                        right = left+width
271                        bottom = top+height
272                       
273                        left2 = right + 20
274                        right2 = left2 + width
275                        top2 = top
276                        bottom2 = bottom
277                       
278                        break                   
279                case "FT":
280                case "FB":
281                case "MT":
282                case "MB":
283                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
284                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
285                                               
286                        left = 20
287                        top = 80
288                        right = left+width
289                        bottom = top+height
290                       
291                        left2 = left
292                        right2 = right
293                        top2 = top + height + 20
294                        bottom2 = bottom + height + 20
295                       
296                        break
297                case "B":
298                        return(0)               //just exit
299                        break                                           
300                default:
301                        return(0)               //just exit
302        endswitch
303
304
305
306//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
307        // generate the new panel display and corrected panel (just a copy right now)
308//      duplicate/O newW curDispPanel
309//      SetScale/P x 0,1, curDispPanel
310//      SetScale/P y 0,1, curDispPanel
311//      Duplicate/O curDispPanel correctedPanel
312       
313        // need to be in the same folder as the data
314        SetDataFolder $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str)
315        Wave data1 = data
316       
317        //draw the detector panel
318        Display/W=(left,top,right,bottom)/HOST=#
319        RenameWindow #,DetData
320        AppendImage/W=IsolateDetector#DetData data1
321        ModifyImage/W=IsolateDetector#DetData '' ctab= {*,*,ColdWarm,0}
322        Label left "Y pixels"
323        Label bottom "X pixels"
324        SetActiveSubwindow ##   
325       
326       
327        SetDataFolder $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str)
328        Wave data2 = data
329       
330        //draw the corrected detector panel
331        // see the main display of RAW data for example of multiple 'data' images
332        Display/W=(left2,top2,right2,bottom2)/HOST=#
333        RenameWindow #,ModelData
334        AppendImage/W=IsolateDetector#ModelData data2
335        ModifyImage/W=IsolateDetector#ModelData '' ctab= {*,*,ColdWarm,0}               // the image is called '' even though the local ref is data2
336        Label left "Y pixels"
337        Label bottom "X pixels"
338
339        SetActiveSubwindow ##   
340
341
342        SetDataFolder root:
343               
344        DoUpdate
345       
346        return(0)
347End
348
349
350
351//
352Function V_isoCorrectButtonProc(ba) : ButtonControl
353        STRUCT WMButtonAction &ba
354
355        Variable sav0,sav1,sav2,sav3,sav4,sav5,sav6
356       
357        switch( ba.eventCode )
358                case 2: // mouse up
359                        // click code here
360                       
361                        // save the state of the global flags
362                        // poll the state of the checkboxes
363                        // temporarily set the global (preference) flags
364
365//                      CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
366                        NVAR gDoNonLinearCor = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor
367                        sav0 = gDoNonLinearCor
368                        ControlInfo check_0
369                        gDoNonLinearCor = V_Value
370                       
371//                      CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
372                        NVAR gDoDeadTimeCor = root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor
373                        sav1 = gDoDeadTimeCor
374                        ControlInfo check_1
375                        gDoDeadTimeCor = V_Value
376                       
377//                      CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
378                        NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor
379                        sav2 = gDoSolidAngleCor
380                        ControlInfo check_2
381                        gDoSolidAngleCor = V_Value
382                       
383//                      CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
384                        NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
385                        sav3 = gDoDIVCor
386                        ControlInfo check_3
387                        gDoDIVCor = V_Value
388                       
389//                      CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
390                        NVAR gDoTrans = root:Packages:NIST:VSANS:Globals:gDoTransmissionCor
391                        sav4 = gDoTrans
392                        ControlInfo check_4
393                        gDoTrans = V_Value
394                       
395//                      CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
396                        NVAR gDoTubeShadowCor = root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor
397                        sav5 = gDoTubeShadowCor
398                        ControlInfo check_5
399                        gDoTubeShadowCor = V_Value
400                       
401//                      CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
402                        NVAR gDoMonitorNormalization = root:Packages:NIST:VSANS:Globals:gDoMonitorNormalization
403                        sav6 = gDoMonitorNormalization
404                        ControlInfo check_6
405                        gDoMonitorNormalization = V_Value
406                       
407       
408                       
409                        // raw_to_work to apply the selected corrections
410                        // TODO -- verify that this works correctly, since ADJ has waves in use and the folder
411                        //         can't be directly killed. Copy is the first step - so verify.
412                        V_Raw_to_work("ADJ")
413                       
414                       
415                       
416                        // set the globals back the the prior state
417                        gDoNonlinearCor = sav0
418                        gDoDeadTimeCor = sav1
419                        gDoSolidAngleCor = sav2
420                        gDoDIVCor = sav3
421                        gDoTrans = sav4
422                        gDoTubeShadowCor = sav5
423                        gDoMonitorNormalization = sav6
424                       
425                       
426                       
427                        break
428                case -1: // control being killed
429                        break
430        endswitch
431
432        return 0
433End
434
435
436
437
438////
439// copies the data from the popped folder (either RAW or VCALC) to ADJ
440//
441Function V_SetFldrPopMenuProc(pa) : PopupMenuControl
442        STRUCT WMPopupAction &pa
443
444        switch( pa.eventCode )
445                case 2: // mouse up
446                        Variable popNum = pa.popNum
447                        String popStr = pa.popStr
448                       
449                        V_CopyHDFToWorkFolder(popStr,"ADJ")
450                       
451                        break
452                case -1: // control being killed
453                        break
454        endswitch
455
456        return 0
457End
458
459
460Function V_isoHelpButtonProc(ba) : ButtonControl
461        STRUCT WMButtonAction &ba
462
463        switch( ba.eventCode )
464                case 2: // mouse up
465                        // click code here
466                       
467                        DoAlert 0,"Help file not written yet..."
468                       
469                        break
470                case -1: // control being killed
471                        break
472        endswitch
473
474        return 0
475End
476
Note: See TracBrowser for help on using the repository browser.