Newer
Older
########################################################################
#
# This is the system test for workflow algorithms
# 1. ExaminePowder...
# 2. SeqRefinement...
# Both of which are based on LeBailFit to do peak profile calibration
# for powder diffractometers.
#
########################################################################
import stresstesting
import mantid.simpleapi as api
from mantid.simpleapi import *
def getSaveDir():
"""determine where to save - the current working directory"""
import os
return os.path.abspath(os.path.curdir)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class VulcanExamineProfile(stresstesting.MantidStressTest):
irf_file = 'arg_powder.irf'
dat_file = 'arg_si.dat'
bkgd_file = 'arg_si_bkgd_polynomial.nxs'
def requiredFiles(self):
files = [self.irf_file, self.dat_file, self.bkgd_file]
return files
def runTest(self):
savedir = getSaveDir()
LoadAscii(Filename=self.dat_file, OutputWorkspace='arg_si',Unit='TOF')
LoadNexusProcessed(Filename=self.bkgd_file, OutputWorkspace='Arg_Si_Bkgd_Parameter')
CreateLeBailFitInput(FullprofParameterFile=self.irf_file,
GenerateBraggReflections='1',LatticeConstant='5.4313640',
InstrumentParameterWorkspace='Arg_Bank1', BraggPeakParameterWorkspace='ReflectionTable')
# run the actual code
ExaminePowderDiffProfile(
InputWorkspace = 'arg_si',
StartX = 1990.,
EndX = 29100.,
ProfileType = 'Back-to-back exponential convoluted with PseudoVoigt',
ProfileWorkspace = 'Arg_Bank1',
BraggPeakWorkspace = 'ReflectionTable',
BackgroundParameterWorkspace = 'Arg_Si_Bkgd_Parameter',
BackgroundType = 'Polynomial',
BackgroundWorkspace = 'Arg_Si_Background',
OutputWorkspace = 'Arg_Si_Calculated')
# load output gsas file and the golden one
Load(Filename = "Arg_Si_ref.nxs", OutputWorkspace = "Arg_Si_golden")
def validateMethod(self):
self.tolerance=1.0e-6
return "ValidateWorkspaceToWorkspace"
def validate(self):
self.tolerance=1.0e-6
return ('Arg_Si_Calculated','Arg_Si_golden')
class VulcanSeqRefineProfileFromScratch(stresstesting.MantidStressTest):
"""
irf_file = 'VULCAN_SNS_1.irf'
dat_file = 'VULCAN_22946_NOM.dat'
def requiredFiles(self):
files = [self.irf_file, self.dat_file]
return files
def runTest(self):
savedir = getSaveDir()
# Data
LoadAscii(Filename=self.dat_file, OutputWorkspace='VULCAN_22946_NOM',Unit='TOF')
# Reflections and starting profile parameters
CreateLeBailFitInput(FullprofParameterFile=self.irf_file,
GenerateBraggReflections='1',LatticeConstant='5.431364000',
InstrumentParameterWorkspace='Vulcan_B270_Profile',
BraggPeakParameterWorkspace='GeneralReflectionTable')
# Pre-refined background
paramnames = ["Bkpos", "A0", "A1", "A2", "A3", "A4", "A5"]
paramvalues = [11000.000, 0.034, 0.027, -0.129, 0.161, -0.083, .015]
bkgdtablewsname = "VULCAN_22946_Bkgd_Parameter"
api.CreateEmptyTableWorkspace(OutputWorkspace=bkgdtablewsname)
ws = mtd[bkgdtablewsname]
ws.addColumn("str", "Name")
ws.addColumn("double", "Value")
for i in xrange(len(paramnames)):
ws.addRow([paramnames[i], paramvalues[i]])
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
# Examine profile
ExaminePowderDiffProfile(
InputWorkspace = "VULCAN_22946_NOM",
LoadData = False,
StartX = 7000.,
EndX = 33000.,
ProfileType = "Back-to-back exponential convoluted with PseudoVoigt",
ProfileWorkspace = "Vulcan_B270_Profile",
BraggPeakWorkspace = "GeneralReflectionTable",
GenerateInformationWS = False,
BackgroundParameterWorkspace = "VULCAN_22946_Bkgd_Parameter",
ProcessBackground = False,
BackgroundType = "FullprofPolynomial",
BackgroundWorkspace = "Dummy",
OutputWorkspace = "VULCAN_22946_Calculated")
# Set up sequential refinement
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "",
InputProfileWorkspace = "Vulcan_B270_Profile",
InputBraggPeaksWorkspace = "GeneralReflectionTable",
InputBackgroundParameterWorkspace = "VULCAN_22946_Bkgd_Parameter",
StartX = 7000.,
EndX = 33000.,
FunctionOption = "Setup", # or "Refine"
RefinementOption = "Random Walk",
ParametersToRefine = "Alph0",
NumRefineCycles = 1000,
ProfileType = "Neutron Back-to-back exponential convoluted with pseudo-voigt",
BackgroundType = "FullprofPolynomial",
ProjectID = "IDx890")
# Refine step 1
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "RecordIDx890Table",
InputProfileWorkspace = "Vulcan_B270_Profile",
InputBraggPeaksWorkspace = "GeneralReflectionTable",
InputBackgroundParameterWorkspace = "VULCAN_22946_Bkgd_Parameter",
StartX = 7000.,
EndX = 33000.,
FunctionOption = "Refine", # or "Refine"
RefinementOption = "Random Walk",
ParametersToRefine = "Alph0",
NumRefineCycles = 1000,
ProfileType = "Neutron Back-to-back exponential convoluted with pseudo-voigt",
BackgroundType = "FullprofPolynomial",
ProjectID = "IDx890")
# Refine step 2
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "RecordIDx890Table",
# InputProfileWorkspace = "Vulcan_B270_Profile",
# InputBraggPeaksWorkspace = "GeneralReflectionTable",
# InputBackgroundParameterWorkspace = "VULCAN_22946_Bkgd_Parameter",
StartX = 7000.,
EndX = 33000.,
FunctionOption = "Refine", # or "Refine"
RefinementOption = "Random Walk",
ParametersToRefine = "Beta0, Beta1",
NumRefineCycles = 100,
# ProfileType = "Neutron Back-to-back exponential convoluted with psuedo-voigt",
# BackgroundType = "FullprofPolynomial"
ProjectID = "IDx890")
# Refine step 3 (not from previous cycle)
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "RecordIDx890Table",
StartX = 7000.,
EndX = 33000.,
FunctionOption = "Refine", # or "Refine"
RefinementOption = "Random Walk",
ParametersToRefine = "Beta0, Beta1",
NumRefineCycles = 100,
FromStep = 1,
ProjectID = "IDx890")
# Save
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "RecordIDx890Table",
OutputProjectFilename = "temp991.nxs",
ProjectID = "IDx890")
return
def validateMethod(self):
""" Return None as running is all that we want at this moment.
"""
return None
def validate(self):
self.tolerance=1.0e-6
return ('VULCAN_22946_Calculated', 'VULCAN_22946_Calculated')
class VulcanSeqRefineProfileLoadPlus(stresstesting.MantidStressTest):
""" System test for sequential refinement
"""
seqfile = "VULCAN_Calibrate_Seq.nxs"
def requiredFiles(self):
files = [self.seqfile]
return files
def runTest(self):
savedir = getSaveDir()
# Load
api.RefinePowderDiffProfileSeq(
InputProjectFilename = self.seqfile,
ProjectID = "IDx890")
# Refine step 4
api.RefinePowderDiffProfileSeq(
InputWorkspace = "VULCAN_22946_NOM",
SeqControlInfoWorkspace = "RecordIDx890Table",
startx = 7000.,
EndX = 33000.,
FunctionOption = "Refine", # or "Refine"
RefinementOption = "Random Walk",
ParametersToRefine = "Alph1",
NumRefineCycles = 200,
ProjectID = "IDx890")
def validateMethod(self):
""" Return None as running is all that we want at this moment.
"""
return None
def validate(self):
self.tolerance=1.0e-6
return ('VULCAN_22946_Calculated', 'VULCAN_22946_Calculated')