1 | #################################################################################################### |
---|
2 | # |
---|
3 | # This script is migrated from Calibration_Step3.py. |
---|
4 | # The plan is to convert it to a Mantid algorithm later. |
---|
5 | # |
---|
6 | ###################################################################### |
---|
7 | #-------------- Definition of Global Variables --------------------- |
---|
8 | bankid = 0 |
---|
9 | |
---|
10 | datafilename = "" |
---|
11 | hklfilename = "" |
---|
12 | irffilename = "" |
---|
13 | |
---|
14 | # montecarlofilename = "" |
---|
15 | # expirffilename = "" |
---|
16 | |
---|
17 | datawsname = "" |
---|
18 | instrparamwsname = "" |
---|
19 | |
---|
20 | # outdataws1name = "" |
---|
21 | |
---|
22 | minpeakheight = 0.001 |
---|
23 | |
---|
24 | # Range for Le Bail Fit of all peaks |
---|
25 | startx = -1 |
---|
26 | endx = -1 |
---|
27 | # Range for fitting single peaks for step 1~3 |
---|
28 | tofmin_singlepeaks = -1 |
---|
29 | tofmax_singlepeaks = -1 |
---|
30 | |
---|
31 | backgroundtype = "Polynomial" |
---|
32 | backgroundorder = 6 |
---|
33 | bkgdtablewsname = "" |
---|
34 | bkgdwsname = "" |
---|
35 | bkgdfilename = "" |
---|
36 | usrbkgdpoints = '' |
---|
37 | |
---|
38 | latticesize = 4.1568899999999998 |
---|
39 | |
---|
40 | class ExamineProfileParameters: |
---|
41 | """ Class to do it |
---|
42 | """ |
---|
43 | def __init__(self): |
---|
44 | """ Initialization |
---|
45 | """ |
---|
46 | |
---|
47 | return |
---|
48 | |
---|
49 | def importGlobals(self, infofilename): |
---|
50 | """ Import global (all scripts) variables |
---|
51 | """ |
---|
52 | self.bankid = 2 |
---|
53 | |
---|
54 | # Material |
---|
55 | self.latticesize = 4.1568899999999998 |
---|
56 | |
---|
57 | # Input files |
---|
58 | self.datafilename = "PG3_11486-2.dat" |
---|
59 | self.hklfilename = "LB4853b2.hkl" |
---|
60 | self.irffilename = "2011B_HR60b2.irf" |
---|
61 | |
---|
62 | self.datawsname = "PG3_11486" |
---|
63 | |
---|
64 | self.backgroundtype = "Polynomial" |
---|
65 | self.usrbkgdpoints = "5243,8910,11165,12153,13731,15060,16511,17767,19650,21874,23167,24519,36000,44282,49000, 60000., 71240" |
---|
66 | self.bkgdtablewsname = "PG3_11486_Background_Parameters" |
---|
67 | |
---|
68 | # self.inputparamwsname = str('Bank%dInstrumentParameterTable1_Step2'%(self.bankid)) |
---|
69 | # self.braggtablewsname = str("BraggPeakParameterTable1") |
---|
70 | |
---|
71 | # Output properties |
---|
72 | self.bkgdwsname = "PG3_11486_Background" |
---|
73 | self.outwsname = "PG3_11486_Calculated" |
---|
74 | |
---|
75 | # Data range |
---|
76 | #self.startx = float(calibDict[self.bankid]["LeBailFitMinTOF"]) |
---|
77 | #self.endx = float(calibDict[self.bankid]["LeBailFitMaxTOF"]) |
---|
78 | |
---|
79 | return |
---|
80 | |
---|
81 | def _processInputs(self): |
---|
82 | """ Process properties |
---|
83 | """ |
---|
84 | # Input |
---|
85 | |
---|
86 | |
---|
87 | return |
---|
88 | |
---|
89 | def PyExec(self): |
---|
90 | """ Main execution body |
---|
91 | """ |
---|
92 | # Process input |
---|
93 | self._processInputs() |
---|
94 | |
---|
95 | if self.loaddata is True: |
---|
96 | # Load data file |
---|
97 | LoadAscii( |
---|
98 | Filename = self.datafilename, |
---|
99 | OutputWorkspace = self.datawsname, |
---|
100 | Unit = 'TOF' |
---|
101 | ) |
---|
102 | |
---|
103 | # Load .irf file and .hkl file |
---|
104 | CreateLeBailFitInput( |
---|
105 | FullprofParameterFile = self.irffilename, |
---|
106 | ReflectionsFile = self.hklfilename, |
---|
107 | LatticeConstant = float(self.latticesize), |
---|
108 | Bank = self.bankid, |
---|
109 | InstrumentParameterWorkspace = self.inputparamwsname, |
---|
110 | BraggPeakParameterWorkspace = self.braggtablewsname, |
---|
111 | ) |
---|
112 | |
---|
113 | if self.process_bkgd is True: |
---|
114 | # [Background] |
---|
115 | # Remove peaks and get pure background (hopefully) |
---|
116 | ProcessBackground( |
---|
117 | Options = 'SelectBackgroundPoints', |
---|
118 | InputWorkspace = self.datawsname, |
---|
119 | OutputWorkspace = self.bkgdwsname, |
---|
120 | LowerBound = self.startx, |
---|
121 | UpperBound = self.endx, |
---|
122 | BackgroundType = self.backgroundtype, |
---|
123 | BackgroundPoints= self.usrbkgdpoints, |
---|
124 | NoiseTolerance = '0.10000000000000001') |
---|
125 | |
---|
126 | # Fit background points |
---|
127 | functionstr = "name=%s,n=%d" % (backgroundtype, backgroundorder) |
---|
128 | for iborder in xrange(backgroundorder+1): |
---|
129 | functionstr = "%s,A%d=%.5f" % (functionstr, iborder, 0.0) |
---|
130 | print "Background function (:)): %s" % (functionstr) |
---|
131 | nwusestr = 'name=Polynomial,n=6,A0=0.657699,A1=3.68433e-05,A2=-1.29638e-08,A3=1.16778e-12,A4=-4.71439e-17,A5=8.8499e-22,A6=-6.26573e-27' |
---|
132 | print "Background function (:(): %s" % (nwusestr) |
---|
133 | Fit( |
---|
134 | Function = nwusestr, |
---|
135 | InputWorkspace = self.bkgdwsname, |
---|
136 | Output = self.bkgdwsname, |
---|
137 | MaxIterations = '1000', |
---|
138 | Minimizer = 'Levenberg-MarquardtMD', |
---|
139 | CreateOutput = '1', |
---|
140 | StartX = self.startx, |
---|
141 | EndX = self.endx) |
---|
142 | |
---|
143 | # [Le Bail calculation] |
---|
144 | index = 0 |
---|
145 | print "Fit range: %f , %f" % (self.startx, self.endx) |
---|
146 | LeBailFit( |
---|
147 | Function = 'Calculation', |
---|
148 | InputWorkspace = self.datawsname, |
---|
149 | OutputWorkspace = self.outwsname, |
---|
150 | InputParameterWorkspace = self.inputparamwsname, |
---|
151 | OutputParameterWorkspace= "Dummy_ParameterTable", |
---|
152 | InputHKLWorkspace = self.braggtablewsname, |
---|
153 | OutputPeaksWorkspace = 'BraggPeakParameterTable2_%d'%(index), |
---|
154 | FitRegion = '%f, %f' % (self.startx, self.endx), |
---|
155 | BackgroundType = 'Chebyshev', #'Polynomial', |
---|
156 | UseInputPeakHeights = False, |
---|
157 | PeakRadius = '8', |
---|
158 | BackgroundParametersWorkspace = self.bkgdtablewsname |
---|
159 | ) |
---|
160 | |
---|
161 | return |
---|
162 | |
---|
163 | def main(argv): |
---|
164 | """ Main |
---|
165 | """ |
---|
166 | globalfilename = "/home/wzz/Projects/MantidTests/LeBailFit/Test2013B/Bank2/Calibration_Information.config" |
---|
167 | |
---|
168 | runner = ExamineProfileParameters() |
---|
169 | runner.importGlobals(globalfilename) |
---|
170 | |
---|
171 | step = 1 |
---|
172 | if step == 1: |
---|
173 | |
---|
174 | runner.loaddata = True |
---|
175 | runner.process_bkgd = True |
---|
176 | |
---|
177 | runner.startx = 7085. |
---|
178 | runner.endx = 18000. |
---|
179 | |
---|
180 | runner.inputparamwsname = 'Bank%dInstrumentParameterTable_Raw'%(runner.bankid) |
---|
181 | runner.outwsname = runner.datawsname + "_Guessed" |
---|
182 | runner.braggtablewsname = "BraggPeakParameterTable_Raw" |
---|
183 | |
---|
184 | #if False: |
---|
185 | # runner.irffilename = "2013A_HR60b2.irf" |
---|
186 | # print "Using special input .irf file: %s. " % (runner.irffilename) |
---|
187 | |
---|
188 | runner.PyExec() |
---|
189 | |
---|
190 | return |
---|
191 | |
---|
192 | |
---|
193 | if __name__=="__main__": |
---|
194 | main(["LeBailFitScript"]) |
---|
195 | |
---|