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

Last change on this file since 999 was 999, checked in by srkline, 7 years ago

changes to a few analysis models to make these Igor 7-ready

adding mask editing utilities

many changes to event mode for easier processing of split lists

updated event mode help file

+ lots more!

File size: 13.1 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5// TODO:
6// x- CHANGE the mask behavior to a more logical choice - and consistent with SANS
7//   x- CHANGE to:
8// 1 == mask == discard data
9// 0 == no Mask == keep data
10// x- and then make the corresponding changes in the I(Q) routines
11
12
13// also, move the mask generating utilities from VC_HDF5_Utils into this procedure - to keep
14// all of the mask procedures together
15
16
17//
18// -- this is to be a very simple editor to generate masks row/column wise, not drawing
19//
20
21
22//TODO
23// -- draw a mask
24// -- save a mask (all panels)
25// -- be able to save the mask name to the file
26// -- be able to read a mask based on what is in the data file
27//
28// x- biggest thing now is to re-write the DrawDetPanel() routine from the beamCenter.ipf
29//    to do what this panel needs
30//
31// -- lots to clean up
32// -- add this to the list of includes, move the file to SVN, and add it.
33//
34// -- for working with VCALC -- maybe have an automatic generator (if val < -2e6, mask = 0)
35//    this can be checked column-wise to go faster (1st index)
36//
37// x- re-write V_OverlayMask to make the "overlay" wave that has the NaNs, and then the drawing
38//    routines need to be aware of this
39
40Macro Edit_a_Mask()
41        V_EditMask()
42end
43
44Function V_EditMask()
45        DoWindow/F MaskEditPanel
46        if(V_flag==0)
47                Execute "MaskEditorPanel()"
48        endif
49End
50
51//
52// TODO - may need to adjust the display for the different pixel dimensions
53//      ModifyGraph width={Plan,1,bottom,left}
54//
55Proc MaskEditorPanel() : Panel
56        PauseUpdate; Silent 1           // building window...
57
58        NewPanel /W=(662,418,1586,960)/N=MaskEditPanel/K=1
59//      ShowTools/A
60       
61        PopupMenu popup_0,pos={20,50},size={109,20},proc=SetMaskPanelPopMenuProc,title="Detector Panel"
62        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;MR;ML;MT;MB;B;\""
63        PopupMenu popup_2,pos={20,20},size={109,20},title="Data Source"//,proc=SetFldrPopMenuProc
64        PopupMenu popup_2,mode=1,popvalue="VCALC",value= #"\"RAW;SAM;VCALC;\""
65               
66//      Button button_0,pos={486,20},size={80,20},proc=DetFitGuessButtonProc,title="Guess"
67//      Button button_1,pos={615,20},size={80,20},proc=DetFitButtonProc,title="Do Fit"
68//      Button button_2,pos={744,20},size={80,20},proc=DetFitHelpButtonProc,title="Help"
69//      Button button_3,pos={615,400},size={110,20},proc=WriteCtrButtonProc,title="Write Centers"
70//      Button button_4,pos={730,400},size={110,20},proc=CtrTableButtonProc,title="Ctr table"
71//      Button button_5,pos={730,440},size={110,20},proc=WriteCtrTableButtonProc,title="Write table"
72
73// TODO -- need buttons for save? quit?
74// setVariable to add a row to the mask, column to the mask, toggle the mask on/off to see what's
75//     happening with the data
76
77
78// TODO - get rid of the hard-wired panel choice
79        duplicate/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FL:det_FL curDispPanel
80        SetScale/P x 0,1, curDispPanel
81        SetScale/P y 0,1, curDispPanel
82
83        // draw the correct images
84        //draw the detector panel
85        DrawPanelToMask("FL")
86       
87        // overlay the current mask
88        V_OverlayMask("FL",1)
89//      OverlayMaskPanel("FL")
90
91EndMacro
92
93//
94// function to choose which detector panel to display, and then to actually display it
95//
96Function SetMaskPanelPopMenuProc(pa) : PopupMenuControl
97        STRUCT WMPopupAction &pa
98
99        switch( pa.eventCode )
100                case 2: // mouse up
101                        Variable popNum = pa.popNum
102                        String popStr = pa.popStr
103                                               
104                        // remove the old image (it may not be the right shape)
105                        // -- but make sure it exists first...
106                        String childList = ChildWindowList("MaskEditPanel")
107                        Variable flag
108                       
109                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
110                        if(flag != -1)
111                                KillWindow MaskEditPanel#DetData
112                        endif
113                       
114                        flag = WhichListItem("ModelData", ChildList)
115                        if(flag != -1)
116                                KillWindow MaskEditPanel#ModelData
117                        endif
118       
119                        // draw the correct images
120                        DrawPanelToMask(popStr)
121
122                        //overlay the mask
123                        V_OverlayMask(popStr,1)
124//                      OverlayMaskPanel(popStr)
125                       
126                        break
127                case -1: // control being killed
128                        break
129        endswitch
130
131        return 0
132End
133
134//
135// SEE DrawDetPanel() in the BeamCenter file
136//
137// TODO - currently is hard-wired for the simulation path!
138//     need to make it more generic, especially for RAW data
139//
140// -- need to adjust the size of the image subwindows to keep the model
141//    calculation from spillon over onto the table (maybe just move the table)
142// -- need to do something for panel "B". currently ignored
143// -- currently the pixel sizes for "real" data is incorrect in the file
144//     and this is why the plots are incorrectly sized
145//
146// draw the selected panel and the model calculation, adjusting for the
147// orientation of the panel and the number of pixels, and pixel sizes
148Function DrawPanelToMask(str)
149        String str
150       
151        // from the selection, find the path to the data
152
153        Variable xDim,yDim
154        Variable left,top,right,bottom
155        Variable height, width
156        Variable left2,top2,right2,bottom2
157        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
158
159       
160        Wave dispW=root:curDispPanel
161
162        //plot it in the subwindow with the proper aspect and positioning
163        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
164        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
165       
166       
167        // using two switches -- one to set the panel-specific dimensions
168        // and the other to set the "common" values, some of which are based on the panel dimensions
169
170// set the source of the data. not always VCALC anymore
171        String folder
172        ControlInfo popup_2
173        folder = S_Value
174
175        // TODO -- fix all of this mess
176        if(cmpstr(folder,"VCALC") == 0)
177                // panel-specific values
178                Variable VC_nPix_X = VCALC_get_nPix_X(str)
179                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
180                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
181                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
182
183       
184        // if VCALC declare this way   
185                wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
186                nPix_X = VC_nPix_X
187                nPix_Y = VC_nPix_Y
188                pixSize_X = VC_pixSize_X
189                pixSize_Y = VC_pixSize_Y
190       
191        else
192        // TODO: if real data, need new declaration w/ data as the wave name
193                wave newW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
194
195                nPix_X = V_getDet_pixel_num_x(folder,str)
196                nPix_Y = V_getDet_pixel_num_Y(folder,str)
197                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
198                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
199        endif
200       
201
202        Variable scale = 5
203       
204        // common values (panel position, etc)
205        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
206        strswitch(str)
207                case "FL":
208                case "FR":
209                case "ML":
210                case "MR":
211                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
212                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
213                       
214                        left = 20
215                        top = 80
216                        right = left+width
217                        bottom = top+height
218                       
219                        left2 = right + 20
220                        right2 = left2 + width
221                        top2 = top
222                        bottom2 = bottom
223                       
224                        break                   
225                case "FT":
226                case "FB":
227                case "MT":
228                case "MB":
229                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
230                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
231                                               
232                        left = 20
233                        top = 80
234                        right = left+width
235                        bottom = top+height
236                       
237                        left2 = left
238                        right2 = right
239                        top2 = top + height + 20
240                        bottom2 = bottom + height + 20
241                       
242                        break
243                case "B":
244                        return(0)               //just exit
245                        break                                           
246                default:
247                        return(0)               //just exit
248        endswitch
249
250        // generate the new panel display
251        duplicate/O newW curDispPanel
252        SetScale/P x 0,1, curDispPanel
253        SetScale/P y 0,1, curDispPanel
254       
255        //draw the detector panel
256        Display/W=(left,top,right,bottom)/HOST=#
257        AppendImage curDispPanel
258        ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
259        Label left "Y pixels"
260        Label bottom "X pixels"
261        RenameWindow #,DetData
262        SetActiveSubwindow ##   
263       
264        DoUpdate
265       
266        return(0)
267End
268
269//
270// overlay the mask
271//
272// TODO
273// -- make it work
274// -- remove the old mask first
275// -- make the mask "toggle" to remove it
276// -- go see SANS for color, implementation, etc.
277// -- un-comment the (two) calls
278//
279//
280//toggles a mask on/off of the SANS_Data window
281// points directly to window, doesn't need current display type
282//
283// if state==1, show the mask, if ==0, hide the mask
284Function V_OverlayMask(str,state)
285        String str
286        Variable state
287
288
289        String maskPath = "root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data"
290        if(WaveExists($maskPath) == 1)
291                //duplicate the mask, which is named "data"
292                wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":data")
293
294                Duplicate/O maskW $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
295                wave overlay = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+str+":overlay")
296
297                Redimension/D overlay
298                SetScale/P x 0,1, overlay
299                SetScale/P y 0,1, overlay
300       
301                String tempStr = "root:Packages:NIST:MSK:overlay"
302                overlay = (maskW == 1) ? 1 : NaN
303//              ResetLoop(tempStr)              //keeps 1's and sets 0's to NaN
304
305                AppendImage/W=MaskEditPanel#DetData overlay
306                ModifyImage/W=MaskEditPanel#DetData overlay ctab= {0,*,BlueRedGreen,0} 
307
308//     
309//              //check to see if mask overlay is currently displayed
310//              DoWindow SANS_Data
311//              if(V_flag==0)
312//                      return(0)
313//              endif
314//             
315//              CheckDisplayed/W=SANS_Data root:Packages:NIST:MSK:overlay
316//              //Print "V_flag = ",V_flag
317//     
318//              If(V_Flag == 1)         //overlay is present
319//                      if(state==0)
320//                              RemoveImage overlay
321//                      endif           //don't need to do anything if we want to keep the mask
322//              Else            //overlay is not present
323//                      if(state==1)
324//                              //append the new overlay
325//                              AppendImage/L=left/B=bottom root:Packages:NIST:MSK:overlay
326//                              //set the color table to vary from 0 to * (=max data = 1), with blue maximum
327//                              //Nan's will appear transparent (just a general feature of images)
328//                              ModifyImage/W=SANS_Data overlay ctab={0,*,BlueRedGreen,0}
329//                      endif           //don't do anything if we don't want the overlay
330//              Endif
331//             
332        Endif
333       
334        return(0)
335End
336
337
338////////////// fake MASK file tests
339//
340//
341//      Make/O/T/N=1    file_name       = "VSANS_MASK_test.h5"
342//
343// simple generation of a fake MASK file. for sans, nothing other than the creation date was written to the
344// file header. nothing more is needed (possibly)
345//
346//
347// TODO -- make the number of pixels GLOBAL
348// TODO -- there will be lots of work to do to develop the procedures necessary to actually generate the
349//      9 data sets to become the MASK file contents. More complexity here than for the simple SANS case.
350//
351// TODO -- this is currently random 0|1 values, need to write an editor
352//
353// currently set up to use 1 = YES MASK == exclude the data
354//      and 0 = NO MASK == keep the data
355//
356Proc H_Setup_VSANS_MASK_Structure()
357       
358        NewDataFolder/O/S root:VSANS_MASK_file         
359
360        NewDataFolder/O/S root:VSANS_MASK_file:entry   
361                Make/O/T/N=1    title   = "This is a fake MASK file for VSANS"
362                Make/O/T/N=1    start_date      = "2015-02-28T08:15:30-5:00"
363                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument         
364                        Make/O/T/N=1    name    = "NG3_VSANS"
365                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_B     
366                        Make/O/I/N=(150,150)    data    = 0
367                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MR             
368                        Make/O/I/N=(48,128)     data    = 0
369                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_ML             
370                        Make/O/I/N=(48,128)     data    = 0
371                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MT             
372                        Make/O/I/N=(128,48)     data    = 0
373                        data[0,49][] = 1
374                        data[78,127][] = 1
375                        data[50,77][] = 0
376                       
377                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_MB             
378                        Make/O/I/N=(128,48)     data    = 0
379                        data[0,49][] = 1
380                        data[78,127][] = 1
381                        data[50,77][] = 0
382                       
383                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FR             
384                        Make/O/I/N=(48,128)     data    = 0
385                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FL             
386                        Make/O/I/N=(48,128)     data    = 0
387                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FT             
388                        Make/O/I/N=(128,48)     data    = 0
389                        data[0,49][] = 1
390                        data[78,127][] = 1
391                        data[50,77][] = 0
392
393                NewDataFolder/O/S root:VSANS_MASK_file:entry:instrument:detector_FB             
394                        Make/O/I/N=(128,48)     data    = 0
395                        data[0,49][] = 1
396                        data[78,127][] = 1
397                        data[50,77][] = 0
398                       
399        SetDataFolder root:
400
401End
402
403////////////////////// MASK FILE
404
405
406// TODO
407// currently, there are no dummy fill values or attributes for the fake MASK file
408//
409Proc Setup_VSANS_MASK_Struct()
410
411        // lays out the tree and fills with dummy values
412        H_Setup_VSANS_MASK_Structure()
413       
414        // writes in the attributes
415//      H_Fill_VSANS_Attributes()
416       
417        // fill in with VCALC simulation bits
418//      H_Fill_VSANS_wSim()
419       
420End
421
422Proc Save_VSANS_MASK_Nexus(fileName)
423        String fileName="Test_VSANS_MASK_file"
424
425        // save as HDF5 (no attributes saved yet)
426        Save_VSANS_file("root:VSANS_MASK_file", fileName+".h5")
427       
428        // read in a data file using the gateway-- reads from the home path
429        H_HDF5Gate_Read_Raw(fileName+".h5")
430       
431        // after reading in a "partial" file using the gateway (to generate the xref)
432        // Save the xref to disk (for later use)
433        Save_HDF5___xref("root:"+fileName,"HDF5___xref")
434       
435        // after you've generated the HDF5___xref, load it in and copy it
436        // to the necessary folder location.
437        Copy_HDF5___xref("root:VSANS_MASK_file", "HDF5___xref")
438       
439        // writes out the contents of a data folder using the gateway
440        H_HDF5Gate_Write_Raw("root:VSANS_MASK_file", fileName+".h5")
441
442        // re-load the data file using the gateway-- reads from the home path
443        // now with attributes
444        H_HDF5Gate_Read_Raw(fileName+".h5")
445       
446End
Note: See TracBrowser for help on using the repository browser.