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

Last change on this file since 1037 was 1023, checked in by srkline, 6 years ago

many additions.

Moved unused igor/nexus testing files to Vx_ prefix since they're garbage. Pulled out the useful bits for mask and div R/W and moved those to theire appropriate procedures.

Testing the simple correction of data, only tested basic subtraction. All of it still needs to be verified since I don't have any real header numbers and units yet.

Adjusted the columns on the file catalog to be more appropriate, and added a hook to allow loading of raw data files directly from the table and a popup contextual menu. May add more functionality to it later.

Corrected how the 1D data is plotted so that it correctly uses the binning type. I(q) save now also uses the binning as specified.

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