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

Last change on this file since 1242 was 1242, checked in by srkline, 2 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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