Ticket #10973: boxSplit4D.py

File boxSplit4D.py, 5.9 KB (added by Anton Piccardo-Selg, 6 years ago)
Line 
1import os
2
3#----------------------------- WITHOUT INITIAL SPLITTING (woIS)-----------------------------------------------------------
4# set up target ws name and remove target workspace with the same name which can occasionally exist.
5# list of MD files (workspaces) to combine into target MD workspace
6MD_FilesList_woIS='';
7
8# define convetr to MD parameters
9pars_woIS = dict();
10pars_woIS['InputWorkspace']=''
11pars_woIS['QDimensions']='Q3D'
12pars_woIS['dEAnalysisMode']='Direct'
13pars_woIS['Q3DFrames']='HKL'
14pars_woIS['QConversionScales']='HKL'
15pars_woIS['PreprocDetectorsWS']='preprDetMantid'
16pars_woIS['MinValues']='-3,-3,-3.,-50.0'
17pars_woIS['MaxValues']='3.,3.,3.,50.0'
18pars_woIS['SplitInto']=5
19pars_woIS['MaxRecursionDepth']=1
20pars_woIS['MinRecursionDepth']=1
21pars_woIS['OverwriteExisting']=1  # Change this to false, if the files should/can be added in memory
22# test script combines all contributed files in memory
23pars_woIS['OverwriteExisting']=0  # Change this to false, if the files should/can be added in memory
24pars_woIS['InitialSplitting']=0
25#
26#---> Start loop over contributing files
27for n in xrange(0,5,1):
28     source_file_woIS = 'MER19566_22.0meV_one2one125.nxspe'; # redefine source files list as function of loop number
29     target_woIS  = 'MDMAP_T1_woIS'+str(n)+'.nxs';
30     # check if the file already been converted to MD and is there
31     if not(os.path.exists(target_woIS)):
32         print 'Converting ',source_file_woIS
33         #current_ws=LoadNXSPE(Filename=source)
34         #### For the sample script, simulate load operation above
35         current_ws_woIS = CreateSimulationWorkspace(Instrument='MAR',BinParams=[-3,1,3],UnitX='DeltaE',OutputWorkspace=source_file_woIS)
36         AddSampleLog(Workspace=current_ws_woIS,LogName='Ei',LogText='3.0',LogType='Number')
37
38         #### Add iformation which is not stored in the nxspe file
39         # Add UB matrix (lattice and the beam direction)
40         SetUB(Workspace=current_ws_woIS,a='1.4165',b='1.4165',c='1.4165',u='1,0,0',v='0,1,0')
41         # Add crystal rotation (assume rotation abgle Psi=5*n where n is file number. Define list of angles if this is not correct
42         AddSampleLog(Workspace=current_ws_woIS,LogName='Psi',LogText=str(5*n)+'.',LogType='Number')  # --correct Psi value may be already in nxspe file. This operation is then unnecessary
43         # set crystal rotation
44         SetGoniometer(Workspace=current_ws_woIS,Axis0='Psi,0,1,0,1')
45
46         # Convert to MD
47         pars_woIS['InputWorkspace']=current_ws_woIS;
48         md_ws_woIS=ConvertToMD(**pars_woIS)
49
50         # save MD for further usage -- disabled in test script
51         #SaveMD(md_ws,Filename=target);
52         #DeleteWorkspace(md_ws);  # delete intermediate workspace to save memory
53         DeleteWorkspace(current_ws_woIS);
54
55     # add the file name of the file to combine
56     if (len(MD_FilesList_woIS) == 0):
57         MD_FilesList_woIS = target_woIS;
58     else:
59         MD_FilesList_woIS=MD_FilesList_woIS+','+target_woIS;
60
61
62
63#----------------------------- WITH INITIAL SPLITTING (wIS)-----------------------------------------------------------
64# set up target ws name and remove target workspace with the same name which can occasionally exist.
65# list of MD files (workspaces) to combine into target MD workspace
66MD_FilesList_wIS='';
67
68# define convetr to MD parameters
69pars_wIS = dict();
70pars_wIS['InputWorkspace']=''
71pars_wIS['QDimensions']='Q3D'
72pars_wIS['dEAnalysisMode']='Direct'
73pars_wIS['Q3DFrames']='HKL'
74pars_wIS['QConversionScales']='HKL'
75pars_wIS['PreprocDetectorsWS']='preprDetMantid'
76pars_wIS['MinValues']='-3,-3,-3.,-50.0'
77pars_wIS['MaxValues']='3.,3.,3.,50.0'
78pars_wIS['SplitInto']=5
79pars_wIS['MaxRecursionDepth']=1
80pars_wIS['MinRecursionDepth']=1
81pars_wIS['OverwriteExisting']=1  # Change this to false, if the files should/can be added in memory
82# test script combines all contributed files in memory
83pars_wIS['OverwriteExisting']=0  # Change this to false, if the files should/can be added in memory
84pars_wIS['InitialSplitting']=1
85#
86#---> Start loop over contributing files
87for n in xrange(0,5,1):
88     source_file_wIS = 'MER19566_22.0meV_one2one125.nxspe'; # redefine source files list as function of loop number
89     target_wIS  = 'MDMAP_T1_wIS'+str(n)+'.nxs';
90     # check if the file already been converted to MD and is there
91     if not(os.path.exists(target_wIS)):
92         print 'Converting ',source_file_wIS
93         #current_ws=LoadNXSPE(Filename=source)
94         #### For the sample script, simulate load operation above
95         current_ws_wIS = CreateSimulationWorkspace(Instrument='MAR',BinParams=[-3,1,3],UnitX='DeltaE',OutputWorkspace=source_file_wIS)
96         AddSampleLog(Workspace=current_ws_wIS,LogName='Ei',LogText='3.0',LogType='Number')
97
98         #### Add iformation which is not stored in the nxspe file
99         # Add UB matrix (lattice and the beam direction)
100         SetUB(Workspace=current_ws_wIS,a='1.4165',b='1.4165',c='1.4165',u='1,0,0',v='0,1,0')
101         # Add crystal rotation (assume rotation abgle Psi=5*n where n is file number. Define list of angles if this is not correct
102         AddSampleLog(Workspace=current_ws_wIS,LogName='Psi',LogText=str(5*n)+'.',LogType='Number')  # --correct Psi value may be already in nxspe file. This operation is then unnecessary
103         # set crystal rotation
104         SetGoniometer(Workspace=current_ws_wIS,Axis0='Psi,0,1,0,1')
105
106         # Convert to MD
107         pars_wIS['InputWorkspace']=current_ws_wIS;
108         md_ws_wIS=ConvertToMD(**pars_wIS)
109
110         # save MD for further usage -- disabled in test script
111         #SaveMD(md_ws,Filename=target);
112         #DeleteWorkspace(md_ws);  # delete intermediate workspace to save memory
113         DeleteWorkspace(current_ws_wIS);
114
115     # add the file name of the file to combine
116     if (len(MD_FilesList_wIS) == 0):
117         MD_FilesList_wIS = target_wIS;
118     else:
119         MD_FilesList_wIS=MD_FilesList_wIS+','+target_wIS;