本文整理汇总了Python中Direct.DirectEnergyConversion.DirectEnergyConversion.convert_to_energy方法的典型用法代码示例。如果您正苦于以下问题:Python DirectEnergyConversion.convert_to_energy方法的具体用法?Python DirectEnergyConversion.convert_to_energy怎么用?Python DirectEnergyConversion.convert_to_energy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direct.DirectEnergyConversion.DirectEnergyConversion
的用法示例。
在下文中一共展示了DirectEnergyConversion.convert_to_energy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multirep_mode
# 需要导入模块: from Direct.DirectEnergyConversion import DirectEnergyConversion [as 别名]
# 或者: from Direct.DirectEnergyConversion.DirectEnergyConversion import convert_to_energy [as 别名]
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])
示例2: ReductionWrapper
# 需要导入模块: from Direct.DirectEnergyConversion import DirectEnergyConversion [as 别名]
# 或者: from Direct.DirectEnergyConversion.DirectEnergyConversion import convert_to_energy [as 别名]
#.........这里部分代码省略.........
reduction properties between script and web variables
"""
if input_file:
self.reducer.sample_run = str(input_file)
if output_directory:
config['defaultsave.directory'] = str(output_directory)
timeToWait = self._wait_for_file
wait_counter=0
if timeToWait > 0:
Found,input_file = PropertyManager.sample_run.find_file(be_quet=True)
while not Found:
file_hint,fext = PropertyManager.sample_run.file_hint()
self.reducer.prop_man.log("*** Waiting {0} sec for file {1} to appear on the data search path"\
.format(timeToWait,file_hint),'notice')
self._run_pause(timeToWait)
Found,input_file = PropertyManager.sample_run.find_file(file_hint=file_hint,be_quet=True)
if Found:
file,found_ext=os.path.splitext(input_file)
if found_ext != fext:
wait_counter+=1
if wait_counter<2:
timeToWait =60
self.reducer.prop_man.log(\
"*** Requested file with extension {0} but found one with extension {1}\n"\
" The target may not have been delivered from the DAE machine\n".format(fext,found_ext))
Found = False
else:
wait_counter = 0
else:
pass # not found, wait more
#endWhile
converted_to_energy_transfer_ws = self.reducer.convert_to_energy(None,input_file)
else:
converted_to_energy_transfer_ws = self.reducer.convert_to_energy(None,input_file)
return converted_to_energy_transfer_ws
#
def sum_and_reduce(self):
""" procedure used to sum and reduce runs in case when not all files
are available and user have to wait for these files to appear
"""
if not PropertyManager.sample_run._run_list:
raise RuntimeError("sum_and_reduce expects run file list to be defined")
self.reducer.prop_man.sum_runs = True
timeToWait = self._wait_for_file
self._wait_for_file = 0
if timeToWait > 0:
run_files = PropertyManager.sample_run.get_run_list()
num_files_to_sum = len(PropertyManager.sample_run)
ok,missing,found = self.reducer.prop_man.find_files_to_sum()
n_found = len(found)
if not ok:
# necessary to cache intermediate sums in memory
self.reducer.prop_man.cashe_sum_ws = True
while not ok:
while n_found > 0:
last_found = found[-1]
self.reducer.prop_man.sample_run = last_found # request to reduce all up to last found
# Note that here we run convert to energy instead of user (may be) reloaded reduction!
# This would cause problem for user-defined reduction, which pre-process rather than
示例3: test_abs_multirep_with_bkg_and_bleed
# 需要导入模块: from Direct.DirectEnergyConversion import DirectEnergyConversion [as 别名]
# 或者: from Direct.DirectEnergyConversion.DirectEnergyConversion import convert_to_energy [as 别名]
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])
示例4: test_multirep_abs_units_mode
# 需要导入模块: from Direct.DirectEnergyConversion import DirectEnergyConversion [as 别名]
# 或者: from Direct.DirectEnergyConversion.DirectEnergyConversion import convert_to_energy [as 别名]
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!")
示例5: ReductionWrapper
# 需要导入模块: from Direct.DirectEnergyConversion import DirectEnergyConversion [as 别名]
# 或者: from Direct.DirectEnergyConversion.DirectEnergyConversion import convert_to_energy [as 别名]
#.........这里部分代码省略.........
""" Method validates results of the reduction against reference file provided
by get_validation_file_name() method
At the moment, get_validation_file_name method should return the name of a file,
where workspace sample reduced workspace with default properties
is stored.
CheckWorkspaceMatch method is applied to verify if current reduced workspace is
equivalent to the workspace, stored in the reference file.
"""
if not build_validation:
if validationFile:
sample = Load(validationFile)
else:
build_validation=True
# just in case, to be sure
current_web_state = self._run_from_web
current_wait_state= self.wait_for_file
# disable wait for input and
self._run_from_web = False
self.wait_for_file = False
#
self.def_advanced_properties()
self.def_main_properties()
#
self.reducer.sample_run = sample_run
self.reducer.prop_man.save_format=None
reduced = self.reduce()
if build_validation:
if validationFile:
result_name = os.path.splitext(validationFile)[0]
else:
result_name = self.reducer.prop_man.save_file_name
self.reducer.prop_man.log("*** Saving validation file with name: {0}.nxs".format(result_name),'notice')
SaveNexus(reduced,Filename=result_name+'.nxs')
return True,'Created validation file {0}.nxs'.format(result_name)
else:
result = CheckWorkspacesMatch(Workspace1=sample,Workspace2=reduced,
Tolerance=Error,CheckSample=False,
CheckInstrument=False,ToleranceRelErr=ToleranceRelErr)
self.wait_for_file = current_wait_state
self._run_from_web = current_web_state
if result == 'Success!':
return True,'Reference file and reduced workspace are equivalent'
else:
return False,result
@abstractmethod
def def_main_properties(self):
""" Define properties which considered to be main properties changeable by user
Should be overwritten by special reduction and decorated with @MainProperties decorator.
Should return dictionary with key are the properties names and values -- the default
values these properties should have.
"""
raise NotImplementedError('def_main_properties has to be implemented')
@abstractmethod
def def_advanced_properties(self):
""" Define properties which considered to be advanced but still changeable by instrument scientist or advanced user
Should be overwritten by special reduction and decorated with @AdvancedProperties decorator.
Should return dictionary with key are the properties names and values -- the default
values these properties should have.
"""
raise NotImplementedError('def_advanced_properties has to be implemented')
def reduce(self,input_file=None,output_directory=None):
""" The method performs all main reduction operations over
single run file
Wrap it into @iliad wrapper to switch input for
reduction properties between script and web variables
"""
if input_file:
self.reducer.sample_run = input_file
timeToWait = self._wait_for_file
if timeToWait:
file = PropertyManager.sample_run.find_file(be_quet=True)
while file.find('ERROR:')>=0:
file_hint,fext = PropertyManager.sample_run.file_hint()
self.reducer.prop_man.log("*** Waiting {0} sec for file {1} to appear on the data search path"\
.format(timeToWait,file_hint),'notice')
Pause(timeToWait)
file = PropertyManager.sample_run.find_file(be_quet=True)
ws = self.reducer.convert_to_energy(None,input_file)
else:
ws = self.reducer.convert_to_energy(None,input_file)
return ws