Commit f20d0762 authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Update filtering/.#FilterTime.py filtering/FilterTime.py...

Update filtering/.#FilterTime.py filtering/FilterTime.py filtering/PowerReduction_temp_filter.py filtering/PowerReduction_ttime_filter.py filtering/Temp_ROI.py
parent 7719117b
rwp@diffuse.12279:1532959676
\ No newline at end of file
from mantid.simpleapi import *
name = 'output'
IPTS = 19834
run = 122687
vanadium = 101567 # Run number or `None`
vanadium_IPTS = 7776
normaliseBy='Monitor' # One on (None, Monitor, Time)
units = 'Theta' # One of (Theta, ElasticQ, ElasticDSpacing)
Binning = '3,123,1200' # Min,Max,Number_of_bins
# Time filter options
TimeInterval=3600
StartTime=None
StopTime=None
###############################################################################
# Load vandium if not already loaded.
vanadium_ws = 'HB2C_{}'.format(vanadium)
if vanadium_ws not in mtd:
cal = LoadWAND(Filename=van_iptsdir+'nexus/HB2C_{}.nxs.h5'.format(vanadium))
# Load data if not already loaded
ws = 'HB2C_{}'.format(vanadium)
if ws not in mtd:
LoadEventNexus(Filename='/HFIR/HB2C/IPTS-{}/nexus/HB2C_{}.nxs.h5'.format(IPTS, run), OutputWorkspace=ws,LoadMonitors=True)
# Filter events
GenerateEventsFilter(InputWorkspace=ws, OutputWorkspace='filter', InformationWorkspace='info', TimeInterval='3600',StartTime='0',StopTime='84000')
FilterEvents(InputWorkspace=ws, SplitterWorkspace='filter', OutputWorkspaceBaseName=ws+'_filtered', InformationWorkspace='info',
GroupWorkspaces=True,FilterByPulseTime=True,OutputWorkspaceIndexedFrom1=True)
FilterEvents(InputWorkspace=ws+'_monitors', SplitterWorkspace='filter', OutputWorkspaceBaseName=ws+'_filtered_mon', InformationWorkspace='info',
GroupWorkspaces=True,FilterByPulseTime=True,SpectrumWithoutDetector='Skip only if TOF correction',OutputWorkspaceIndexedFrom1=True)
for n in range(mtd['out'].getNumberOfEntries()):
AddSampleLog(mtd['out'].getItem(n), LogName="gd_prtn_chrg", LogType='Number', NumberType='Double',LogText=str(mtd['mon'].getItem(n).getNumberEvents()))
MaskBTP('out', Bank='8', Tube='475-480')
MaskBTP('out', Pixel='1,2,511,512')
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'].getNumberOfEntries()):
nameT = name+'_'+mtd['out'][n].name()
group_list.append(nameT)
WANDPowderReduction(mtd['out'][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name)
from mantid.simpleapi import *
name = 'La1p3Sr2p3FeO3_1'
IPTS = 20325
run = 26563
vanadium = 7553 # Run number of `None`
vanadium_IPTS = 20325
normaliseBy='Monitor' # One on (None, Monitor, Time)
units = 'Theta' # One of (Theta, ElasticQ, ElasticDSpacing)
Binning = '2.5,122,2500' # Min,Max,Number_of_bins
use_autoreduced = False
use_autoreduced_van = True
###############################################################################
def reduceToPowder(ws, OutputWorkspace, cal=None, target='Theta', XMin=10, XMax=135, NumberBins=2500, normaliseBy='Monitor'):
ConvertSpectrumAxis(InputWorkspace=ws, Target=target, OutputWorkspace=OutputWorkspace)
Transpose(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace)
ResampleX(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, XMin=XMin, XMax=XMax, NumberBins=NumberBins)
if cal is not None:
CopyInstrumentParameters(ws, cal)
ConvertSpectrumAxis(InputWorkspace=cal, Target=target, OutputWorkspace='__cal')
Transpose(InputWorkspace='__cal', OutputWorkspace='__cal')
ResampleX(InputWorkspace='__cal', OutputWorkspace='__cal', XMin=XMin, XMax=XMax, NumberBins=NumberBins)
Divide(LHSWorkspace=OutputWorkspace, RHSWorkspace='__cal', OutputWorkspace=OutputWorkspace)
DeleteWorkspace('__cal')
if normaliseBy == "Monitor":
ws_monitor = mtd[str(ws)].run().getProtonCharge()
cal_monitor = mtd[str(cal)].run().getProtonCharge()
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_monitor/ws_monitor)
elif normaliseBy == "Time":
ws_duration = mtd[str(ws)].run().getLogData('duration').value
cal_duration = mtd[str(cal)].run().getLogData('duration').value
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_duration/ws_duration)
return OutputWorkspace
###############################################################################
iptsdir = '/HFIR/HB2C/IPTS-{}/'.format(IPTS)
van_iptsdir = '/HFIR/HB2C/IPTS-{}/'.format(vanadium_IPTS)
LoadEventNexus(Filename=iptsdir+'nexus/HB2C_{}.nxs.h5'.format(run), OutputWorkspace='ws',LoadMonitors=True)
GenerateEventsFilter(InputWorkspace='ws', OutputWorkspace='filter', InformationWorkspace='info', LogName='HB2C:SE:SampleTemp', LogValueInterval=1,MinimumLogValue=190,MaximumLogValue=210)
FilterEvents(InputWorkspace='ws', SplitterWorkspace='filter', OutputWorkspaceBaseName='out', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,OutputWorkspaceIndexedFrom1=True)
FilterEvents(InputWorkspace='ws_monitors', SplitterWorkspace='filter', OutputWorkspaceBaseName='mon', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,SpectrumWithoutDetector='Skip only if TOF correction',OutputWorkspaceIndexedFrom1=True)
for n in range(mtd['out'].getNumberOfEntries()):
AddSampleLog(mtd['out'].getItem(n), LogName="gd_prtn_chrg", LogType='Number', NumberType='Double',LogText=str(mtd['mon'].getItem(n).getNumberEvents()))
MaskBTP('out', Bank='8', Tube='475-480')
MaskBTP('out', Pixel='1,2,511,512')
if vanadium is not None:
if 'cal' in mtd:
cal = mtd['cal']
else:
if use_autoreduced_van:
cal = LoadNexus(Filename=van_iptsdir+'shared/autoreduce/HB2C_{}.nxs'.format(vanadium))
else:
cal = LoadWAND(Filename=van_iptsdir+'shared/autoreduce/HB2C_{}.nxs.h5'.format(vanadium))
else:
cal = None
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'].getNumberOfEntries()):
nameT = name+'_{:05.1f}K'.format(mtd['out'][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name)
labels=','.join(['{:.1f}'.format(w.run().getLogData("HB2C:SE:SampleTemp").timeAverageValue()) for w in mtd['out']])
print(labels)
from mantid.simpleapi import *
name = 'AmV6a_time'
IPTS = 19834
run = 122687
vanadium = 101567 # Run number of `None`
vanadium_IPTS = 7776
normaliseBy='Monitor' # One on (None, Monitor, Time)
units = 'Theta' # One of (Theta, ElasticQ, ElasticDSpacing)
Binning = '3,123,1200' # Min,Max,Number_of_bins
use_autoreduced = False
use_autoreduced_van = False
###############################################################################
def reduceToPowder(ws, OutputWorkspace, cal=None, target='Theta', XMin=10, XMax=135, NumberBins=2500, normaliseBy='Monitor'):
ConvertSpectrumAxis(InputWorkspace=ws, Target=target, OutputWorkspace=OutputWorkspace)
Transpose(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace)
ResampleX(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, XMin=XMin, XMax=XMax, NumberBins=NumberBins)
if cal is not None:
CopyInstrumentParameters(ws, cal)
ConvertSpectrumAxis(InputWorkspace=cal, Target=target, OutputWorkspace='__cal')
Transpose(InputWorkspace='__cal', OutputWorkspace='__cal')
ResampleX(InputWorkspace='__cal', OutputWorkspace='__cal', XMin=XMin, XMax=XMax, NumberBins=NumberBins)
Divide(LHSWorkspace=OutputWorkspace, RHSWorkspace='__cal', OutputWorkspace=OutputWorkspace)
DeleteWorkspace('__cal')
if normaliseBy == "Monitor":
ws_monitor = mtd[str(ws)].run().getProtonCharge()
cal_monitor = mtd[str(cal)].run().getProtonCharge()
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_monitor/ws_monitor)
elif normaliseBy == "Time":
ws_duration = mtd[str(ws)].run().getLogData('duration').value
cal_duration = mtd[str(cal)].run().getLogData('duration').value
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_duration/ws_duration)
return OutputWorkspace
###############################################################################
iptsdir = '/HFIR/HB2C/IPTS-{}/'.format(IPTS)
van_iptsdir = '/HFIR/HB2C/IPTS-{}/'.format(vanadium_IPTS)
LoadEventNexus(Filename=iptsdir+'nexus/HB2C_{}.nxs.h5'.format(run), OutputWorkspace='ws',LoadMonitors=True)
GenerateEventsFilter(InputWorkspace='ws', OutputWorkspace='filter', InformationWorkspace='info', TimeInterval='3600',StartTime='0',StopTime='84000')
FilterEvents(InputWorkspace='ws', SplitterWorkspace='filter', OutputWorkspaceBaseName='out', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,OutputWorkspaceIndexedFrom1=True)
FilterEvents(InputWorkspace='ws_monitors', SplitterWorkspace='filter', OutputWorkspaceBaseName='mon', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,SpectrumWithoutDetector='Skip only if TOF correction',OutputWorkspaceIndexedFrom1=True)
for n in range(mtd['out'].getNumberOfEntries()):
AddSampleLog(mtd['out'].getItem(n), LogName="gd_prtn_chrg", LogType='Number', NumberType='Double',LogText=str(mtd['mon'].getItem(n).getNumberEvents()))
MaskBTP('out', Bank='8', Tube='475-480')
MaskBTP('out', Pixel='1,2,511,512')
if vanadium is not None:
if 'cal' in mtd:
cal = mtd['cal']
else:
if use_autoreduced_van:
cal = LoadNexus(Filename=van_iptsdir+'shared/autoreduce/HB2C_{}.nxs'.format(vanadium))
else:
cal = LoadWAND(Filename=van_iptsdir+'nexus/HB2C_{}.nxs.h5'.format(vanadium))
else:
cal = None
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'].getNumberOfEntries()):
nameT = name+'_'+mtd['out'][n].name()
group_list.append(nameT)
reduceToPowder(mtd['out'][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name)
ws=LoadEventNexus('/HFIR/HB2C/IPTS-20148/nexus/HB2C_55562.nxs.h5',LoadMonitors=True)
GenerateEventsFilter(InputWorkspace='ws', OutputWorkspace='filter', InformationWorkspace='info', LogName='HB2C:SE:SampleTemp', LogValueInterval=2,MinimumLogValue=150,MaximumLogValue=300)
FilterEvents(InputWorkspace='ws', SplitterWorkspace='filter', OutputWorkspaceBaseName='out', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,OutputWorkspaceIndexedFrom1=True)
FilterEvents(InputWorkspace='ws_monitors', SplitterWorkspace='filter', OutputWorkspaceBaseName='mon', InformationWorkspace='info',GroupWorkspaces=True,FilterByPulseTime=True,SpectrumWithoutDetector='Skip only if TOF correction',OutputWorkspaceIndexedFrom1=True)
Ei=UnitConversion.run('Wavelength', 'Energy', 1.488, 0, 0, 0, Elastic, 0)
for n in range(mtd['out'].getNumberOfEntries()):
AddSampleLog(mtd['out'].getItem(n), LogName="gd_prtn_chrg", LogType='Number', NumberType='Double',LogText=str(mtd['mon'].getItem(n).getNumberEvents()))
AddSampleLog(mtd['out'], LogName="Ei", LogType='Number', NumberType='Double',LogText=str(Ei))
MaskBTP('out', Bank='8', Tube='475-480')
MaskBTP('out', Pixel='1,2,511,512')
name = 'LSCO_150to300'
IPTS = 20148
first_run = 55562
vanadium = 26613
vanadium_IPTS = 20148
normaliseBy='Monitor' # One on (None, Monitor, Time)
units = 'ElasticDSpacing' # One of (Theta, ElasticQ, ElasticDSpacing)
Binning = '1.5,2,201' # Min,Max,Number_of_bins
use_autoreduced = False
use_autoreduced_van = False
###############################################################################
def reduceToPowder(ws, OutputWorkspace, cal=None, target='Theta', XMin=10, XMax=135, NumberBins=2500, normaliseBy='Monitor'):
ConvertSpectrumAxis(InputWorkspace=ws, Target=target, OutputWorkspace=OutputWorkspace)
Transpose(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace)
ResampleX(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, XMin=XMin, XMax=XMax, NumberBins=NumberBins)
if cal is not None:
CopyInstrumentParameters(ws, cal)
ConvertSpectrumAxis(InputWorkspace=cal, Target=target, OutputWorkspace='__cal')
Transpose(InputWorkspace='__cal', OutputWorkspace='__cal')
ResampleX(InputWorkspace='__cal', OutputWorkspace='__cal', XMin=XMin, XMax=XMax, NumberBins=NumberBins)
Divide(LHSWorkspace=OutputWorkspace, RHSWorkspace='__cal', OutputWorkspace=OutputWorkspace)
DeleteWorkspace('__cal')
if normaliseBy == "Monitor":
ws_monitor = mtd[str(ws)].run().getProtonCharge()
cal_monitor = mtd[str(cal)].run().getProtonCharge()
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_monitor/ws_monitor)
elif normaliseBy == "Time":
ws_duration = mtd[str(ws)].run().getLogData('duration').value
cal_duration = mtd[str(cal)].run().getLogData('duration').value
Scale(InputWorkspace=OutputWorkspace, OutputWorkspace=OutputWorkspace, Factor=cal_duration/ws_duration)
return OutputWorkspace
###############################################################################
van_iptsdir = '/HFIR/HB2C/IPTS-{}/'.format(vanadium_IPTS)
if vanadium is not None:
if 'cal' in mtd:
cal = mtd['cal']
else:
if use_autoreduced_van:
cal = LoadNexus(Filename=van_iptsdir+'shared/autoreduce/HB2C_{}.nxs'.format(vanadium))
else:
cal = LoadWAND(Filename=van_iptsdir+'shared/HB2C_{}.nxs.h5'.format(vanadium))
else:
cal = None
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'].getNumberOfEntries()):
nameT = name+'_{:05.1f}K'.format(mtd['out'][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name)
labels=','.join(['{:.1f}'.format(w.run().getLogData("HB2C:SE:SampleTemp").timeAverageValue()) for w in mtd['out']])
print(labels)
# ROI 1
ROI_workspace='MaskWorkspace'
roi_name = '_ROI1'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
# ROI 2
ROI_workspace='MaskWorkspace_2'
roi_name = '_ROI2'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
DeleteWorkspace('out'+roi_name)
DeleteWorkspace('cal'+roi_name)
# ROI 3
ROI_workspace='MaskWorkspace_3'
roi_name = '_ROI3'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
DeleteWorkspace('out'+roi_name)
DeleteWorkspace('cal'+roi_name)
# ROI 4
ROI_workspace='MaskWorkspace_4'
roi_name = '_ROI4'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
DeleteWorkspace('out'+roi_name)
DeleteWorkspace('cal'+roi_name)
# ROI 5
ROI_workspace='MaskWorkspace_5'
roi_name = '_ROI5'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
DeleteWorkspace('out'+roi_name)
DeleteWorkspace('cal'+roi_name)
# ROI 6
ROI_workspace='MaskWorkspace_6'
roi_name = '_ROI6'
CloneWorkspace('out',OutputWorkspace='out'+roi_name)
CloneWorkspace('cal',OutputWorkspace='cal'+roi_name)
MaskDetectors('out'+roi_name,MaskedWorkspace=ROI_workspace)
MaskDetectors('cal'+roi_name,MaskedWorkspace=ROI_workspace)
xmin, xmax, bins = Binning.split(',')
group_list=[]
for n in range(mtd['out'+roi_name].getNumberOfEntries()):
nameT = name+roi_name+'_{:05.1f}K'.format(mtd['out'+roi_name][n].run().getLogData("HB2C:SE:SampleTemp").timeAverageValue())
group_list.append(nameT)
reduceToPowder(mtd['out'+roi_name][n], OutputWorkspace=nameT, cal=cal, target=units, XMin=xmin, XMax=xmax, NumberBins=bins, normaliseBy=normaliseBy)
GroupWorkspaces(group_list,OutputWorkspace=name+roi_name)
DeleteWorkspace('out'+roi_name)
DeleteWorkspace('cal'+roi_name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment