1 | # Algorithm to start Bayes programs |
---|
2 | from mantid.simpleapi import * |
---|
3 | from mantid.kernel import StringListValidator, StringMandatoryValidator |
---|
4 | from mantid.api import PythonAlgorithm, AlgorithmFactory |
---|
5 | from mantid import config |
---|
6 | import os |
---|
7 | |
---|
8 | class QLwater(PythonAlgorithm): |
---|
9 | |
---|
10 | def category(self): |
---|
11 | return "Workflow\\MIDAS;PythonAlgorithms" |
---|
12 | |
---|
13 | def PyInit(self): |
---|
14 | self.declareProperty(name='InputType',defaultValue='File',validator=StringListValidator(['File','Workspace']), doc='Origin of data input - File (*.nxs) or Workspace') |
---|
15 | self.declareProperty(name='Instrument',defaultValue='iris',validator=StringListValidator(['irs','iris','osi','osiris']), doc='Instrument') |
---|
16 | self.declareProperty(name='Analyser',defaultValue='graphite002',validator=StringListValidator(['graphite002','graphite004']), doc='Analyser & reflection') |
---|
17 | self.declareProperty(name='SamNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Sample run number') |
---|
18 | self.declareProperty(name='ResInputType',defaultValue='File',validator=StringListValidator(['File','Workspace']), doc='Origin of res input - File (*_res.nxs) or Workspace') |
---|
19 | self.declareProperty(name='ResNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Resolution run number') |
---|
20 | self.declareProperty(name='BackgroundOption',defaultValue='Sloping',validator=StringListValidator(['Sloping','Flat','Zero']), doc='Form of background to fit') |
---|
21 | self.declareProperty(name='ElasticOption',defaultValue=True, doc='Include elastic peak in fit') |
---|
22 | self.declareProperty(name='ResNorm',defaultValue=False, doc='Use ResNorm output file') |
---|
23 | self.declareProperty(name='ResNormNumber', defaultValue='', doc='Name of file containing fixed width values') |
---|
24 | self.declareProperty(name='EnergyMin', defaultValue=-0.5, doc='Minimum energy for fit. Default=-0.5') |
---|
25 | self.declareProperty(name='EnergyMax', defaultValue=0.5, doc='Maximum energy for fit. Default=0.5') |
---|
26 | self.declareProperty(name='SamBinning', defaultValue=1, doc='Binning value (integer) for sample. Default=1') |
---|
27 | self.declareProperty(name='ResBinning', defaultValue=1, doc='Binning value (integer) for resolution - QLd only. Default=1') |
---|
28 | self.declareProperty(name='Sequence',defaultValue=True, doc='Switch Sequence Off/On') |
---|
29 | self.declareProperty(name='Plot',defaultValue='None',validator=StringListValidator(['None','ProbBeta','Intensity','FwHm','Fit','All']), doc='Plot options') |
---|
30 | self.declareProperty(name='Verbose',defaultValue=True, doc='Switch Verbose Off/On') |
---|
31 | self.declareProperty(name='Save',defaultValue=False, doc='Switch Save result to nxs file Off/On') |
---|
32 | |
---|
33 | def PyExec(self): |
---|
34 | from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform |
---|
35 | |
---|
36 | if is_supported_f2py_platform(): |
---|
37 | import IndirectBayes as Main |
---|
38 | |
---|
39 | run_f2py_compatibility_test() |
---|
40 | |
---|
41 | self.log().information('QLines input') |
---|
42 | inType = self.getPropertyValue('InputType') |
---|
43 | prefix = self.getPropertyValue('Instrument') |
---|
44 | ana = self.getPropertyValue('Analyser') |
---|
45 | prog = 'QLwat' |
---|
46 | sam = self.getPropertyValue('SamNumber') |
---|
47 | rinType = self.getPropertyValue('ResInputType') |
---|
48 | rtype = 'Res' |
---|
49 | res = self.getPropertyValue('ResNumber') |
---|
50 | elastic = self.getProperty('ElasticOption').value |
---|
51 | bgd = self.getPropertyValue('BackgroundOption') |
---|
52 | width = False |
---|
53 | wfile = '' |
---|
54 | resnorm = self.getProperty('ResNorm').value |
---|
55 | resn = self.getPropertyValue('ResNormNumber') |
---|
56 | emin = self.getPropertyValue('EnergyMin') |
---|
57 | emax = self.getPropertyValue('EnergyMax') |
---|
58 | nbin = self.getPropertyValue('SamBinning') |
---|
59 | nrbin = self.getPropertyValue('ResBinning') |
---|
60 | nbins = [nbin, nrbin] |
---|
61 | |
---|
62 | if rtype == 'Res': |
---|
63 | rext = 'res' |
---|
64 | if rtype == 'Data': |
---|
65 | rext = 'red' |
---|
66 | sname = prefix+sam+'_'+ana + '_red' |
---|
67 | rname = prefix+res+'_'+ana + '_' + rext |
---|
68 | rsname = prefix+resn+'_'+ana + '_ResNorm_Paras' |
---|
69 | erange = [float(emin), float(emax)] |
---|
70 | |
---|
71 | fitOp = [elastic, bgd, width, resnorm] |
---|
72 | loopOp = self.getProperty('Sequence').value |
---|
73 | verbOp = self.getProperty('Verbose').value |
---|
74 | plotOp = self.getPropertyValue('Plot') |
---|
75 | saveOp = self.getProperty('Save').value |
---|
76 | |
---|
77 | workdir = config['defaultsave.directory'] |
---|
78 | if inType == 'File': |
---|
79 | spath = os.path.join(workdir, sname+'.nxs') # path name for sample nxs file |
---|
80 | LoadNexusProcessed(Filename=spath, OutputWorkspace=sname) |
---|
81 | Smessage = 'Sample from File : '+spath |
---|
82 | else: |
---|
83 | Smessage = 'Sample from Workspace : '+sname |
---|
84 | if rinType == 'File': |
---|
85 | rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file |
---|
86 | LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) |
---|
87 | Rmessage = 'Resolution from File : '+rpath |
---|
88 | else: |
---|
89 | Rmessage = 'Resolution from Workspace : '+rname |
---|
90 | if verbOp: |
---|
91 | logger.notice(Smessage) |
---|
92 | logger.notice(Rmessage) |
---|
93 | if fitOp[3] == 1: |
---|
94 | path = os.path.join(workdir, rsname+'.nxs') # path name for resnnrm nxs file |
---|
95 | LoadNexusProcessed(Filename=path, OutputWorkspace='ResNorm') |
---|
96 | Main.QLRun(prog,sname,rname,rsname,erange,nbins,fitOp,wfile,loopOp,verbOp,plotOp,saveOp) |
---|
97 | |
---|
98 | AlgorithmFactory.subscribe(QLwater) # Register algorithm with Mantid |
---|