| 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 | bkgdfunction = 'name=%s,n=6,A0=0.,A1=0.,A2=0.,A3=0.,A4=0.,A5=0.,A6=0..' % (self.bkgdtype) |
|---|
| 129 | print "Background function: %s" % (bkgdfunction) |
|---|
| 130 | f = Fit( |
|---|
| 131 | Function = bkgdfunction, |
|---|
| 132 | InputWorkspace = self.bkgdwsname, |
|---|
| 133 | Output = self.bkgdwsname, |
|---|
| 134 | MaxIterations = '1000', |
|---|
| 135 | Minimizer = 'Levenberg-MarquardtMD', |
|---|
| 136 | CreateOutput = '1', |
|---|
| 137 | StartX = self.startx, |
|---|
| 138 | EndX = self.endx) |
|---|
| 139 | print f |
|---|
| 140 | |
|---|
| 141 | # [Le Bail calculation] |
|---|
| 142 | index = 0 |
|---|
| 143 | print "Fit range: %f , %f" % (self.startx, self.endx) |
|---|
| 144 | LeBailFit( |
|---|
| 145 | Function = 'Calculation', |
|---|
| 146 | InputWorkspace = self.datawsname, |
|---|
| 147 | OutputWorkspace = self.outwsname, |
|---|
| 148 | InputParameterWorkspace = self.inputparamwsname, |
|---|
| 149 | OutputParameterWorkspace= "Dummy_ParameterTable", |
|---|
| 150 | InputHKLWorkspace = self.braggtablewsname, |
|---|
| 151 | OutputPeaksWorkspace = 'BraggPeakParameterTable2_%d'%(index), |
|---|
| 152 | FitRegion = '%f, %f' % (self.startx, self.endx), |
|---|
| 153 | BackgroundType = self.bkgdtype, #'Polynomial', |
|---|
| 154 | UseInputPeakHeights = False, |
|---|
| 155 | PeakRadius = '8', |
|---|
| 156 | BackgroundParametersWorkspace = self.bkgdtablewsname |
|---|
| 157 | ) |
|---|
| 158 | |
|---|
| 159 | return |
|---|
| 160 | |
|---|
| 161 | def main(argv): |
|---|
| 162 | """ Main |
|---|
| 163 | """ |
|---|
| 164 | globalfilename = "/home/wzz/Projects/MantidTests/LeBailFit/Test2013B/Bank2/Calibration_Information.config" |
|---|
| 165 | |
|---|
| 166 | runner = ExamineProfileParameters() |
|---|
| 167 | runner.importGlobals(globalfilename) |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | runner.loaddata = True |
|---|
| 171 | runner.process_bkgd = True |
|---|
| 172 | |
|---|
| 173 | runner.startx = 7085. |
|---|
| 174 | runner.endx = 70500. |
|---|
| 175 | |
|---|
| 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 | |
|---|