source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_MaskUtils.ipf @ 1073

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

lots of changes here:
many little fixes to clean up TODO items and marke them DONE

changed the handling of the panel "gap" to split the gap evenly. Q-calculations have been re-verified with this change.

re-named the list of "bin Type" values, and added a few more choices. Streamlined how the averaging and plotting works with this list so that it can be more easily modified as different combinations of binning are envisioned. This resulted in a lot of excess code being cut out and replaced with cleaner logic. This change has also been verified to work as intended.

Attenuation is now always calculated from the table. The table also by (NEW) definition has values for the white beam (one waelength) and graphite (multiple possible wavelengths) where the wavelengths are artificially scaled (*1000) or *1e6) so that the interpolations can be done internally without the need for multiple attenuator tables.

File size: 25.0 KB
RevLine 
[999]1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
[1002]4//
5// Mask utilities:
6// - loader
7// - simple editor
8// - save mask file
9// - assign mask file to data file
10//
11//
12//  this is (at first) to be a very simple editor to generate masks row/column wise, not drawing
13//  masks with arbitrary shape.
14//
[1014]15//
16//
17//
[1002]18//
19//
[999]20
[1002]21///// LOADING
22
[1050]23// TODO
24// -- when mask is loaded, need to be sure to clean up the "extra" waves that may be present
25//
26// -- the overlay and the currentTube waves since these are not overwritten or killed when new mask
[1002]27//  data is read in from HDF. need to manually? check for these and delete then, or the data and
28//  mask overlay will be out of sync.
29//
30
31
32// passing null file string presents a dialog
33// called from the Main Button " Read Mask"
[1024]34Proc V_LoadMASKData()
[1002]35        V_LoadHDF5Data("","MSK")
36End
37
38
39
40//// DRAWING/SAVING
41//
[1073]42// (DONE)
[999]43// x- CHANGE the mask behavior to a more logical choice - and consistent with SANS
44//   x- CHANGE to:
45// 1 == mask == discard data
46// 0 == no Mask == keep data
47// x- and then make the corresponding changes in the I(Q) routines
[1073]48//
[1002]49// x- move the mask generating utilities from VC_HDF5_Utils into this procedure - to keep
[999]50// all of the mask procedures together
51
52
[1050]53// TODO
54// -- document the arrow keys moving the tube number and adding/deleting tubes from the mask
[1002]55//  this is done through a window hook function (LR moves tube number, up/down = add/delete)
[999]56//
[1073]57// (DONE)
58// x- (NO)- Igor 7 is necessary for some VSANS functionality, so do not support Igor 6
59//    x (no)make the arrow keys Igor 6 compatible - search for specialKeyCode or Keyboard Events in the help file
[1002]60//     and what needs to be replaced for Igor 6
[1073]61// DONE
62// x- for L/R panels, the maksing of columns should be sufficient. Tubes are vertical. For the T/B panels
[1002]63//         the L/R panels cast a vertical shadow (=vertical mask) AND the tubes are horizontal, so the individual
64//         tubes will likely need to be masked in a horizontal line too, per tube. ADD this in...
[999]65
66
67//TODO
[1002]68// x- draw a mask
69// x- save a mask (all panels)
[1015]70// -- move everything into it's own folder, rather than root:
[1002]71// -- be able to save the mask name to the RAW data file
72// -- be able to read a mask based on what name is in the data file
[999]73//
74// x- biggest thing now is to re-write the DrawDetPanel() routine from the beamCenter.ipf
75//    to do what this panel needs
76//
[1002]77// x- add this to the list of includes, move the file to SVN, and add it.
[999]78//
79// -- for working with VCALC -- maybe have an automatic generator (if val < -2e6, mask = 0)
80//    this can be checked column-wise to go faster (1st index)
81//
82// x- re-write V_OverlayMask to make the "overlay" wave that has the NaNs, and then the drawing
83//    routines need to be aware of this
84
[1002]85
86
87// called from the main button "Draw Mask"
[1024]88Proc V_Edit_a_Mask()
[999]89        V_EditMask()
90end
91
92Function V_EditMask()
93        DoWindow/F MaskEditPanel
94        if(V_flag==0)
[1015]95       
96                NewDataFolder/O root:Packages:NIST:VSANS:Globals:Mask
97
98                Variable/G root:Packages:NIST:VSANS:Globals:Mask:gMaskTube = 0
99                Variable/G root:Packages:NIST:VSANS:Globals:Mask:gMaskMaxIndex = 47
100               
101                // check for a mask, if not present, generate a default mask
102                String str="FT"
103                wave/Z maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
104                if(!WaveExists(maskW))
105                        V_GenerateDefaultMask()
106                endif
107               
[1024]108                Execute "V_MaskEditorPanel()"
[999]109        endif
110End
111
112//
[1050]113// TODO
114// -- may need to adjust the display for the different pixel dimensions
[999]115//      ModifyGraph width={Plan,1,bottom,left}
116//
[1050]117// TODO
118//  need buttons for:
119//              -- quit (to exit gracefully)
[1002]120//    -- help (button is there, fill in the content)
121//
[1024]122Proc V_MaskEditorPanel() : Panel
[999]123        PauseUpdate; Silent 1           // building window...
124
[1000]125        NewPanel /W=(662,418,1300,960)/N=MaskEditPanel   /K=1
[999]126//      ShowTools/A
127       
[1024]128        PopupMenu popup_0,pos={20,50},size={109,20},proc=V_SetMaskPanelPopMenuProc,title="Detector Panel"
[1000]129        PopupMenu popup_0,mode=1,popvalue="FT",value= #"\"FL;FR;FT;FB;MR;ML;MT;MB;B;\""
[999]130        PopupMenu popup_2,pos={20,20},size={109,20},title="Data Source"//,proc=SetFldrPopMenuProc
[1000]131        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;SAM;VCALC;\""
[999]132
[1002]133        SetVariable setvar0,pos={257.00,20.00},size={150.00,14.00},title="tube number"
[1015]134        SetVariable setvar0,limits={0,127,1},value=root:Packages:NIST:VSANS:Globals:Mask:gMaskTube
[1024]135        Button button_0,pos={257,46.00},size={50.00,20.00},proc=V_AddToMaskButtonProc,title="Add"
136        Button button_1,pos={319.00,46.00},size={50.00,20.00},proc=V_RemoveFromMaskButtonProc,title="Del"
137        Button button_2,pos={409.00,46.00},size={90.00,20.00},proc=V_ToggleMaskButtonProc,title="Toggle"
138        Button button_3,pos={509.00,46.00},size={80.00,20.00},proc=V_SaveMaskButtonProc,title="Save"
139        Button button_4,pos={603.00,10.00},size={20.00,20.00},proc=V_DrawMaskHelpButtonProc,title="?"
140        CheckBox check_0,pos={190.00,23.00},size={37.00,15.00},proc=V_DrawMaskRadioCheckProc,title="Row"
[1002]141        CheckBox check_0,value= 0,mode=1
[1024]142        CheckBox check_1,pos={190.00,46.00},size={32.00,15.00},proc=V_DrawMaskRadioCheckProc,title="Col"
[1002]143        CheckBox check_1,value= 1,mode=1
[1000]144
[1024]145        SetWindow MaskEditPanel, hook(MyHook)=V_MaskWindowHook
[999]146
147        // draw the correct images
148        //draw the detector panel
[1024]149        V_DrawPanelToMask("FT")
[999]150       
151        // overlay the current mask
[1000]152        V_OverlayMask("FT",1)
[999]153
154EndMacro
155
[1024]156Function V_DrawMaskHelpButtonProc(ba) : ButtonControl
[1002]157        STRUCT WMButtonAction &ba
[1000]158
[1002]159        switch( ba.eventCode )
160                case 2: // mouse up
161                        // click code here
162                        DoAlert 0, "Draw Mask Help not written yet..."
163                        break
164                case -1: // control being killed
165                        break
166        endswitch
167
168        return 0
169End
170
171//
172//a simple toggle between the two, so the logic is not done in the cleanest way.
173//
174// update the limits on the tube nubmer based on row/col and the panel (gMaskMaxIndex global)
175//
[1024]176Function V_DrawMaskRadioCheckProc(cba) : CheckBoxControl
[1002]177        STRUCT WMCheckboxAction &cba
178
179        switch( cba.eventCode )
180                case 2: // mouse up
181                        Variable checked = cba.checked
182                        String name = cba.ctrlName
183                       
184                        //get information to update the limits on the tube number setvar
185                        ControlInfo popup_0
186                        String str=S_Value
187                        wave data = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
188                        Variable val
189                       
190                        // update the radio button status and the setvar limits                 
191                        if(cmpstr(name,"check_0") == 0)         // ROW is being selected
192                                CheckBox check_0,value = 1
193                                CheckBox check_1,value = 0
194                                val = DimSize(data, 1) -1
195                        else
196                                // COL is being selected
197                                CheckBox check_0,value = 0
198                                CheckBox check_1,value = 1
199                                val = DimSize(data, 0) -1
200                        endif
[1013]201
202//                      print "max = ",val
203                                               
[1002]204                        SetVariable setvar0,limits={0,val,1}
[1015]205                        NVAR gVal = root:Packages:NIST:VSANS:Globals:Mask:gMaskTube
206                        NVAR gMax = root:Packages:NIST:VSANS:Globals:Mask:gMaskMaxIndex
[1002]207                        gMax = val
208                        if(gVal > val)
209                                gVal = val
210                        endif
211                       
212                        break
213                case -1: // control being killed
214                        break
215        endswitch
216
217        return 0
218End
219
[1024]220Function V_MaskWindowHook(s)
[1002]221        STRUCT WMWinHookStruct &s
222       
223        Variable hookResult = 0 // 0 if we do not handle event, 1 if we handle it.
224       
225        String message = ""
226
227        switch(s.eventCode)
228                case 11:        // Keyboard event
229//                      String keyCodeInfo
230//                      sprintf keyCodeInfo, "s.keycode = 0x%04X", s.keycode
231//                      if (strlen(message) > 0)
232//                              message += "\r"
233//                      endif
234//                      message +=keyCodeInfo
235//
236//                      message += "\r"
237//                      String specialKeyCodeInfo
238//                      sprintf specialKeyCodeInfo, "s.specialKeyCode = %d", s.specialKeyCode
239//                      message +=specialKeyCodeInfo
240//                      message += "\r"
241//
242//                      String keyTextInfo
243//                      sprintf keyTextInfo, "s.keyText = \"%s\"", s.keyText
244//                      message +=keyTextInfo
245//
246//                      String text = "\\Z24" + message
247//                      Textbox /C/N=Message/W=KeyboardEventsGraph/A=MT/X=0/Y=15 text
248
[1050]249                // NOTE:  these special keyCodes are all Igor-7 ONLY
[1002]250
251// Note that I need to keep track of the index value since I'm intercepting the
252// SetVariable event here. I need to keep the index in range.           
253                        STRUCT WMButtonAction ba
254                        ba.eventCode = 2
[1015]255                        NVAR tubeVal = root:Packages:NIST:VSANS:Globals:Mask:gMaskTube
[1002]256                        if(s.specialKeyCode == 100)
257                                //left arrow
258                                tubeVal -= 1
259                        endif
260                        if(s.specialKeyCode == 101)
261                                //right arrow
262                                tubeVal += 1
263                        endif
264                        if(s.specialKeyCode == 102)
265                                //up arrow
[1024]266                                V_AddToMaskButtonProc(ba)
[1002]267                        endif
268                        if(s.specialKeyCode == 103)
269                                //down arrow
[1024]270                                V_RemoveFromMaskButtonProc(ba)
[1002]271                        endif
272
273// enforce the limits on the setvar
[1015]274                        NVAR gMax = root:Packages:NIST:VSANS:Globals:Mask:gMaskMaxIndex
[1002]275                        if(tubeVal > gMax)
276                                tubeVal = gMax
277                        endif
278                        if(tubeVal < 0)
279                                tubeVal = 0
280                        endif
281                       
282// draw the "currentTube" every time
283                        ControlInfo popup_0
284                        String str=S_Value
285                        wave currentTube = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":currentTube")
286
287                        // update so that the proper row is displayed on the currentTube
288                        currentTube = 0
289                       
290                        ControlInfo check_0             // is it row?
291                        Variable isRow = V_value
292                        if(isRow)
293                                currentTube[][tubeVal] = 1                     
294                        else
295                                currentTube[tubeVal][] = 1
296                        endif           
297
298
299                        hookResult = 1  // We handled keystroke
300                        break
301        endswitch
302       
303        return hookResult               // If non-zero, we handled event and Igor will ignore it.
304End
305
[1024]306
307Function V_ToggleMaskButtonProc(ba) : ButtonControl
[1000]308        STRUCT WMButtonAction &ba
309
310        switch( ba.eventCode )
311                case 2: // mouse up
312                        // click code here
313                       
314                        ControlInfo popup_0
315                        String str=S_Value
316
317                        wave/Z overlay = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
318                       
319                        CheckDisplayed/W=MaskEditPanel#DetData overlay
320                        Variable state = !(V_flag)              //if V_flag == 0, then set to 1 (and vice versa)
321                        V_OverlayMask(str,state)
322
323                        break
324                case -1: // control being killed
325                        break
326        endswitch
327
328        return 0
329End
330
331
[1024]332Function V_AddToMaskButtonProc(ba) : ButtonControl
[1000]333        STRUCT WMButtonAction &ba
334
335        switch( ba.eventCode )
336                case 2: // mouse up
337                        // click code here
338                        ControlInfo popup_0
339                        String str=S_Value
340                       
341                        wave/Z maskData = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
342                       
343                        Variable val
[1002]344                        ControlInfo setvar0             //get the tube number
[1000]345                        val = V_Value
346                       
[1002]347                        ControlInfo check_0             // is it row?
348                        Variable isRow = V_value
349                        if(isRow)
350                                maskData[][val] = 1                     
351                        else
352                                maskData[val][] = 1
353                        endif
354                       
[1000]355                        V_OverlayMask(str,1)
356                       
357                        break
358                case -1: // control being killed
359                        break
360        endswitch
361
362        return 0
363End
364
[1024]365Function V_RemoveFromMaskButtonProc(ba) : ButtonControl
[1000]366        STRUCT WMButtonAction &ba
367
368        switch( ba.eventCode )
369                case 2: // mouse up
370                        // click code here
371                        ControlInfo popup_0
372                        String str=S_Value
373                       
374                        wave/Z maskData = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
375                       
376                        Variable val
[1002]377                        ControlInfo setvar0 // get the tube number
[1000]378                        val = V_Value
379                       
[1002]380                        ControlInfo check_0             // is it row?
381                        Variable isRow = V_value
382                        if(isRow)
383                                maskData[][val] = 0                     
384                        else
385                                maskData[val][] = 0
386                        endif
387                       
388                        V_OverlayMask(str,1)   
389                                       
[1000]390                        break
391                case -1: // control being killed
392                        break
393        endswitch
394
395        return 0
396End
397
[999]398//
399// function to choose which detector panel to display, and then to actually display it
400//
[1024]401Function V_SetMaskPanelPopMenuProc(pa) : PopupMenuControl
[999]402        STRUCT WMPopupAction &pa
403
404        switch( pa.eventCode )
405                case 2: // mouse up
406                        Variable popNum = pa.popNum
407                        String popStr = pa.popStr
408                                               
409                        // remove the old image (it may not be the right shape)
410                        // -- but make sure it exists first...
411                        String childList = ChildWindowList("MaskEditPanel")
412                        Variable flag
413                       
414                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
415                        if(flag != -1)
416                                KillWindow MaskEditPanel#DetData
417                        endif
418                       
419                        flag = WhichListItem("ModelData", ChildList)
420                        if(flag != -1)
421                                KillWindow MaskEditPanel#ModelData
422                        endif
423       
424                        // draw the correct images
[1024]425                        V_DrawPanelToMask(popStr)
[999]426
[1013]427                        // fake a "click" on the radio buttons to re-set the row/col limits
428                        STRUCT WMCheckboxAction cba
429                        cba.eventCode = 2
430                       
431                        ControlInfo check_0
432                        if(V_flag == 1)         //row is currently selected
433                                cba.ctrlName = "check_0"
434                        else
435                                cba.ctrlName = "check_1"
436                        endif
437                       
[1024]438                        V_DrawMaskRadioCheckProc(cba)           //call the radio button action proc     
[1013]439                       
[999]440                        //overlay the mask
441                        V_OverlayMask(popStr,1)
[1002]442
[999]443                        break
444                case -1: // control being killed
445                        break
446        endswitch
447
448        return 0
449End
450
451//
452// SEE DrawDetPanel() in the BeamCenter file
453//
[1002]454// TODO
455// x- currently is hard-wired for the simulation path!   need to make it more generic, especially for RAW data
[999]456//
[1073]457// -- need to adjust the size of the image subwindows
458//
[999]459// -- need to do something for panel "B". currently ignored
460//
[1073]461//
[999]462// draw the selected panel and the model calculation, adjusting for the
463// orientation of the panel and the number of pixels, and pixel sizes
[1024]464Function V_DrawPanelToMask(str)
[999]465        String str
466       
467        // from the selection, find the path to the data
468
469        Variable xDim,yDim
470        Variable left,top,right,bottom
471        Variable height, width
472        Variable left2,top2,right2,bottom2
473        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
474
475       
[1002]476//      Wave dispW=root:curDispPanel
[999]477
478        //plot it in the subwindow with the proper aspect and positioning
479        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
480        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
481       
482       
483        // using two switches -- one to set the panel-specific dimensions
484        // and the other to set the "common" values, some of which are based on the panel dimensions
485
486// set the source of the data. not always VCALC anymore
487        String folder
488        ControlInfo popup_2
489        folder = S_Value
490
491        // TODO -- fix all of this mess
492        if(cmpstr(folder,"VCALC") == 0)
493                // panel-specific values
494                Variable VC_nPix_X = VCALC_get_nPix_X(str)
495                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
496                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
497                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
498
499       
500        // if VCALC declare this way   
501                wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
502                nPix_X = VC_nPix_X
503                nPix_Y = VC_nPix_Y
504                pixSize_X = VC_pixSize_X
505                pixSize_Y = VC_pixSize_Y
506       
507        else
508        // TODO: if real data, need new declaration w/ data as the wave name
509                wave newW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
510
511                nPix_X = V_getDet_pixel_num_x(folder,str)
512                nPix_Y = V_getDet_pixel_num_Y(folder,str)
513                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
514                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
515        endif
516       
517
[1000]518        Variable scale = 10
[999]519       
520        // common values (panel position, etc)
521        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
522        strswitch(str)
523                case "FL":
524                case "FR":
525                case "ML":
526                case "MR":
527                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
528                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
529                       
530                        left = 20
531                        top = 80
532                        right = left+width
533                        bottom = top+height
534                       
535                        left2 = right + 20
536                        right2 = left2 + width
537                        top2 = top
538                        bottom2 = bottom
539                       
540                        break                   
541                case "FT":
542                case "FB":
543                case "MT":
544                case "MB":
545                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
546                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
547                                               
548                        left = 20
549                        top = 80
550                        right = left+width
551                        bottom = top+height
552                       
553                        left2 = left
554                        right2 = right
555                        top2 = top + height + 20
556                        bottom2 = bottom + height + 20
557                       
558                        break
559                case "B":
560                        return(0)               //just exit
561                        break                                           
562                default:
563                        return(0)               //just exit
564        endswitch
565
[1015]566        SetDataFolder root:Packages:NIST:VSANS:Globals:Mask
567       
[999]568        // generate the new panel display
569        duplicate/O newW curDispPanel
570        SetScale/P x 0,1, curDispPanel
571        SetScale/P y 0,1, curDispPanel
572       
[1064]573        Wave LookupWave = root:Packages:NIST:VSANS:Globals:logLookupWave
574
[999]575        //draw the detector panel
576        Display/W=(left,top,right,bottom)/HOST=#
577        AppendImage curDispPanel
578        ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
[1064]579//      ModifyImage curDispPanel log=1          // this fails, since there are data values that are zero
580        ModifyImage curDispPanel ctabAutoscale=0,lookup= LookupWave
[999]581        Label left "Y pixels"
582        Label bottom "X pixels"
583        RenameWindow #,DetData
584        SetActiveSubwindow ##   
585       
586        DoUpdate
587       
[1015]588        SetDataFolder root:
[999]589        return(0)
590End
591
592//
593// overlay the mask
594//
[1073]595// (DONE)
[1002]596// x- remove the old mask first
597// x- make the mask "toggle" to remove it
598// x- go see SANS for color, implementation, etc.
599// x- un-comment the (two) calls
[999]600//
601//
602//toggles a mask on/off of the SANS_Data window
603// points directly to window, doesn't need current display type
604//
605// if state==1, show the mask, if ==0, hide the mask
[1002]606//
[1013]607//** This assumes that if the overlay is/not present on the image display, then the currentTube is also there/not
[1002]608// and is not checked
609//
[999]610Function V_OverlayMask(str,state)
611        String str
612        Variable state
613
614
615        String maskPath = "root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data"
616        if(WaveExists($maskPath) == 1)
[1000]617                if(state == 1)
618                        //duplicate the mask, which is named "data"
619                        wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
620       
621                        Duplicate/O maskW $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
622                        wave overlay = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
[1002]623                        Duplicate/O maskW $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":currentTube")
624                        wave currentTube = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":currentTube")
625
626                        Redimension/D overlay,currentTube
627                        SetScale/P x 0,1, overlay,currentTube
628                        SetScale/P y 0,1, overlay,currentTube
[1000]629               
[1002]630                        //              overlay = (maskW == 1) ? 1 : NaN                        //no need to do this - simply adjust the coloring
631
632                        // update so that the proper row is displayed on the currentTube
633                        currentTube = 0
634                                               
635                        Variable val
636                        ControlInfo setvar0             //get the tube number
637                        val = V_Value
638                       
639                        ControlInfo check_0             // is it row?
640                        Variable isRow = V_value
641                        if(isRow)
642                                currentTube[][val] = 1                 
643                        else
644                                currentTube[val][] = 1
645                        endif                   
646                               
[1000]647                        CheckDisplayed/W=MaskEditPanel#DetData overlay
648                        if(V_flag==0)           //so the overlay doesn't get appended more than once
649                                AppendImage/W=MaskEditPanel#DetData overlay
[1002]650                                AppendImage/W=MaskEditPanel#DetData currentTube
[1000]651                                ModifyImage/W=MaskEditPanel#DetData overlay ctab= {0.9,1,BlueRedGreen,0}        ,minRGB=NaN,maxRGB=0
[1002]652                                ModifyImage/W=MaskEditPanel#DetData currentTube ctab= {0.9,1,CyanMagenta,0}     ,minRGB=NaN,maxRGB=0
[1000]653                //              ModifyImage/W=MaskEditPanel#DetData overlay ctab= {0,*,BlueRedGreen,0} 
654                        endif
655                endif
[999]656
[1000]657                if(state == 0)
658                        wave overlay = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
[1002]659                        wave currentTube = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":currentTube")
660
[1000]661                        CheckDisplayed/W=MaskEditPanel#DetData overlay
662//                      Print "V_flag = ",V_flag
[999]663       
[1000]664                        If(V_Flag == 1)         //overlay is present
665                                RemoveImage/W=MaskEditPanel#DetData overlay
[1002]666                                RemoveImage/W=MaskEditPanel#DetData currentTube
[1000]667                        endif
668                endif
[999]669        Endif
670       
671        return(0)
672End
673
674
[1024]675Function V_SaveMaskButtonProc(ba) : ButtonControl
[1000]676        STRUCT WMButtonAction &ba
677
678        switch( ba.eventCode )
679                case 2: // mouse up
680                        // click code here
681                       
[1015]682                        // fills in a "default mask" in a separate folder to then write out
[1000]683                        Execute "H_Setup_VSANS_MASK_Structure()"
684                       
685                        // fill with current "stuff"
[1015]686                        SetDataFolder root:VSANS_MASK_file:entry       
[1000]687                        Wave/T title    = title
[1043]688                        title = "This is a custom MASK file for VSANS: VSANS_MASK"
[1000]689                        SetDataFolder root:
690                       
691                       
[1015]692                // copy over what was actually drawn for all of the detector panels
[1000]693
694                        Variable ii
695                        String str
696                        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
697                                str = StringFromList(ii, ksDetectorListAll, ";")
698                                Wave det_str = $("root:VSANS_MASK_file:entry:instrument:detector_"+str+":data")
699                                wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")                   
700                                det_str = maskW
701                        endfor
702
703                        //save it
704//                      String fileName = "ThisIsAMASK"
705
706                        Execute "Save_VSANS_MASK_Nexus()"
707                       
708                        break
709                case -1: // control being killed
710                        break
711        endswitch
712
713        SetDataFolder root:
714        return 0
715End
716
717
[999]718////////////// fake MASK file tests
719//
720//
721//      Make/O/T/N=1    file_name       = "VSANS_MASK_test.h5"
722//
723// simple generation of a fake MASK file. for sans, nothing other than the creation date was written to the
724// file header. nothing more is needed (possibly)
725//
726//
[1050]727// TODO
[1073]728// -- make the number of pixels GLOBAL to pick up the right numbers for the detector dimensions
[1050]729//  x- there will be lots of work to do to develop the procedures necessary to actually generate the
[999]730//      9 data sets to become the MASK file contents. More complexity here than for the simple SANS case.
731//
[1050]732//  x- this is currently random 0|1 values, need to write an editor
[999]733//
734// currently set up to use 1 = YES MASK == exclude the data
735//      and 0 = NO MASK == keep the data
736//
737Proc H_Setup_VSANS_MASK_Structure()
738       
739        NewDataFolder/O/S root:VSANS_MASK_file         
740
741        NewDataFolder/O/S root:VSANS_MASK_file:entry   
[1043]742                Make/O/T/N=1    title   = "This is a MASK file for VSANS: VSANS_MASK"
[999]743                Make/O/T/N=1    start_date      = "2015-02-28T08:15:30-5:00"
744                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument         
745                        Make/O/T/N=1    name    = "NG3_VSANS"
746                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_B     
747                        Make/O/I/N=(150,150)    data    = 0
748                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MR             
749                        Make/O/I/N=(48,128)     data    = 0
750                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_ML             
751                        Make/O/I/N=(48,128)     data    = 0
752                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MT             
753                        Make/O/I/N=(128,48)     data    = 0
754                        data[0,49][] = 1
755                        data[78,127][] = 1
756                        data[50,77][] = 0
757                       
758                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MB             
759                        Make/O/I/N=(128,48)     data    = 0
760                        data[0,49][] = 1
761                        data[78,127][] = 1
762                        data[50,77][] = 0
763                       
764                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FR             
765                        Make/O/I/N=(48,128)     data    = 0
766                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FL             
767                        Make/O/I/N=(48,128)     data    = 0
768                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FT             
769                        Make/O/I/N=(128,48)     data    = 0
770                        data[0,49][] = 1
771                        data[78,127][] = 1
772                        data[50,77][] = 0
773
774                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FB             
775                        Make/O/I/N=(128,48)     data    = 0
776                        data[0,49][] = 1
777                        data[78,127][] = 1
778                        data[50,77][] = 0
[1025]779
780
781                // fake, empty folders so that the generic loaders can be used
782                NewDataFolder/O root:VSANS_MASK_file:entry:DAS_logs
783                NewDataFolder/O root:VSANS_MASK_file:entry:control
784                NewDataFolder/O root:VSANS_MASK_file:entry:reduction
785                NewDataFolder/O root:VSANS_MASK_file:entry:sample
786                NewDataFolder/O root:VSANS_MASK_file:entry:user                 
[999]787        SetDataFolder root:
788
789End
790
[1015]791
792// this default mask is only generated on startup of the panel, if a mask
793// has not been previously loaded. If any mask is present ("FT" is tested) then
794// this function is skipped and the existing mask is not overwritten
795Function V_GenerateDefaultMask()
796
797        NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry   
[1025]798                Make/O/T/N=1    title   = "This is a MASK file for VSANS: VSANS_MASK"
[1015]799                Make/O/T/N=1    start_date      = "2015-02-28T08:15:30-5:00"
800                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument         
801                        Make/O/T/N=1    name    = "NG3_VSANS"
802                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_B     
803                        Make/O/I/N=(150,150)    data    = 0
804                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_MR             
805                        Make/O/I/N=(48,128)     data    = 0
806                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_ML             
807                        Make/O/I/N=(48,128)     data    = 0
808                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_MT             
809                        Make/O/I/N=(128,48)     data    = 0
810                        data[0,49][] = 1
811                        data[78,127][] = 1
812                        data[50,77][] = 0
813                       
814                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_MB             
815                        Make/O/I/N=(128,48)     data    = 0
816                        data[0,49][] = 1
817                        data[78,127][] = 1
818                        data[50,77][] = 0
819                       
820                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_FR             
821                        Make/O/I/N=(48,128)     data    = 0
822                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_FL             
823                        Make/O/I/N=(48,128)     data    = 0
824                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_FT             
825                        Make/O/I/N=(128,48)     data    = 0
826                        data[0,49][] = 1
827                        data[78,127][] = 1
828                        data[50,77][] = 0
829
830                NewDataFolder/O/S root:Packages:NIST:VSANS:MSK:entry:instrument:detector_FB             
831                        Make/O/I/N=(128,48)     data    = 0
832                        data[0,49][] = 1
833                        data[78,127][] = 1
834                        data[50,77][] = 0
835                       
836        SetDataFolder root:
837
838end
839
[999]840////////////////////// MASK FILE
841
842
[1073]843// (DONE)
844// x- currently, there are no dummy fill values or attributes for the fake MASK file
[999]845//
846Proc Setup_VSANS_MASK_Struct()
847
848        // lays out the tree and fills with dummy values
849        H_Setup_VSANS_MASK_Structure()
850       
851        // writes in the attributes
852//      H_Fill_VSANS_Attributes()
853       
[1023]854
[999]855End
856
857Proc Save_VSANS_MASK_Nexus(fileName)
858        String fileName="Test_VSANS_MASK_file"
859
860        // save as HDF5 (no attributes saved yet)
861        Save_VSANS_file("root:VSANS_MASK_file", fileName+".h5")
862       
[1002]863//      // read in a data file using the gateway-- reads from the home path
864//      H_HDF5Gate_Read_Raw(fileName+".h5")
865//     
866//      // after reading in a "partial" file using the gateway (to generate the xref)
867//      // Save the xref to disk (for later use)
868//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
869//     
870//      // after you've generated the HDF5___xref, load it in and copy it
871//      // to the necessary folder location.
872//      Copy_HDF5___xref("root:VSANS_MASK_file", "HDF5___xref")
873//     
874//      // writes out the contents of a data folder using the gateway
875//      H_HDF5Gate_Write_Raw("root:VSANS_MASK_file", fileName+".h5")
876//
877//      // re-load the data file using the gateway-- reads from the home path
878//      // now with attributes
879//      H_HDF5Gate_Read_Raw(fileName+".h5")
[999]880       
881End
Note: See TracBrowser for help on using the repository browser.