Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge branch 'bugfix/9162_jumpfit_input_to_HWHM' of github.com:mantid…
Browse files Browse the repository at this point in the history
…project/systemtests into feature/4856_msdfit_ui_upgrade
  • Loading branch information
Samuel Jackson committed Mar 26, 2014
2 parents 5cb9498 + b4e2041 commit 3d33af3
Show file tree
Hide file tree
Showing 23 changed files with 7,997 additions and 7,761 deletions.
Binary file added Data/EMU03087.nxs
Binary file not shown.
Binary file added Data/LET00014305.nxs
Binary file not shown.
Binary file added Data/LET00014319.nxs
Binary file not shown.
Binary file added Data/det_corrected7.nxs
Binary file not shown.
Binary file added Data/irs53664_graphite002_sqw.nxs
Binary file not shown.
Binary file added Data/osi97935_graphite002_sqw.nxs
Binary file not shown.
36 changes: 26 additions & 10 deletions StressTestFramework/stresstesting.py
Expand Up @@ -243,14 +243,27 @@ def validateWorkspaceToNeXus(self):
'''
valNames = list(self.validate())
from mantid.simpleapi import Load
workspace2 = valNames[1]
if workspace2.endswith('.nxs'):
Load(Filename=workspace2,OutputWorkspace="RefFile")
workspace2 = "RefFile"
else:
raise RuntimeError("Should supply a NeXus file: %s" % workspace2)
valNames[1] = "RefFile"
return self.validateWorkspaces(valNames)
numRezToCheck=len(valNames)
mismatchName=None;

validationResult =True;
for ik in range(0,numRezToCheck,2): # check All results
workspace2 = valNames[ik+1]
if workspace2.endswith('.nxs'):
Load(Filename=workspace2,OutputWorkspace="RefFile")
workspace2 = "RefFile"
else:
raise RuntimeError("Should supply a NeXus file: %s" % workspace2)
valPair=(valNames[ik],"RefFile");
if numRezToCheck>2:
mismatchName = valNames[ik];

if not(self.validateWorkspaces(valPair,mismatchName)):
validationResult = False;
print 'Workspace {0} not equal to its reference file'.format(valNames[ik]);
#end check All results

return validationResult;

def validateWorkspaceToWorkspace(self):
'''
Expand All @@ -260,7 +273,7 @@ def validateWorkspaceToWorkspace(self):
valNames = list(self.validate())
return self.validateWorkspaces(valNames)

