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

Last change on this file since 1248 was 1246, checked in by srkline, 3 years ago

A large number of changes to the size of panels to enable "Laptop Mode" where all of the panels and controls are scaled down so that they fit on screen and are still in correct proportion. For the laptop I'm using for testing, the resolution is 1920x1080. For this, a scaling of 0.7 seems to work. The on/off of the "laptop Mode" is controlled by a checkbox in the preference panel (under the General tab).

There are still more panels to update in the next commit.

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