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 | bkgdfunction = 'name=%s,n=6,A0=0.,A1=0.,A2=0.,A3=0.,A4=0.,A5=0.,A6=0, StartX=%f, EndX=%f.' % (self.bkgdtype, self.startx, self.endx) |
---|
128 | print "Background function: %s" % (bkgdfunction) |
---|
129 | f = Fit( |
---|
130 | Function = bkgdfunction, |
---|
131 | InputWorkspace = self.bkgdwsname, |
---|
132 | Output = self.bkgdwsname, |
---|
133 | MaxIterations = '1000', |
---|
134 | Minimizer = 'Levenberg-MarquardtMD', |
---|
135 | CreateOutput = '1', |
---|
136 | StartX = self.startx, |
---|
137 | EndX = self.endx) |
---|
138 | print f |
---|
139 | |
---|
140 | # [Le Bail calculation] |
---|
141 | index = 0 |
---|
142 | print "Fit range: %f , %f" % (self.startx, self.endx) |
---|
143 | LeBailFit( |
---|
144 | Function = 'Calculation', |
---|
145 | InputWorkspace = self.datawsname, |
---|
146 | OutputWorkspace = self.outwsname, |
---|
147 | InputParameterWorkspace = self.inputparamwsname, |
---|
148 | OutputParameterWorkspace= "Dummy_ParameterTable", |
---|
149 | InputHKLWorkspace = self.braggtablewsname, |
---|
150 | OutputPeaksWorkspace = 'BraggPeakParameterTable2_%d'%(index), |
---|
151 | FitRegion = '%f, %f' % (self.startx, self.endx), |
---|
152 | BackgroundType = self.bkgdtype, #'Polynomial', |
---|
153 | UseInputPeakHeights = False, |
---|
154 | PeakRadius = '8', |
---|
155 | BackgroundParametersWorkspace = self.bkgdtablewsname |
---|
156 | ) |
---|
157 | |
---|
158 | return |
---|
159 | |
---|
160 | def main(argv): |
---|
161 | """ Main |
---|
162 | """ |
---|
163 | globalfilename = "/home/wzz/Projects/MantidTests/LeBailFit/Test2013B/Bank2/Calibration_Information.config" |
---|
164 | |
---|
165 | runner = ExamineProfileParameters() |
---|
166 | runner.importGlobals(globalfilename) |
---|
167 | |
---|
168 | |
---|
169 | runner.loaddata = True |
---|
170 | runner.process_bkgd = True |
---|
171 | |
---|
172 | runner.startx = 7085. |
---|
173 | runner.endx = 70500. |
---|
174 | |
---|
175 | runner.bkgdtype = "Chebyshev" |
---|
176 | #runner.bkgdtype = "Polynomial" |
---|
177 | |
---|
178 | runner.inputparamwsname = 'Bank%dInstrumentParameterTable_Raw'%(runner.bankid) |
---|
179 | runner.outwsname = runner.datawsname + "_Guessed" |
---|
180 | runner.braggtablewsname = "BraggPeakParameterTable_Raw" |
---|
181 | |
---|
182 | #if False: |
---|
183 | # runner.irffilename = "2013A_HR60b2.irf" |
---|
184 | # print "Using special input .irf file: %s. " % (runner.irffilename) |
---|
185 | |
---|
186 | runner.PyExec() |
---|
187 | |
---|
188 | return |
---|
189 | |
---|
190 | |
---|
191 | if __name__=="__main__": |
---|
192 | main(["LeBailFitScript"]) |
---|
193 | |
---|