本文整理汇总了Python中Direct.DirectEnergyConversion.DirectEnergyConversion类的典型用法代码示例。如果您正苦于以下问题:Python DirectEnergyConversion类的具体用法?Python DirectEnergyConversion怎么用?Python DirectEnergyConversion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DirectEnergyConversion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_late_rebinning
def test_late_rebinning(self):
run_monitors=CreateSampleWorkspace(Function='Multiple Peaks', NumBanks=4, BankPixelWidth=1, NumEvents=100000, XUnit='Energy',
XMin=3, XMax=200, BinWidth=0.1)
LoadInstrument(run_monitors,InstrumentName='MARI')
ConvertUnits(InputWorkspace='run_monitors', OutputWorkspace='run_monitors', Target='TOF')
run_monitors = mtd['run_monitors']
tof = run_monitors.dataX(3)
tMin = tof[0]
tMax = tof[-1]
run = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=8, BankPixelWidth=1, NumEvents=100000,
XUnit='TOF',xMin=tMin,xMax=tMax)
LoadInstrument(run,InstrumentName='MARI')
wb_ws = Rebin(run,Params=[tMin,1,tMax],PreserveEvents=False)
# References used to test against ordinary reduction
ref_ws = Rebin(run,Params=[tMin,1,tMax],PreserveEvents=False)
ref_ws_monitors = CloneWorkspace('run_monitors')
# just in case, wb should work without clone too.
wb_clone = CloneWorkspace(wb_ws)
# Run Mono
tReducer = DirectEnergyConversion(run.getInstrument())
tReducer.energy_bins = [-20,0.2,60]
ei_guess = 67.
mono_s = tReducer.mono_sample(run, ei_guess,wb_ws)
#
mono_ref = tReducer.mono_sample(ref_ws, ei_guess,wb_clone)
rez = CheckWorkspacesMatch(mono_s,mono_ref)
self.assertEqual(rez,'Success!')
示例2: test_get_abs_normalization_factor
def test_get_abs_normalization_factor(self) :
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1,function='Flat background')
LoadInstrument(mono_ws,InstrumentName='MARI', RewriteSpectraMap=True)
tReducer = DirectEnergyConversion(mono_ws.getInstrument())
tReducer.prop_man.incident_energy = 5.
tReducer.prop_man.monovan_integr_range=[-10,10]
tReducer.wb_run = mono_ws
(nf1,nf2,nf3,nf4) = tReducer.get_abs_normalization_factor(PropertyManager.wb_run,5.)
self.assertAlmostEqual(nf1,0.58561121802167193,7)
self.assertAlmostEqual(nf1,nf2)
self.assertAlmostEqual(nf2,nf3)
self.assertAlmostEqual(nf3,nf4)
# check warning. WB spectra with 0 signal indicate troubles.
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1,function='Flat background')
LoadInstrument(mono_ws,InstrumentName='MARI', RewriteSpectraMap=True)
sig = mono_ws.dataY(0)
sig[:]=0
tReducer.wb_run = mono_ws
(nf1,nf2,nf3,nf4) = tReducer.get_abs_normalization_factor(PropertyManager.wb_run,5.)
self.assertAlmostEqual(nf1,0.585611218022,7)
self.assertAlmostEqual(nf1,nf2)
self.assertAlmostEqual(nf2,nf3)
self.assertAlmostEqual(nf3,nf4)
示例3: test_sum_monitors
def test_sum_monitors(self):
# create test workspace
monitor_ws=CreateSampleWorkspace(Function='Multiple Peaks', NumBanks=6, BankPixelWidth=1,\
NumEvents=100000, XUnit='Energy', XMin=3, XMax=200, BinWidth=0.1)
ConvertUnits(InputWorkspace=monitor_ws, OutputWorkspace='monitor_ws', Target='TOF')
# Rebin to "formally" make common bin boundaries as it is not considered as such
#any more after converting units (Is this a bug?)
xx = monitor_ws.readX(0)
x_min = min(xx[0],xx[-1])
x_max= max(xx[0],xx[-1])
x_step = (x_max-x_min)/(len(xx)-1)
monitor_ws = Rebin(monitor_ws,Params=[x_min,x_step,x_max])
monitor_ws = mtd['monitor_ws']
#
# keep this workspace for second test below -- clone and give
# special name for RunDescriptor to recognize as monitor workspace for
# fake data workspace we will provide.
_TMPmonitor_ws_monitors = CloneWorkspace(monitor_ws)
# Estimate energy from two monitors
ei,mon1_peak,mon1_index,tzero = \
GetEi(InputWorkspace=monitor_ws, Monitor1Spec=1,Monitor2Spec=4,
EnergyEstimate=62.2,FixEi=False)
self.assertAlmostEqual(ei,62.1449,3)
# Provide instrument parameter, necessary to define
# DirectEnergyConversion class properly
SetInstrumentParameter(monitor_ws,ParameterName='fix_ei',ParameterType='Number',Value='0')
SetInstrumentParameter(monitor_ws,DetectorList=[1,2,3,6],ParameterName='DelayTime',\
ParameterType='Number',Value='0.5')
SetInstrumentParameter(monitor_ws,ParameterName='mon2_norm_spec',\
ParameterType='Number',Value='1')
# initiate test reducer
tReducer = DirectEnergyConversion(monitor_ws.getInstrument())
tReducer.prop_man.ei_mon_spectra= ([1,2,3],6)
tReducer.prop_man.normalise_method = 'current'
tReducer.prop_man.mon2_norm_spec = 2
ei_mon_spectra = tReducer.prop_man.ei_mon_spectra
ei_mon_spectra,monitor_ws = tReducer.sum_monitors_spectra(monitor_ws,ei_mon_spectra)
#
# Check GetEi with summed monitors. Try to run separately.
ei1,mon1_peak,mon1_index,tzero = \
GetEi(InputWorkspace=monitor_ws, Monitor1Spec=1,Monitor2Spec=6,
EnergyEstimate=62.2,FixEi=False)
self.assertAlmostEqual(ei1,ei,2)
# Second test Check get_ei as part of the reduction
tReducer.prop_man.ei_mon_spectra= ([1,2,3],[4,5,6])
tReducer.prop_man.fix_ei = False
# DataWorkspace == monitor_ws data workspace is not used anyway. The only thing we
# use it for is to retrieve monitor workspace from Mantid using its name
ei2,mon1_peak2=tReducer.get_ei(monitor_ws,62.2)
self.assertAlmostEqual(ei2,64.95,2)
ei2b,mon1_peak2=tReducer.get_ei(monitor_ws,62.2)
self.assertAlmostEqual(ei2b,64.95,2)
示例4: test_do_white_wb
def test_do_white_wb(self) :
wb_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000)
#LoadParameterFile(Workspace=wb_ws,ParameterXML = used_parameters)
LoadInstrument(wb_ws,InstrumentName='MARI', RewriteSpectraMap=True)
tReducer = DirectEnergyConversion(wb_ws.getInstrument())
white_ws = tReducer.do_white(wb_ws, None, None)
self.assertTrue(white_ws)
示例5: test_diagnostics_wb
def test_diagnostics_wb(self):
wb_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000)
LoadInstrument(wb_ws, InstrumentName="MARI", RewriteSpectraMap=True)
tReducer = DirectEnergyConversion(wb_ws.getInstrument())
mask_workspace = tReducer.diagnose(wb_ws)
self.assertTrue(mask_workspace)
api.AnalysisDataService.clear()
示例6: test_tof_range
def test_tof_range(self):
run = CreateSampleWorkspace(
Function="Multiple Peaks",
NumBanks=6,
BankPixelWidth=1,
NumEvents=10,
XUnit="Energy",
XMin=5,
XMax=75,
BinWidth=0.2,
)
LoadInstrument(run, InstrumentName="MARI", RewriteSpectraMap=True)
red = DirectEnergyConversion(run.getInstrument())
red.prop_man.incident_energy = 26.2
red.prop_man.energy_bins = [-20, 0.1, 20]
red.prop_man.multirep_tof_specta_list = [4, 5, 6]
MoveInstrumentComponent(Workspace="run", ComponentName="Detector", DetectorID=1102, Z=3)
MoveInstrumentComponent(Workspace="run", ComponentName="Detector", DetectorID=1103, Z=6)
run_tof = ConvertUnits(run, Target="TOF", EMode="Elastic")
tof_range = red.find_tof_range_for_multirep(run_tof)
self.assertEqual(len(tof_range), 3)
x = run_tof.readX(3)
dx = abs(x[1:] - x[:-1])
xMin = min(x)
dt = min(dx)
x = run_tof.readX(5)
xMax = max(x)
self.assertTrue(tof_range[0] > xMin)
# self.assertAlmostEqual(tof_range[1],dt)
self.assertTrue(tof_range[2] < xMax)
# check another working mode
red.prop_man.multirep_tof_specta_list = 4
red.prop_man.incident_energy = 47.505
red.prop_man.energy_bins = [-20, 0.1, 45]
tof_range1 = red.find_tof_range_for_multirep(run_tof)
self.assertTrue(tof_range1[0] > xMin)
self.assertTrue(tof_range1[2] < xMax)
self.assertTrue(tof_range1[2] < tof_range[2])
self.assertTrue(tof_range1[0] < tof_range[0])
self.assertTrue(tof_range1[1] < tof_range[1])
示例7: test_late_rebinning
def test_late_rebinning(self):
run_monitors = CreateSampleWorkspace(
Function="Multiple Peaks",
NumBanks=4,
BankPixelWidth=1,
NumEvents=100000,
XUnit="Energy",
XMin=3,
XMax=200,
BinWidth=0.1,
)
LoadInstrument(run_monitors, InstrumentName="MARI", RewriteSpectraMap=True)
ConvertUnits(InputWorkspace="run_monitors", OutputWorkspace="run_monitors", Target="TOF")
run_monitors = mtd["run_monitors"]
tof = run_monitors.dataX(3)
tMin = tof[0]
tMax = tof[-1]
run = CreateSampleWorkspace(
Function="Multiple Peaks",
WorkspaceType="Event",
NumBanks=8,
BankPixelWidth=1,
NumEvents=100000,
XUnit="TOF",
xMin=tMin,
xMax=tMax,
)
LoadInstrument(run, InstrumentName="MARI", RewriteSpectraMap=True)
run.setMonitorWorkspace(run_monitors)
wb_ws = Rebin(run, Params=[tMin, 1, tMax], PreserveEvents=False)
# References used to test against ordinary reduction
ref_ws = Rebin(run, Params=[tMin, 1, tMax], PreserveEvents=False)
ref_ws_monitors = CloneWorkspace("run_monitors")
ref_ws.setMonitorWorkspace(ref_ws_monitors)
# just in case, wb should work without clone too.
wb_clone = CloneWorkspace(wb_ws)
# Run Mono
tReducer = DirectEnergyConversion(run.getInstrument())
tReducer.energy_bins = [-20, 0.2, 60]
ei_guess = 67.0
mono_s = tReducer.mono_sample(run, ei_guess, wb_ws)
#
mono_ref = tReducer.mono_sample(ref_ws, ei_guess, wb_clone)
rez = CheckWorkspacesMatch(mono_s, mono_ref)
self.assertEqual(rez, "Success!")
示例8: __init__
def __init__(self,instrumentName,web_var=None):
""" sets properties defaults for the instrument with Name
and define if wrapper runs from web services or not
"""
# internal variable, indicating if we should try to wait for input files to appear
self._wait_for_file = False
#The property defines the run number, to validate. If defined, switches reduction wrapper from
#reduction to validation mode
self._run_number_to_validate=None
# internal variable, used in system tests to validate workflow,
# with waiting for files. It is the holder to the function
# used during debugging "wait for files" workflow
# instead of Pause algorithm
self._debug_wait_for_files_operation = None
# tolerance to change in some tests if default is not working well
self._tolerr=None
# The variables which are set up from web interface or to be exported to
# web interface
if web_var:
self._run_from_web = True
else:
self._run_from_web = False
self._wvs = ReductionWrapper.var_holder(web_var)
# Initialize reduced for given instrument
self.reducer = DirectEnergyConversion(instrumentName)
#
web_vars = self._wvs.get_all_vars()
if web_vars :
self.reducer.prop_man.set_input_parameters(**web_vars)
示例9: test_multirep_mode
def test_multirep_mode(self):
# create test workspace
run_monitors=CreateSampleWorkspace(Function='Multiple Peaks', NumBanks=4, BankPixelWidth=1,\
NumEvents=100000,XUnit='Energy', XMin=3, XMax=200, BinWidth=0.1)
LoadInstrument(run_monitors,InstrumentName='MARI', RewriteSpectraMap=True)
ConvertUnits(InputWorkspace='run_monitors', OutputWorkspace='run_monitors', Target='TOF')
run_monitors = mtd['run_monitors']
tof = run_monitors.dataX(3)
tMin = tof[0]
tMax = tof[-1]
run = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=8, BankPixelWidth=1,\
NumEvents=100000, XUnit='TOF',xMin=tMin,xMax=tMax)
LoadInstrument(run,InstrumentName='MARI', RewriteSpectraMap=True)
MoveInstrumentComponent(Workspace='run', ComponentName='Detector', DetectorID=1102,Z=1)
# MoveInstrumentComponent(Workspace='run', ComponentName='Detector', DetectorID=1103,Z=4)
# MoveInstrumentComponent(Workspace='run', ComponentName='Detector', DetectorID=1104,Z=5)
# do second
run2 = CloneWorkspace(run)
run2_monitors = CloneWorkspace(run_monitors)
wb_ws = Rebin(run,Params=[tMin,1,tMax],PreserveEvents=False)
# Run multirep
tReducer = DirectEnergyConversion(run.getInstrument())
tReducer.prop_man.run_diagnostics=True
tReducer.hard_mask_file=None
tReducer.map_file=None
tReducer.save_format=None
tReducer.multirep_tof_specta_list = [4,5]
result = tReducer.convert_to_energy(wb_ws,run,[67.,122.],[-2,0.02,0.8])
self.assertEqual(len(result),2)
ws1=result[0]
self.assertEqual(ws1.getAxis(0).getUnit().unitID(),'DeltaE')
x = ws1.readX(0)
self.assertAlmostEqual(x[0],-2*67.)
self.assertAlmostEqual(x[-1],0.8*67.)
ws2=result[1]
self.assertEqual(ws2.getAxis(0).getUnit().unitID(),'DeltaE')
x = ws2.readX(0)
self.assertAlmostEqual(x[0],-2*122.)
self.assertAlmostEqual(x[-1],0.8*122.)
# test another ws
# rename samples from previous workspace to avoid deleting them on current run
for ind,item in enumerate(result):
result[ind]=RenameWorkspace(item,OutputWorkspace='SampleRez#'+str(ind))
#
result2 = tReducer.convert_to_energy(None,run2,[67.,122.],[-2,0.02,0.8])
rez = CompareWorkspaces(result[0],result2[0])
self.assertTrue(rez[0])
rez = CompareWorkspaces(result[1],result2[1])
self.assertTrue(rez[0])
示例10: test_energy_to_TOF_range
def test_energy_to_TOF_range(self):
ws = Load(Filename='MAR11001.raw',LoadMonitors='Include')
en_range = [0.8*13,13,1.2*13]
detIDs=[1,2,3,10]
red = DirectEnergyConversion()
TRange = red.get_TOF_for_energies(ws,en_range,detIDs)
for ind,detID in enumerate(detIDs):
tof = TRange[ind]
y = [1]*(len(tof)-1)
ind = ws.getIndexFromSpectrumNumber(detID)
ExtractSingleSpectrum(InputWorkspace=ws, OutputWorkspace='_ws_template', WorkspaceIndex=ind)
CreateWorkspace(OutputWorkspace='TOF_WS',NSpec = 1,DataX=tof,DataY=y,UnitX='TOF',ParentWorkspace='_ws_template')
EnWs=ConvertUnits(InputWorkspace='TOF_WS',Target='Energy',EMode='Elastic')
eni = EnWs.dataX(0)
for samp,rez in zip(eni,en_range): self.assertAlmostEqual(samp,rez)
# Now Test shifted:
ei,mon1_peak,mon1_index,tzero = GetEi(InputWorkspace=ws, Monitor1Spec=int(2), Monitor2Spec=int(3),EnergyEstimate=13)
ScaleX(InputWorkspace='ws',OutputWorkspace='ws',Operation="Add",Factor=-mon1_peak,InstrumentParameter="DelayTime",Combine=True)
ws = mtd['ws']
mon1_det = ws.getDetector(1)
mon1_pos = mon1_det.getPos()
src_name = ws.getInstrument().getSource().getName()
MoveInstrumentComponent(Workspace='ws',ComponentName= src_name, X=mon1_pos.getX(), Y=mon1_pos.getY(), Z=mon1_pos.getZ(), RelativePosition=False)
# Does not work for monitor 2 as it has been moved to mon2 position and there all tof =0
detIDs=[1,3,10]
TRange1 = red.get_TOF_for_energies(ws,en_range,detIDs)
for ind,detID in enumerate(detIDs):
tof = TRange1[ind]
y = [1]*(len(tof)-1)
ind = ws.getIndexFromSpectrumNumber(detID)
ExtractSingleSpectrum(InputWorkspace=ws, OutputWorkspace='_ws_template', WorkspaceIndex=ind)
CreateWorkspace(OutputWorkspace='TOF_WS',NSpec = 1,DataX=tof,DataY=y,UnitX='TOF',ParentWorkspace='_ws_template')
EnWs=ConvertUnits(InputWorkspace='TOF_WS',Target='Energy',EMode='Elastic')
eni = EnWs.dataX(0)
for samp,rez in zip(eni,en_range): self.assertAlmostEqual(samp,rez)
示例11: __init__
def __init__(self,instrumentName,web_var=None):
""" sets properties defaults for the instrument with Name
and define if wrapper runs from web services or not
"""
# internal variable, indicating if we should try to wait for input files to appear
self._wait_for_file=False
# The variables which are set up from web interface or to be exported to
# web interface
if web_var:
self._run_from_web = True
self._wvs = web_var
else:
self._run_from_web = False
self._wvs = ReductionWrapper.var_holder()
# Initialize reduced for given instrument
self.reducer = DirectEnergyConversion(instrumentName)
self._validation_fname=None
示例12: ReductionWrapper
class ReductionWrapper(object):
""" Abstract class provides interface to direct inelastic reduction
allowing it to be run from Mantid, web services, or system tests
using the same interface and the same run file placed in different
locations.
"""
class var_holder(object):
""" A simple wrapper class to keep web variables"""
def __init__(self,Web_vars=None):
if Web_vars:
self.standard_vars = Web_vars.standard_vars
self.advanced_vars = Web_vars.advanced_vars
else:
self.standard_vars = None
self.advanced_vars = None
#
def get_all_vars(self):
"""Return dictionary with all defined variables
combined together
"""
web_vars = {}
if self.advanced_vars:
web_vars = self.advanced_vars.copy()
if self.standard_vars:
if len(web_vars)>0:
web_vars.update(self.standard_vars)
else:
web_vars = self.standard_vars.copy()
return web_vars
def __init__(self,instrumentName,web_var=None):
""" sets properties defaults for the instrument with Name
and define if wrapper runs from web services or not
"""
# internal variable, indicating if we should try to wait for input files to appear
self._wait_for_file = False
#The property defines the run number, to validate. If defined, switches reduction wrapper from
#reduction to validation mode
self._run_number_to_validate=None
# internal variable, used in system tests to validate workflow,
# with waiting for files. It is the holder to the function
# used during debugging "wait for files" workflow
# instead of Pause algorithm
self._debug_wait_for_files_operation = None
# tolerance to change in some tests if default is not working well
self._tolerr=None
# The variables which are set up from web interface or to be exported to
# web interface
if web_var:
self._run_from_web = True
else:
self._run_from_web = False
self._wvs = ReductionWrapper.var_holder(web_var)
# Initialize reduced for given instrument
self.reducer = DirectEnergyConversion(instrumentName)
#
web_vars = self._wvs.get_all_vars()
if web_vars :
self.reducer.prop_man.set_input_parameters(**web_vars)
@property
def wait_for_file(self):
""" If this variable set to positive value, this value
is interpreted as time to wait until check for specified run file
if this file have not been find immediately.
if this variable is 0 or false and the file have not been found,
reduction will fail
"""
return self._wait_for_file
@wait_for_file.setter
def wait_for_file(self,value):
if value > 0:
self._wait_for_file = value
else:
self._wait_for_file = False
#
def save_web_variables(self,FileName=None):
""" Method to write simple and advanced properties and help
information into dictionary, to use by web reduction
interface
If no file is provided, reduce_var.py file will be written
to the folder, containing current script
"""
if not FileName:
FileName = 'reduce_vars.py'
f = open(FileName,'w')
f.write("standard_vars = {\n")
str_wrapper = ' '
for key,val in self._wvs.standard_vars.iteritems():
if isinstance(val,str):
row = "{0}\'{1}\':\'{2}\'".format(str_wrapper,key,val)
else:
#.........这里部分代码省略.........
示例13: test_abs_multirep_with_bkg_and_bleed
def test_abs_multirep_with_bkg_and_bleed(self):
# create test workspace
run_monitors=CreateSampleWorkspace(Function='Multiple Peaks', NumBanks=4, BankPixelWidth=1,\
NumEvents=100000, XUnit='Energy', XMin=3, XMax=200, BinWidth=0.1)
LoadInstrument(run_monitors,InstrumentName='MARI', RewriteSpectraMap=True)
ConvertUnits(InputWorkspace='run_monitors', OutputWorkspace='run_monitors', Target='TOF')
run_monitors = mtd['run_monitors']
tof = run_monitors.dataX(3)
tMin = tof[0]
tMax = tof[-1]
run = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=8, BankPixelWidth=1,\
NumEvents=100000, XUnit='TOF',xMin=tMin,xMax=tMax)
LoadInstrument(run,InstrumentName='MARI', RewriteSpectraMap=True)
AddSampleLog(run,LogName='gd_prtn_chrg',LogText='1.',LogType='Number')
run.setMonitorWorkspace(run_monitors)
# build "monovanadium"
mono = CloneWorkspace(run)
mono_monitors = CloneWorkspace(run_monitors)
mono.setMonitorWorkspace(mono_monitors)
# build "White-beam"
wb_ws = Rebin(run,Params=[tMin,1,tMax],PreserveEvents=False)
# build "second run" to ensure repeated execution
run2 = CloneWorkspace(run)
run2_monitors = CloneWorkspace(run_monitors)
run2.setMonitorWorkspace(run2_monitors)
# Run multirep
tReducer = DirectEnergyConversion(run.getInstrument())
tReducer.prop_man.run_diagnostics=True
tReducer.hard_mask_file=None
tReducer.map_file=None
tReducer.prop_man.check_background = True
tReducer.prop_man.background_range=[0.99*tMax,tMax]
tReducer.prop_man.monovan_mapfile=None
tReducer.save_format=None
tReducer.prop_man.normalise_method='monitor-2'
tReducer.prop_man.bleed = True
tReducer.norm_mon_integration_range=[tMin,tMax]
AddSampleLog(run,LogName='good_frames',LogText='1.',LogType='Number Series')
result = tReducer.convert_to_energy(wb_ws,run,[67.,122.],[-2,0.02,0.8],None,mono)
self.assertEqual(len(result),2)
ws1=result[0]
self.assertEqual(ws1.getAxis(0).getUnit().unitID(),'DeltaE')
x = ws1.readX(0)
self.assertAlmostEqual(x[0],-2*67.)
self.assertAlmostEqual(x[-1],0.8*67.)
ws2=result[1]
self.assertEqual(ws2.getAxis(0).getUnit().unitID(),'DeltaE')
x = ws2.readX(0)
self.assertAlmostEqual(x[0],-2*122.)
self.assertAlmostEqual(x[-1],0.8*122.)
# test another ws
# rename samples from previous workspace to avoid deleting them on current run
for ind,item in enumerate(result):
result[ind]=RenameWorkspace(item,OutputWorkspace='SampleRez#'+str(ind))
#
AddSampleLog(run2,LogName='goodfrm',LogText='1',LogType='Number')
result2 = tReducer.convert_to_energy(None,run2)
rez = CompareWorkspaces(result[0],result2[0])
self.assertTrue(rez[0])
rez = CompareWorkspaces(result[1],result2[1])
self.assertTrue(rez[0])
示例14: test_multirep_abs_units_mode
def test_multirep_abs_units_mode(self):
# create test workspace
run_monitors = CreateSampleWorkspace(
Function="Multiple Peaks",
NumBanks=4,
BankPixelWidth=1,
NumEvents=100000,
XUnit="Energy",
XMin=3,
XMax=200,
BinWidth=0.1,
)
LoadInstrument(run_monitors, InstrumentName="MARI", RewriteSpectraMap=True)
ConvertUnits(InputWorkspace="run_monitors", OutputWorkspace="run_monitors", Target="TOF")
run_monitors = mtd["run_monitors"]
tof = run_monitors.dataX(3)
tMin = tof[0]
tMax = tof[-1]
run = CreateSampleWorkspace(
Function="Multiple Peaks",
WorkspaceType="Event",
NumBanks=8,
BankPixelWidth=1,
NumEvents=100000,
XUnit="TOF",
xMin=tMin,
xMax=tMax,
)
LoadInstrument(run, InstrumentName="MARI", RewriteSpectraMap=True)
# build "monovanadium"
mono = CloneWorkspace(run)
mono_monitors = CloneWorkspace(run_monitors)
# build "White-beam"
wb_ws = Rebin(run, Params=[tMin, 1, tMax], PreserveEvents=False)
# build "second run" to ensure repeated execution
run2 = CloneWorkspace(run)
run2_monitors = CloneWorkspace(run_monitors)
# Run multirep
tReducer = DirectEnergyConversion(run.getInstrument())
tReducer.prop_man.run_diagnostics = True
tReducer.hard_mask_file = None
tReducer.map_file = None
tReducer.prop_man.background_range = [0.99 * tMax, tMax]
tReducer.prop_man.monovan_mapfile = None
tReducer.save_format = None
tReducer.prop_man.normalise_method = "monitor-1"
tReducer.norm_mon_integration_range = [tMin, tMax]
result = tReducer.convert_to_energy(wb_ws, run, [67.0, 122.0], [-2, 0.02, 0.8], None, mono)
self.assertEqual(len(result), 2)
ws1 = result[0]
self.assertEqual(ws1.getAxis(0).getUnit().unitID(), "DeltaE")
x = ws1.readX(0)
self.assertAlmostEqual(x[0], -2 * 67.0)
self.assertAlmostEqual(x[-1], 0.8 * 67.0)
ws2 = result[1]
self.assertEqual(ws2.getAxis(0).getUnit().unitID(), "DeltaE")
x = ws2.readX(0)
self.assertAlmostEqual(x[0], -2 * 122.0)
self.assertAlmostEqual(x[-1], 0.8 * 122.0)
# test another ws
# rename samples from previous workspace to avoid deleting them on current run
for ind, item in enumerate(result):
result[ind] = RenameWorkspace(item, OutputWorkspace="SampleRez#" + str(ind))
#
result2 = tReducer.convert_to_energy(None, run2)
rez = CheckWorkspacesMatch(result[0], result2[0])
self.assertEqual(rez, "Success!")
rez = CheckWorkspacesMatch(result[1], result2[1])
self.assertEqual(rez, "Success!")
示例15: ReductionWrapper
class ReductionWrapper(object):
""" Abstract class provides interface to direct inelastic reduction
allowing it to be run from Mantid, web services, or system tests
using the same interface and the same run file placed in different
locations.
"""
class var_holder(object):
""" A simple wrapper class to keep web variables"""
def __init__(self):
self.standard_vars = None
self.advanced_vars = None
pass
def __init__(self,instrumentName,web_var=None):
""" sets properties defaults for the instrument with Name
and define if wrapper runs from web services or not
"""
# internal variable, indicating if we should try to wait for input files to appear
self._wait_for_file=False
# The variables which are set up from web interface or to be exported to
# web interface
if web_var:
self._run_from_web = True
self._wvs = web_var
else:
self._run_from_web = False
self._wvs = ReductionWrapper.var_holder()
# Initialize reduced for given instrument
self.reducer = DirectEnergyConversion(instrumentName)
self._validation_fname=None
#
def get_validation_file_name(self,ReferenceFile=None):
""" function provides name of the file with mantid
workspace reduced earlier and which should be validated
against results of current reduction
Should be overloaded to return real file name for particular
reduction
"""
if ReferenceFile:
self._validation_fname = ReferenceFile
return self._validation_fname
@property
def wait_for_file(self):
""" If this variable set to positive value, this value
is interpreted as time to wait until check for specified run file
if this file have not been find immediately.
if this variable is 0 or false and the the file have not been found,
reduction will fail
"""
return self._wait_for_file
@wait_for_file.setter
def wait_for_file(self,value):
if value>0:
self._wait_for_file = value
else:
self._wait_for_file = False
#
def save_web_variables(self,FileName=None):
""" Method to write simple and advanced properties and help
information into dictionary, to use by web reduction
interface
If no file is provided, reduce_var.py file will be written
to
"""
if not FileName:
FileName = 'reduce_vars.py'
f=open(FileName,'w')
f.write("standard_vars = {\n")
str_wrapper = ' '
for key,val in self._wvs.standard_vars.iteritems():
if isinstance(val,str):
row = "{0}\'{1}\':\'{2}\'".format(str_wrapper,key,val)
else:
row = "{0}\'{1}\':{2}".format(str_wrapper,key,val)
f.write(row)
str_wrapper=',\n '
f.write("\n}\nadvanced_vars={\n")
str_wrapper=' '
for key,val in self._wvs.advanced_vars.iteritems():
if isinstance(val,str):
row = "{0}\'{1}\':\'{2}\'".format(str_wrapper,key,val)
else:
row = "{0}\'{1}\':{2}".format(str_wrapper,key,val)
f.write(row)
str_wrapper=',\n '
f.write("\n}\n")
f.close()
#
#
def validate_result(self,build_validation=False,Error=1.e-3,ToleranceRelErr=True):
#.........这里部分代码省略.........