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

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

LOTS of changes to accommodate the beam center being reported in cm rather than pixels. Required a lot of changes to VCALC (to fill in simulated data), and in the reading and interpreting of data for display, and most importantly, the calculation of q.

There may still be a few residual bugs with this. I am still re-testing with new sample data sets.

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