1 | |
---|
2 | from mantid.simpleapi import * |
---|
3 | import math |
---|
4 | |
---|
5 | def mergeWS(prepath, wsList,output): |
---|
6 | for ix in wsList: |
---|
7 | name='RUN'+str(ix).zfill(7) |
---|
8 | LoadNexus(Filename=prepath+'\\'+name+'\\'+output+'.nxs',OutputWorkspace=str(ix)) |
---|
9 | for i in range(len(wsList)): |
---|
10 | if len(wsList)== 1: |
---|
11 | CloneWorkspace(InputWorkspace=str(wsList[i]), OutputWorkspace=output) |
---|
12 | DeleteWorkspace(Workspace=str(wsList[i])) |
---|
13 | elif wsList[i+1]!=wsList[-1]: |
---|
14 | Plus(LHSWorkspace=str(wsList[i]),RHSWorkspace=str(wsList[i+1]), OutputWorkspace=str(wsList[i+1])) |
---|
15 | DeleteWorkspace(Workspace=str(wsList[i])) |
---|
16 | else: |
---|
17 | Plus(LHSWorkspace=str(wsList[i]),RHSWorkspace=str(wsList[i+1]), OutputWorkspace=output) |
---|
18 | DeleteWorkspace(Workspace=str(wsList[i])) |
---|
19 | DeleteWorkspace(Workspace=str(wsList[i+1])) |
---|
20 | break |
---|
21 | |
---|
22 | |
---|
23 | def getMask(xPids, yPids): |
---|
24 | index=[] |
---|
25 | xnum=xPids[1]-xPids[0]+1 |
---|
26 | ynum=yPids[1]-yPids[0]+1 |
---|
27 | sta=yPids[0]*125+xPids[0] |
---|
28 | for i in range(xnum): |
---|
29 | for j in range(ynum): |
---|
30 | index.append(sta+j*125+i) |
---|
31 | print index |
---|
32 | return index |
---|
33 | |
---|
34 | |
---|
35 | def findCmaskWS(wsname): |
---|
36 | x=0.0009 |
---|
37 | y=-0.00229 |
---|
38 | MoveInstrumentComponent(Workspace=wsname, ComponentName='Bank01', X=x, Y=y, RelativePosition=False) |
---|
39 | index=getMask([0,18],[0,119]) |
---|
40 | MaskDetectors(Workspace=wsname, WorkspaceIndexList=index) |
---|
41 | index=getMask([105,124],[0,119]) |
---|
42 | MaskDetectors(Workspace=wsname, WorkspaceIndexList=index) |
---|
43 | inner=0.048 |
---|
44 | xml_inner='<infinite-cylinder id="beam_stop"><centre x="0" y="0" z="0.0" /><axis x="0" y="0" z="1" /><radius val= "'+str(inner)+'" /></infinite-cylinder><algebra val="beam_stop"/>' |
---|
45 | MaskDetectorsInShape(Workspace=wsname, ShapeXML=xml_inner) |
---|
46 | |
---|
47 | index=getMask([60,63],[0,57]) |
---|
48 | MaskDetectors(Workspace=wsname, WorkspaceIndexList=index) |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | empty_run=[960,961] |
---|
54 | |
---|
55 | monSUM=True |
---|
56 | prepath=r'C:\Users\admin\Documents\python\CSNSSANS' |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | mergeWS(prepath, empty_run, 'sample') |
---|
61 | CloneWorkspace(InputWorkspace='sample',OutputWorkspace='empty_tmp') |
---|
62 | |
---|
63 | LoadInstrument(Workspace='empty_tmp', Filename=prepath+'/paramData/detector_mod.xml', RewriteSpectraMap=True) |
---|
64 | |
---|
65 | findCmaskWS('empty_tmp') |
---|
66 | ConvertUnits(InputWorkspace='empty_tmp', OutputWorkspace='empty_tmp0', Target='Wavelength', AlignBins=True) |
---|
67 | |
---|
68 | |
---|
69 | wave_rebin='2,0.02,7.9' |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | LoadAscii(Filename=prepath+'/paramData/cal_bp_1M.dat', OutputWorkspace='cali', Separator='Automatic', Unit='Wavelength') |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | ConvertToHistogram(InputWorkspace='cali', OutputWorkspace='cali') |
---|
79 | Rebin(InputWorkspace='cali', OutputWorkspace='cali', Params=wave_rebin) |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | ''' |
---|
86 | mergeWS(prepath, empty_run, 'sample') |
---|
87 | CloneWorkspace(InputWorkspace='sample',OutputWorkspace='empty_tmp') |
---|
88 | LoadInstrument(Workspace='empty_tmp', Filename=prepath+'/paramData/detector_mod.xml', RewriteSpectraMap=True) |
---|
89 | #CloneWorkspace(InputWorkspace='bg',OutputWorkspace='empty_tmp') |
---|
90 | findCmaskWS('empty_tmp') |
---|
91 | ConvertUnits(InputWorkspace='empty_tmp', OutputWorkspace='empty_tmp', Target='Wavelength', AlignBins=True) |
---|
92 | |
---|
93 | ''' |
---|
94 | Rebin(InputWorkspace='empty_tmp0',OutputWorkspace='empty_tmp',Params=wave_rebin) |
---|
95 | |
---|
96 | mergeWS(prepath, empty_run,'monitor2') |
---|
97 | RenameWorkspace(InputWorkspace='monitor2',OutputWorkspace='mon_empty') |
---|
98 | |
---|
99 | ConvertUnits(InputWorkspace='mon_empty', OutputWorkspace='empty_m2', Target='Wavelength', AlignBins=True) |
---|
100 | Rebin(InputWorkspace='empty_m2',OutputWorkspace='empty_m2',Params=wave_rebin) |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | if monSUM: |
---|
106 | name=mtd['empty_m2'] |
---|
107 | counts=sum(name.readY(0))*1.0 |
---|
108 | CreateSingleValuedWorkspace(OutputWorkspace='m2',DataValue=counts) |
---|
109 | Divide(LHSWorkspace='empty_tmp', RHSWorkspace='m2', OutputWorkspace='empty_tmp', AllowDifferentNumberSpectra=True) |
---|
110 | else: |
---|
111 | Divide(LHSWorkspace='empty_tmp', RHSWorkspace='empty_m2', OutputWorkspace='empty_tmp', AllowDifferentNumberSpectra=True) |
---|
112 | |
---|
113 | Divide(LHSWorkspace='empty_tmp', RHSWorkspace='cali', OutputWorkspace='empty_tmp', AllowDifferentNumberSpectra=True) |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | q_rebin='0.01,-0.08,0.4' |
---|
118 | |
---|
119 | |
---|
120 | Q1D(DetBankWorkspace='empty_tmp', OutputWorkspace='IQ_air', OutputBinning=q_rebin, AccountForGravity=False, SolidAngleWeighting=True) |
---|
121 | ReplaceSpecialValues(InputWorkspace='IQ_air', OutputWorkspace='IQ_air', NaNValue=0, InfinityValue=0) |
---|
122 | |
---|
123 | |
---|
124 | dlamda=0.5 |
---|
125 | CreateSingleValuedWorkspace(OutputWorkspace='dlamda_sample', DataValue=dlamda) |
---|
126 | Multiply(LHSWorkspace='IQ_air', RHSWorkspace='dlamda_sample', OutputWorkspace='IQ_air', AllowDifferentNumberSpectra=True) |
---|
127 | |
---|
128 | |
---|
129 | trans_run=[1118] |
---|
130 | mergeWS(prepath, trans_run,'monitors') |
---|
131 | RenameWorkspace(InputWorkspace='monitors',OutputWorkspace='monTran') |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | LoadInstrument(Workspace='monTran', Filename=prepath+'/paramData/monitors.xml', RewriteSpectraMap=True) |
---|
137 | ConvertUnits(InputWorkspace='monTran', OutputWorkspace='monTran', Target='Wavelength', AlignBins=True) |
---|
138 | |
---|
139 | |
---|
140 | Rebin(InputWorkspace='monTran', OutputWorkspace="monTran", Params=wave_rebin) |
---|
141 | |
---|
142 | name=mtd['monTran'] |
---|
143 | monTranM2=(name.readY(0))*1.0 |
---|
144 | monTranM3=(name.readY(1))*1.0 |
---|
145 | monTranMWavelength=(name.readX(0))*1.0 |
---|
146 | |
---|
147 | CreateWorkspace(OutputWorkspace='monTranM3',DataX=monTranMWavelength,DataY=monTranM3) |
---|
148 | CreateWorkspace(OutputWorkspace='monTranM2',DataX=monTranMWavelength,DataY=monTranM2) |
---|
149 | |
---|
150 | Divide(LHSWorkspace='monTranM3', RHSWorkspace='monTranM2',OutputWorkspace='monTranM3toM2'+str(trans_run), AllowDifferentNumberSpectra=True) |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | ', OutputWorkspace='empty_tmp', AllowDifferentNumberSpectra=True) |
---|
191 | |
---|
192 | |
---|
193 | |
---|