source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Initialize.ipf @ 1104

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

updated mask drawing procedures to allow draw/erase of different shapes, rather than limited to single tubes.

added USANS_SlitSmearing.ipf back to the includes, removing the VSANS version which was duplicated.

File size: 16.0 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2#pragma version=0.1
3#pragma IgorVersion=6.1
4
5//***********************
6// NOV 2015 Vers 0.1
7//
8// Initialization procedures that must be run before anything
9// this is accomplished by placing:
10//
11// Initialize()
12// #include "includes"
13//
14// in the built-in procedure window of the .pxt (template) experiment
15// IGOR recognizes this, and executes Initialize() immediately after
16// compiling all of the included procedures. This is all done as the blank
17// template is opened
18//
19// Choosing initialize from the VSANS menu will do the same, and no harm is done
20// to the experiment by re- initializing. no data or folders are overwritten
21//
22//************************
23
24
25
26// TODO -- need to set up a separate file of "constants" or "globals" where the actual numbers are
27//stored. If there are not a lot, that place could be here. InitFacilityGlobals() is currently in NCNR_Utils.ipf
28
29
30// for the change in July 2017 where the beam center is now defined in cm, rather than pixels.
31// this need not ever change from 1
32Constant kBCTR_CM = 1                   //set to 1 to use beam center in cm. O to use pixels
33
34// // TODO: -- replace this constant with V_getDet_panel_gap(fname,detStr)
35//Constant kPanelTouchingGap = 10                       // TODO -- measure this gap when panels "touch", UNITS OF mm, not cm
36
37
38// the base data folder path where the raw data is loaded
39Strconstant ksBaseDFPath = "root:Packages:NIST:VSANS:RawVSANS:"
40
41
42// the list of WORK Folders
43// RawVSANS does not behave as a WORK folder, but it is local. so add it in explicitly to the list if needed
44// VCALC behaves *almost* as a WORK folder, but it is local. so add it in explicitly to the list if needed
45//Strconstant ksWorkFolderList = "RAW;SAM;EMP;BGD;COR;DIV;ABS;MSK;CAL;STO;SUB;DRK;ADJ;VCALC;RawVSANS;"
46Strconstant ksWorkFolderListShort = "RAW;SAM;EMP;BGD;COR;DIV;ABS;MSK;CAL;STO;SUB;DRK;ADJ;"
47
48
49// for defining which "bin type" corresponds to which set of extensions for I(q) data
50// !! see V_BinTypeStr2Num() for the numbering, not the order of the list
51//
52//////////////////
53//Strconstant ksBinTypeStr = "One;Two;Four;Slit Mode;"
54Strconstant ksBinTypeStr = "F4-M4-B;F2-M2-B;F1-M1-B;F2-M1-B;F1-M2xTB-B;F2-M2xTB-B;SLIT-F2-M2-B;"
55Strconstant ksBinType1 = "FT;FB;FL;FR;MT;MB;ML;MR;B;"           //these are the "active" extensions
56Strconstant ksBinType2 = "FTB;FLR;MTB;MLR;B;"
57Strconstant ksBinType3 = "FLRTB;MLRTB;B;"
58//Strconstant ksBinType4 = "FT;FB;FL;FR;MT;MB;ML;MR;B;"
59Strconstant ksBinType4 = "FL;FR;ML;MR;B;"               //in SLIT mode, disregard the T/B panels
60Strconstant ksBinType5 = "FTB;FLR;MLRTB;B;"
61Strconstant ksBinType6 = "FLRTB;MLR;B;"
62Strconstant ksBinType7 = "FTB;FLR;MLR;B;"
63///////////////////
64
65
66// for looping over each detector
67Strconstant ksDetectorListNoB = "FL;FR;FT;FB;ML;MR;MT;MB;"
68Strconstant ksDetectorListAll = "FL;FR;FT;FB;ML;MR;MT;MB;B;"
69
70
71// for Protocols
72Constant kNumProtocolSteps = 12
73// for trimming of the I(q) data sets, and part of the protocol
74Strconstant ksPanelBinTypeList = "B;FT;FB;FL;FR;MT;MB;ML;MR;FTB;FLR;MTB;MLR;FLRTB;MLRTB;"
75Strconstant ksBinTrimBegDefault = "B=5;FT=3;FB=3;FL=3;FR=3;MT=3;MB=3;ML=3;MR=3;FTB=2;FLR=2;MTB=2;MLR=2;FLRTB=1;MLRTB=1;"
76Strconstant ksBinTrimEndDefault = "B=10;FT=5;FB=5;FL=5;FR=5;MT=5;MB=5;ML=5;MR=5;FTB=4;FLR=4;MTB=4;MLR=4;FLRTB=3;MLRTB=3;"
77
78
79
80
81Proc Initialize_VSANS()
82        V_Initialize()
83End
84
85//this is the main initualization procedure that must be the first thing
86//done when opening a new Data reduction experiment
87//
88//sets up data folders, globals, protocols, and draws the main panel
89Proc V_Initialize()
90
91        Variable curVersion = 0.1
92        Variable oldVersion = NumVarOrDefault("root:VSANS_RED_VERSION",curVersion)
93               
94        if(oldVersion == curVersion)
95                //must just be a new startup with the current version
96                Variable/G root:VSANS_RED_VERSION=0.1
97        endif
98       
99        if(oldVersion < curVersion)
100                String str =    "This experiment was created with version "+num2str(oldVersion)+" of the macros. I'll try to make this work, but please start new work with a current template"
101                DoAlert 0,str
102        endif
103       
104        V_InitFolders()
105       
106        VC_Initialize_Space()           //initialize folders for VCALC
107       
108        V_InitFakeProtocols()
109        V_InitGlobals()
110        V_InitFacilityGlobals()
111        DoWindow/F Main_VSANS_Panel
112        If(V_flag == 0)
113                //draw panel
114                Main_VSANS_Panel()
115        Endif
116//      V_ResizeCmdWindow()
117
118// TODO - be sure that NCNR is defined correctly       
119        //unload the NCNR_Package_Loader, if NCNR not defined
120        UnloadNCNR_VSANS_Procedures()
121
122End
123
124//creates all the necessary data folders in the root folder
125//does not overwrite any existing folders of the same name
126//it leaves data in them untouched
127//
128// x-- make sure that I have all of the folders that I need
129//
130Function V_InitFolders()
131       
132        NewDataFolder/O root:Packages
133        NewDataFolder/O root:Packages:NIST
134        NewDataFolder/O root:Packages:NIST:VSANS
135       
136// for the file catalog
137        NewDataFolder/O root:Packages:NIST:VSANS:CatVSHeaderInfo
138// for the globals
139        NewDataFolder/O root:Packages:NIST:VSANS:Globals
140// for the raw nexus data (so I don't need to reload to get a single value)
141        NewDataFolder/O root:Packages:NIST:VSANS:RawVSANS
142
143// folders for the reduction steps             
144        NewDataFolder/O root:Packages:NIST:VSANS:RAW
145        NewDataFolder/O root:Packages:NIST:VSANS:SAM
146        NewDataFolder/O root:Packages:NIST:VSANS:EMP
147        NewDataFolder/O root:Packages:NIST:VSANS:BGD
148        NewDataFolder/O root:Packages:NIST:VSANS:COR
149        NewDataFolder/O root:Packages:NIST:VSANS:DIV
150        NewDataFolder/O root:Packages:NIST:VSANS:MSK
151        NewDataFolder/O root:Packages:NIST:VSANS:ABS
152        NewDataFolder/O root:Packages:NIST:VSANS:CAL
153        NewDataFolder/O root:Packages:NIST:VSANS:STO
154        NewDataFolder/O root:Packages:NIST:VSANS:SUB
155        NewDataFolder/O root:Packages:NIST:VSANS:DRK
156        NewDataFolder/O root:Packages:NIST:VSANS:ADJ
157
158
159// ?? anything else
160
161// for simulation
162//      NewDataFolder/O root:Packages:NIST:VSANS:SAS
163
164
165       
166        Return(0)
167End
168
169
170
171
172//
173//Global folder already exists...
174//adds appropriate globals to the newly created myGlobals folder
175//return data folder to root: before leaving
176//
177//
178Function V_InitGlobals()
179       
180       
181        Variable/G root:Packages:NIST:VSANS:Globals:gIsLogScale = 0
182        String/G root:Packages:NIST:VSANS:Globals:gCurDispType = "RAW"
183       
184        //check platform, so Angstrom can be drawn correctly
185
186        //TODO  -- this is different on Igor 7. Macintosh # has been updated, but Windows has not
187        // use Print char2num("Å") to find the magic number
188        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
189                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(197)
190                String/G root:Packages:NIST:gAngstStr = num2char(197)
191                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 1
192        else
193                //either Windows or Windows NT
194                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(-59)
195                String/G root:Packages:NIST:gAngstStr = num2char(-59)
196                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 0
197                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
198                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
199        endif
200       
201        // TODO x- find the SANS preferences, copy over and update for VSANS
202        // x- these are all in PlotUtilsMacro_v40.ipf as the preferences are set up as common
203        // to all packages. I'm not sure that I want to do this with VSANS, but make the packages
204        // separate entities. I'm seeing little benefit of the crossover, especially now that
205        // Analysis is not mine. So for VSANS, there is a new, separate file: V_VSANS_Preferences.ipf
206
207        //this is critical to initialize now - as it has the y/n flags for the detector correction steps
208        Execute "Initialize_VSANSPreferences()"
209
210       
211        // set the lookup waves for log/lin display of the detector images
212        V_MakeImageLookupTables(10000,0,1)
213
214
215
216        //set flag if Demo Version is detected
217        Variable/G root:Packages:NIST:VSANS:Globals:isDemoVersion = V_isDemo()
218       
219        //set XML globals
220//      String/G root:Packages:NIST:gXMLLoader_Title = ""
221       
222        Return(0)
223End
224
225//
226//num = number of points (10000 seeems to be a good number so far)
227// lo = lower value (between 0 and 1)
228// hi = upper value (between 0 and 1)
229//
230// note that it is currenty NOT OK for lo > hi (!= reversed color scale, right now log(negative) == bad)
231//
232// TODO hi, lo not used properly here, seems to mangle log display now that I'm switching the lo,hi of the ctab
233//
234Function V_MakeImageLookupTables(num,lo,hi)
235        Variable num,lo,hi
236
237                // lookup waves for log and linear display of images
238        // this is used for the main data display. With this, I can use the original
239        // detector data (no copy) and the zeros in the data set are tolerated when displaying
240        // on log scale
241        SetDataFolder root:Packages:NIST:VSANS:Globals
242        Variable val,offset
243       
244        offset = 1/num          //can't use 1/lo if lo == 0
245       
246        Make/O/D/N=(num) logLookupWave,linearLookupWave
247       
248        linearLookupWave = (p+1)/num
249       
250       
251        logLookupWave = log(linearLookupWave)
252        val = logLookupWave[0]
253        logLookupWave += -val + offset
254        val = logLookupWave[num-1]
255        logLookupWave /= val
256       
257        SetDataFolder root:
258       
259        return(0)
260end
261
262//
263// initializes globals that are specific to VSANS
264//
265// there really should be nothing here... all of this should now be in the Nexus data file
266// and not tethered to hard-wired constants.
267//
268// -- what was here was:
269// number of detector pixels
270// pixel size
271// deadtime
272// beamstop "tolerance" to identify Trans files
273// sample aperture offset
274//
275Function V_InitFacilityGlobals()
276
277//      //Detector -specific globals
278//      Variable/G root:myGlobals:gNPixelsX=128
279//      Variable/G root:myGlobals:gNPixelsY=128
280//     
281//      // as of Jan2008, detector pixel sizes are read directly from the file header, so they MUST
282//      // be set correctly in instr.cfg - these values are not used, but declared to avoid errors
283//      Variable/G root:myGlobals:PixelResNG3_ILL = 1.0         //pixel resolution in cm
284//      Variable/G root:myGlobals:PixelResNG5_ILL = 1.0
285//      Variable/G root:myGlobals:PixelResNG7_ILL = 1.0
286//      Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5
287//      Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5
288//      Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5
289//      Variable/G root:myGlobals:PixelResNGB_ORNL = 0.5
290////    Variable/G root:myGlobals:PixelResCGB_ORNL = 0.5                // fiction
291//
292//      Variable/G root:myGlobals:PixelResDefault = 0.5
293//     
294//      Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6              //deadtime in seconds
295//      Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6
296//      Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6
297//      Variable/G root:myGlobals:DeadtimeNGB_ILL = 4.0e-6              // fictional
298//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_VAX = 3.4e-6         //pre - 23-JUL-2009 used VAX
299//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_ICE = 1.5e-6         //post - 23-JUL-2009 used ICE
300//      Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6                     //as of 9 MAY 2002
301//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_VAX = 3.4e-6         //pre 25-FEB-2010 used VAX
302//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_ICE = 2.3e-6         //post 25-FEB-2010 used ICE
303//      Variable/G root:myGlobals:DeadtimeNGB_ORNL_ICE = 4.0e-6         //per JGB 16-JAN-2013, best value we have for the oscillating data
304//
305////    Variable/G root:myGlobals:DeadtimeCGB_ORNL_ICE = 1.5e-6         // fiction
306//
307//      Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6
308//
309//      //new 11APR07
310//      Variable/G root:myGlobals:BeamstopXTol = -8                     // (cm) is BS Xpos is -5 cm or less, it's a trans measurement
311//      // sample aperture offset is NOT stored in the VAX header, but it should be
312//      // - when it is, remove the global and write an accessor AND make a place for
313//      // it in the RealsRead
314//      Variable/G root:myGlobals:apOff = 5.0                           // (cm) distance from sample aperture to sample position
315
316End
317
318///////////////////////////////////////////////
319// TODO
320////////////// everything below needs to be re-written for VSANS
321//
322//////////////////////////////////////////////
323
324
325//
326// do I need to make the protocols any longer for VSANS? (yes -- now 12 points)
327// What other options for processing / averaging / saving are needed??
328//  TODO
329// x- likely that I'll want to have #pts to cut from I(q) as input to NSORT within the protocol so that the
330// entire reduction can be automatic
331//
332//
333// x- creates the "base" protocols that should be available, after creating the data folder
334// x- all protocols are kept in the root:Packages:NIST:VSANS:Globals:Protocols folder, created here
335//
336//
337//*****as of 05_2017, protocols are 12 points long, [6] is used for work.drk, [7,8] are for trimmig points, and [9,11] are currently unused
338//
339Function V_InitFakeProtocols()
340       
341        NewDataFolder/O root:Packages:NIST:VSANS:Globals:Protocols
342        Make/O/T $"root:Packages:NIST:VSANS:Globals:Protocols:Base"={"none","none","ask","ask","none","AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;BINTYPE=F4-M4-B;","DRK=none,DRKMODE=0,","","","","",""}
343        Make/O/T $"root:Packages:NIST:VSANS:Globals:Protocols:DoAll"={"ask","ask","ask","ask","ask","AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;BINTYPE=F4-M4-B;","DRK=none,DRKMODE=0,","","","","",""}
344        Make/O/T/N=(kNumProtocolSteps) $"root:Packages:NIST:VSANS:Globals:Protocols:CreateNew"                  //null wave
345        //Initialize waves to store values in
346       
347        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr=""
348        String/G root:Packages:NIST:VSANS:Globals:Protocols:gNewStr=""
349        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = "AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;BINTYPE=F4-M4-B;"
350       
351        String/G root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr=""
352        String/G root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr=""
353       
354        Return(0)
355End
356
357//simple function to resize the comand window to a nice size, no matter what the resolution
358//need to test out on several different monitors and both platforms
359//
360// could easily be incorporated into the initialization routines to ensure that the
361// command window is always visible at startup of the macros. No need for a hook function
362//
363Function V_ResizeCmdWindow()
364
365        String str=IgorInfo(0),rect="",platform=igorinfo(2)
366        Variable depth,left,top,right,bottom,factor
367       
368        if(cmpstr(platform,"Macintosh")==0)
369                factor=1
370        else
371                factor = 0.6            //fudge factor to get command window on-screen on Windows
372        endif
373        rect = StringByKey("SCREEN1", str  ,":",";")   
374        sscanf rect,"DEPTH=%d,RECT=%d,%d,%d,%d",depth, left,top,right,bottom
375        MoveWindow/C  (left+3)*factor,(bottom-150)*factor,(right-50)*factor,(bottom-10)*factor
376End
377
378// since the NCNR procedures can't be loaded concurrently with the other facility functions,
379// unload this procedure file, and add this to the functions that run at initialization of the
380// experiment
381//
382// TODO - be sure that this unloads correctly
383Function UnloadNCNR_VSANS_Procedures()
384
385#if (exists("NCNR_VSANS")==6)                   //defined in the main #includes file.
386        //do nothing if an NCNR reduction experiment
387#else
388        if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128")))
389                Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\""
390                Execute/P "COMPILEPROCEDURES "
391        endif
392#endif
393
394End
395
396//returns 1 if demo version, 0 if full version
397Function V_IsDemo()
398
399        // create small offscreen graph
400        Display/W=(3000,3000,3010,3010)
401        DoWindow/C IsDemoGraph
402
403        // try to save a PICT or bitmap of it to the clipboard
404        SavePICT/Z  as "Clipboard"
405        Variable isDemo= V_Flag != 0    // if error: must be demo
406        DoWindow/K IsDemoGraph
407        return isDemo
408End
409
410// Clean out the RawVSANS folder before saving
411Function BeforeExperimentSaveHook(rN,fileName,path,type,creator,kind)
412        Variable rN,kind
413        String fileName,path,type,creator
414
415        // clean out, so that the file SAVE is not slow due to the large experiment size
416        // TODO -- decide if this is really necessary
417//     
418//      V_CleanOutRawVSANS()
419// present a progress window
420        V_CleanupData_w_Progress(0,1)
421        Printf "Hook cleaned out RawVSANS, experiment saved\r"
422
423
424// these KillDF are a bad idea - it wipes out all of the current work
425// whenever a save is done - which is the opposite of what you want
426// to happen when you save!
427
428//      KillDataFolder/Z root:Packages:NIST:VSANS:RAW
429//      KillDataFolder/Z root:Packages:NIST:VSANS:SAM
430//      KillDataFolder/Z root:Packages:NIST:VSANS:EMP
431//      KillDataFolder/Z root:Packages:NIST:VSANS:BGD
432//      KillDataFolder/Z root:Packages:NIST:VSANS:COR
433//      KillDataFolder/Z root:Packages:NIST:VSANS:DIV
434//      KillDataFolder/Z root:Packages:NIST:VSANS:MSK
435//      KillDataFolder/Z root:Packages:NIST:VSANS:ABS
436//      KillDataFolder/Z root:Packages:NIST:VSANS:CAL
437//      KillDataFolder/Z root:Packages:NIST:VSANS:STO
438//      KillDataFolder/Z root:Packages:NIST:VSANS:SUB
439//      KillDataFolder/Z root:Packages:NIST:VSANS:DRK
440//      KillDataFolder/Z root:Packages:NIST:VSANS:ADJ
441
442// re-create anthing that was killed
443        V_initFolders()
444
445End
Note: See TracBrowser for help on using the repository browser.