def validateWorkspaces(self, valNames=None):
def validateWorkspaces(self, valNames=None,mismatchName=None):
'''
Performs a check that two workspaces are equal using the CheckWorkspacesMatch
algorithm. Loads one workspace from a nexus file if appropriate.
Expand All @@ -284,7 +297,10 @@ def validateWorkspaces(self, valNames=None):
checker.execute()
if checker.getPropertyValue("Result") != 'Success!':
print self.__class__.__name__
SaveNexus(InputWorkspace=valNames[0],Filename=self.__class__.__name__+'-mismatch.nxs')
if mismatchName:
SaveNexus(InputWorkspace=valNames[0],Filename=self.__class__.__name__+mismatchName+'-mismatch.nxs')
else:
SaveNexus(InputWorkspace=valNames[0],Filename=self.__class__.__name__+'-mismatch.nxs')
return False

return True
Expand Down
175 changes: 162 additions & 13 deletions SystemTests/AnalysisTests/ISISDirectInelastic.py
Expand Up @@ -359,6 +359,38 @@ def validate(self):
return result, reference

#------------------------- LET tests -------------------------------------------------
#
def find_binning_range(energy,ebin):
""" function finds the binning range used in multirep mode
# THIS FUNCTION SHOULD BE MADE GENERIG AND MOVED OUT OF HERE
"""
energy=float(energy)

emin=(1.0-ebin[2])*energy #minimum energy is with 80% energy loss
lam=(81.81/energy)**0.5
lam_max=(81.81/emin)**0.5
tsam=252.82*lam*25 #time at sample
tmon2=252.82*lam*23.5 #time to monitor 6 on LET
tmax=tsam+(252.82*lam_max*4.1) #maximum time to measure inelastic signal to
t_elastic=tsam+(252.82*lam*4.1) #maximum time of elastic signal
tbin=[int(tmon2),1.6,int(tmax)]
energybin=[float("{0: 6.4f}".format(elem*energy)) for elem in ebin]

return (energybin,tbin,t_elastic);
#--------------------------------------------------------------------------------------------------------
def find_background(ws_name,bg_range):
""" Function to find background from multirep event workspace
# THIS FUNCTION SHOULD BE MADE GENERIC AND MOVED OUT OF HERE
"""
delta=bg_range[1]-bg_range[0]
Rebin(InputWorkspace='w1',OutputWorkspace='bg',Params=[bg_range[0],delta,bg_range[1]],PreserveEvents=False)
v=(delta)/1.6
CreateSingleValuedWorkspace(OutputWorkspace='d',DataValue=v)
Divide(LHSWorkspace='bg',RHSWorkspace='d',OutputWorkspace='bg')



class LETReduction(stresstesting.MantidStressTest):

Expand Down Expand Up @@ -389,27 +421,21 @@ def runTest(self):
MonitorsAsEvents='1')
ConjoinWorkspaces(InputWorkspace1=sample_ws, InputWorkspace2=monitors_ws)

energy = ei
emin = 0.2*energy #minimum energy is with 80% energy loss
lam = (81.81/energy)**0.5
lam_max = (81.81/emin)**0.5
tsam = 252.82*lam*25 #time at sample
tmon2 = 252.82*lam*23.5 #time to monitor 6 on LET
tmax = tsam+(252.82*lam_max*4.1) #maximum time to measure inelastic signal to
t_elastic = tsam+(252.82*lam*4.1) #maximum time of elastic signal
tbin = [int(tmon2),1.6,int(tmax)]
(energybin,tbin,t_elastic) = find_binning_range(ei,ebin);

Rebin(InputWorkspace=sample_ws,OutputWorkspace=sample_ws, Params=tbin, PreserveEvents='1')
energybin = [ebin[0]*energy,ebin[1]*energy,ebin[2]*energy]
energybin = [ '%.4f' % elem for elem in energybin ]
#energybin = [ebin[0]*energy,ebin[1]*energy,ebin[2]*energy]
#energybin = [ '%.4f' % elem for elem in energybin ]
ebinstring = str(energybin[0])+','+str(energybin[1])+','+str(energybin[2])
argi={}
argi['det_cal_file']='det_corrected7.dat'
argi['bleed'] = False
argi['norm_method']='current'
argi['detector_van_range']=[0.5,200]
argi['bkgd_range']=[int(t_elastic),int(tmax)]
argi['bkgd_range']=[int(t_elastic),int(tbin[2])]
argi['hard_mask_file']='LET_hard.msk'
reduced_ws = dgreduce.arb_units(white_ws, sample_ws, energy, ebinstring, map_file,**argi)

reduced_ws = dgreduce.arb_units(white_ws, sample_ws, ei, ebinstring, map_file,**argi)
pass

def validate(self):
Expand All @@ -420,3 +446,126 @@ def validate(self):

return "reduced_ws", "LETReduction.nxs"

class LETReductionEvent2014Multirep(stresstesting.MantidStressTest):
"""
written in a hope that most of the stuff find here will eventually find its way into main reduction routines
"""

def requiredMemoryMB(self):
"""Far too slow for managed workspaces. They're tested in other places. Requires 2Gb"""
return 2000

def runTest(self):
"""
Run the LET reduction with event NeXus files
Relies on LET_Parameters.xml file from June 2013
"""

dgreduce.setup('LET')
wb=5545 #11869 # enter whitebeam run number here

run_no=[14305]
ei=[3.4,8.] # multiple energies provided in the data file
ebin=[-4,0.002,0.8] #binning of the energy for the spe file. The numbers are as a fraction of ei [from ,step, to ]
mapping='rings_103.map' # rings mapping file for powders, liquout=iliad("wb_wksp","w1reb",energy,ebinstring,mapping,bleed=False,norm_method='current',det_cal_file='det_corrected7.dat',detector_van_range=[0.5,200],bkgd_range=[int(t_elastic),int(tmax)])
mask_file = 'LET_hard.msk'
# currently done here on-
remove_background = True #if true then will subtract a flat background in time from the time range given below otherwise put False
bg_range=[92000,98000] # range of times to take background in



# loads the whitebeam (or rather the long monovan ). Does it as a raw file to save time as the event mode is very large
if 'wb_wksp' in mtd:
wb_wksp=mtd['wb_wksp']
else: #only load whitebeam if not already there
LoadRaw(Filename='LET0000'+str(wb)+'.raw',OutputWorkspace='wb_wksp')
#dgreduce.getReducer().det_cal_file = 'det_corrected7.nxs'
#wb_wksp = dgreduce.getReducer().load_data('LET0000'+str(wb)+'.raw','wb_wksp')
#dgreduce.getReducer().det_cal_file = wb_wksp;

######################################################################

############################################
# Vanadium labelled Dec 2011 - flat plate of dimensions: 40.5x41x2.0# volume = 3404.025 mm**3 mass= 20.79
sampleMass=20.79 # 17.25 # mass of your sample (PrAl3)
sampleRMM= 50.9415 # 221.854 # molecular weight of your sample
MonoVanRun=14319 # vanadium run in the same configuration as your sample
monovan_mapfile='rings_103.map' #

######################################################################

MonoVanWB="wb_wksp"
for run in run_no: #loop around runs
fname='LET0000'+str(run)+'.nxs'
print ' processing file ', fname
#w1 = dgreduce.getReducer().load_data(run,'w1')
Load(Filename=fname,OutputWorkspace='w1',LoadMonitors='1');


if remove_background:
find_background('w1',bg_range);

#############################################################################################
# this section finds all the transmitted incident energies if you have not provided them
#if len(ei) == 0: -- not tested here -- should be unit test for that.
#ei = find_chopper_peaks('w1_monitors');
print 'Energies transmitted are:'
print (ei)

RenameWorkspace(InputWorkspace = 'w1',OutputWorkspace='w1_storage');
RenameWorkspace(InputWorkspace = 'w1_monitors',OutputWorkspace='w1_mon_storage');

#now loop around all energies for the run
result =[];
for ind,energy in enumerate(ei):
print float(energy)
(energybin,tbin,t_elastic) = find_binning_range(energy,ebin);
print " Rebinning will be performed in the range: ",energybin
# if we calculate more then one energy, initial workspace will be used more then once
if ind <len(ei)-1:
CloneWorkspace(InputWorkspace = 'w1_storage',OutputWorkspace='w1')
CloneWorkspace(InputWorkspace = 'w1_mon_storage',OutputWorkspace='w1_monitors')
else:
RenameWorkspace(InputWorkspace = 'w1_storage',OutputWorkspace='w1');
RenameWorkspace(InputWorkspace = 'w1_mon_storage',OutputWorkspace='w1_monitors');

if remove_background:
w1=Rebin(InputWorkspace='w1',OutputWorkspace='w1',Params=tbin,PreserveEvents=False)
Minus(LHSWorkspace='w1',RHSWorkspace='bg',OutputWorkspace='w1')


######################################################################
argi={};
argi['norm_method']='current'
argi['det_cal_file']='det_corrected7.nxs'
argi['detector_van_range']=[2,7]
argi['bkgd_range']=[bg_range[0],bg_range[1]]
argi['hardmaskOnly']=mask_file # diag does not work well on LET. At present only use a hard mask RIB has created
argi['check_background']=False;

# abs units
argi['sample_mass']=sampleMass;
argi['sample_rmm'] =sampleRMM;
argi['monovan_mapfile']=monovan_mapfile;
# ensure correct round-off procedure
argi['monovan_integr_range']=[round(ebin[0]*energy,4),round(ebin[2]*energy,4)]; # integration range of the vanadium
#MonoVanWSName = None;

# absolute unit reduction -- if you provided MonoVan run or relative units if monoVan is not present
out=dgreduce.arb_units("wb_wksp","w1",energy,energybin,mapping,MonoVanRun,**argi)
ws_name = 'LETreducedEi{0:2.1f}'.format(energy);
RenameWorkspace(InputWorkspace=out,OutputWorkspace=ws_name);
#SaveNXSPE(InputWorkspace=ws_name,Filename=ws_name+'.nxspe');



def validate(self):
self.tolerance = 1e-6
self.tolerance_is_reller=False
self.disableChecking.append('SpectraMap')
self.disableChecking.append('Instrument')

return "LETreducedEi3.4","LET14305_3_4mev.nxs","LETreducedEi8.0", "LET14305_8_0mev.nxs"

6 changes: 3 additions & 3 deletions SystemTests/AnalysisTests/ISISIndirectBayesTest.py
Expand Up @@ -304,7 +304,7 @@ def validate(self):
return 'irs26176_graphite002_QLr_CEfit_Workspace','ISISIndirectBayes_JumpCETest.nxs'

#=============================================================================
class JumpSSTest(stresstesting.MantidStressTest):
class JumpHallRossTest(stresstesting.MantidStressTest):

def runTest(self):
from IndirectJumpFit import JumpRun
Expand All @@ -316,11 +316,11 @@ def runTest(self):

path = sname+'.nxs' # path name for nxs file
LoadNexusProcessed(Filename=path, OutputWorkspace=sname)
JumpRun(sname,'SS',2,qrange[0],qrange[1],verbOp,plotOp,saveOp)
JumpRun(sname,'HallRoss',2,qrange[0],qrange[1],verbOp,plotOp,saveOp)

def validate(self):
self.tolerance = 1e-5
return 'irs26176_graphite002_QLr_SSfit_Workspace','ISISIndirectBayes_JumpSSTest.nxs'
return 'irs26176_graphite002_QLr_HallRossfit_Workspace','ISISIndirectBayes_JumpHallRossTest.nxs'

#=============================================================================
class JumpFickTest(stresstesting.MantidStressTest):
Expand Down
59 changes: 56 additions & 3 deletions SystemTests/AnalysisTests/ISISIndirectInelastic.py
Expand Up @@ -442,7 +442,62 @@ def __init__(self):

def get_reference_files(self):
return ["II.OSIRISDiagnostics.nxs"]



#==============================================================================
class ISISIndirectInelasticMoments(ISISIndirectInelasticBase):
'''A base class for the ISIS indirect inelastic Fury/FuryFit tests
The output of Elwin is usually used with MSDFit and so we plug one into
the other in this test.
'''
# Mark as an abstract class
__metaclass__ = ABCMeta

def _run(self):
'''Defines the workflow for the test'''

LoadNexus(self.input_workspace,
OutputWorkspace=self.input_workspace)

SofQWMoments(Sample=self.input_workspace, EnergyMin=self.e_min,
EnergyMax=self.e_max, Scale=self.scale,
Verbose=False, Plot=False, Save=False, OutputWorkspace=self.input_workspace + '_Moments')

self.result_names = [self.input_workspace + '_Moments']

def _validate_properties(self):
'''Check the object properties are in an expected state to continue'''
pass


#------------------------- OSIRIS tests ---------------------------------------
class OSIRISMoments(ISISIndirectInelasticMoments):

def __init__(self):
ISISIndirectInelasticMoments.__init__(self)
self.input_workspace = 'osi97935_graphite002_sqw.nxs'
self.e_min = -0.4
self.e_max = 0.4
self.scale = 1

def get_reference_files(self):
return ['II.OSIRISMoments.nxs']


#------------------------- IRIS tests -----------------------------------------
class IRISMoments(ISISIndirectInelasticMoments):

def __init__(self):
ISISIndirectInelasticMoments.__init__(self)
self.input_workspace = 'irs53664_graphite002_sqw.nxs'
self.e_min = -0.4
self.e_max = 0.4
self.scale = 1

def get_reference_files(self):
return ['II.IRISMoments.nxs']


#==============================================================================
class ISISIndirectInelasticElwinAndMSDFit(ISISIndirectInelasticBase):
Expand Down Expand Up @@ -731,5 +786,3 @@ def __init__(self):

def get_reference_files(self):
return ['II.IRISConvFitSeq.nxs']


3 changes: 2 additions & 1 deletion SystemTests/AnalysisTests/LoadLotsOfFiles.py
Expand Up @@ -56,7 +56,8 @@
'MANTID_FLAT_CELL.115',
'MaskLOQData.txt',
'DIRECTHAB.983',
'loq_batch_mode_reduction.csv'
'loq_batch_mode_reduction.csv',
'det_corrected7.nxs' # this file can be loaded by LoadDetectorInfo but I am not sure if generic loader should ever deal with it
]

EXPECTED_EXT = '.expected'
Expand Down
17 changes: 17 additions & 0 deletions SystemTests/AnalysisTests/LoadMuonNexusTest.py
@@ -0,0 +1,17 @@
import stresstesting
from mantid.simpleapi import *

class LoadMuonNexusTest(stresstesting.MantidStressTest):

def runTest(self):
# EMU03087 is an old data file produced by CONVERT_NEXUS from MCS binary files.
# Checked specifically because stores resulution (used to calculate FirstGoodData)
# as NX_FLOAT32 opposed to NX_INT32 in other Muon files.
loadResult = LoadMuonNexus(Filename = "EMU03087.nxs",
OutputWorkspace = "EMU03087")

firstGoodData = loadResult[3]
self.assertDelta(firstGoodData, 0.416, 0.0001)

def cleanup(self):
mtd.remove("EMU03087")
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3d33af3

Please sign in to comment.