Ticket #10259: calibration_energy.py

File calibration_energy.py, 1.6 KB (added by Dan Nixon, 6 years ago)
Line 
1from mantid import config, logger, mtd
2# this section not needed - ws already there when gui is opened
3instr = 'IRIS'
4ana = 'graphite'
5refl = '002'
6mt_ws = '_empty'+instr
7idf_dir = config['instrumentDefinition.directory']
8idf = idf_dir + instr + '_Definition.xml'
9LoadEmptyInstrument(Filename=idf, OutputWorkspace=mt_ws)
10ipf = idf_dir + instr + '_' + ana + '_' + refl + '_Parameters.xml'
11LoadParameterFile(Workspace=mt_ws, Filename=ipf)
12# except for mt_ws
13instrument = mtd[mt_ws].getInstrument()
14analyser = instrument.getStringParameter('analyser')[0]
15resolution = instrument.getComponentByName(analyser).getNumberParameter('resolution')[0]
16x = [-6*resolution, -5*resolution, -2*resolution, 0.0, 2*resolution]
17# BgdMin, BgdMax, PeakMin, PeakZero, PeakMax
18y = [1,2,3,4]
19e = [0,0,0,0]
20CreateWorkspace(OutputWorkspace='energy', DataX=x, DataY=y, DataE=e,
21    Nspec=1, UnitX='DeltaE')
22ConvertToHistogram(InputWorkspace='energy', OutputWorkspace='energy')
23LoadInstrument(Workspace='energy', InstrumentName=instr)
24LoadParameterFile(Workspace='energy', Filename=ipf)
25efixed = mtd['energy'].getInstrument().getNumberParameter('efixed-val')[0]
26print 'efixed = '+str(efixed)
27# Reset det IDs
28spectrum = mtd['energy'].getSpectrum(0)
29spectrum.setSpectrumNo(3)
30spectrum.clearDetectorIDs()
31spectrum.addDetectorID(3)
32ConvertUnits(InputWorkspace='energy', OutputWorkspace='tof', Target='TOF',
33    EMode='Indirect', EFixed=efixed)
34tof = mtd['tof'].readX(0)
35# energy increasing on converting becomes time decreasing
36# so the parameter order is reversed
37# these are the default values
38PeakMin = tof[0]
39PeakMax = tof[2]
40BgdMin = tof[3]
41BgdMax = tof[4]