1 | # Algorithm to start Jump fit programs |
---|
2 | from mantid.api import PythonAlgorithm, AlgorithmFactory |
---|
3 | from mantid.kernel import StringListValidator, StringMandatoryValidator |
---|
4 | from mantid.simpleapi import * |
---|
5 | from mantid import config, logger, mtd |
---|
6 | import os.path |
---|
7 | from IndirectBayes import JumpRun |
---|
8 | |
---|
9 | class JumpFit(PythonAlgorithm): |
---|
10 | |
---|
11 | def category(self): |
---|
12 | return "Workflow\\MIDAS;PythonAlgorithms" |
---|
13 | |
---|
14 | def PyInit(self): |
---|
15 | self.declareProperty(name='InputType',defaultValue='File',validator=StringListValidator(['File','Workspace']), doc='Origin of data input - File (*.nxs) or Workspace') |
---|
16 | self.declareProperty(name='Instrument',defaultValue='iris',validator=StringListValidator(['irs','iris','osi','osiris']), doc='Instrument') |
---|
17 | self.declareProperty(name='Analyser',defaultValue='graphite002',validator=StringListValidator(['graphite002','graphite004']), doc='Analyser & reflection') |
---|
18 | self.declareProperty(name='QLprogram',defaultValue='QLr',validator=StringListValidator(['QLr','QLd']), doc='QL output from Res or Data') |
---|
19 | self.declareProperty(name='Fit',defaultValue='CE',validator=StringListValidator(['CE','SS']), doc='Chudley-Elliott or Singwi-Sjolander') |
---|
20 | self.declareProperty(name='Width',defaultValue='width11',validator=StringListValidator(['width11','width21','width22']), doc='FullWidth type') |
---|
21 | self.declareProperty(name='SamNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Sample run number') |
---|
22 | self.declareProperty(name='CropQ',defaultValue=False, doc='Switch CropQ Off/On') |
---|
23 | self.declareProperty(name='Qmin',defaultValue='', doc='Qmin for cropping') |
---|
24 | self.declareProperty(name='Qmax',defaultValue='', doc='Qmax for cropping') |
---|
25 | self.declareProperty(name='Plot',defaultValue=False, doc='Switch Plot Off/On') |
---|
26 | self.declareProperty(name='Verbose',defaultValue=True, doc='Switch Verbose Off/On') |
---|
27 | self.declareProperty(name='Save',defaultValue=False, doc='Switch Save result to nxs file Off/On') |
---|
28 | |
---|
29 | def PyExec(self): |
---|
30 | |
---|
31 | self.log().information('Jump input') |
---|
32 | inType = self.getPropertyValue('InputType') |
---|
33 | prefix = self.getPropertyValue('Instrument') |
---|
34 | ana = self.getPropertyValue('Analyser') |
---|
35 | prog = self.getPropertyValue('QLprogram') |
---|
36 | jump = self.getPropertyValue('Fit') |
---|
37 | width = self.getPropertyValue('Width') |
---|
38 | if width == 'width11': |
---|
39 | index = 0 |
---|
40 | if width == 'width21': |
---|
41 | index = 2 |
---|
42 | if width == 'width22': |
---|
43 | index = 4 |
---|
44 | sam = self.getPropertyValue('SamNumber') |
---|
45 | |
---|
46 | samWS = prefix+sam+'_'+ana+'_'+prog |
---|
47 | cropOp = self.getProperty('CropQ').value |
---|
48 | verbOp = self.getProperty('Verbose').value |
---|
49 | plotOp = self.getProperty('Plot').value |
---|
50 | saveOp = self.getProperty('Save').value |
---|
51 | |
---|
52 | workdir = config['defaultsave.directory'] |
---|
53 | if inType == 'File': |
---|
54 | path = os.path.join(workdir, samWS+'_Workspace.nxs') # path name for nxs file |
---|
55 | LoadNexusProcessed(Filename=path, OutputWorkspace=samWS) |
---|
56 | message = 'Input from File : '+path |
---|
57 | else: |
---|
58 | message = 'Input from Workspace : '+samWS |
---|
59 | ExtractSingleSpectrum(InputWorkspace=samWS, OutputWorkspace=samWS, WorkspaceIndex=index) |
---|
60 | inGR = mtd[samWS].getRun() |
---|
61 | val = inGR.getLogData('Fit Program').value |
---|
62 | if verbOp: |
---|
63 | logger.notice(message) |
---|
64 | logger.notice('Fit program was : '+val) |
---|
65 | x = mtd[samWS].readX(0) |
---|
66 | xmin = x[0] |
---|
67 | xmax = x[len(x)-1] |
---|
68 | if cropOp: |
---|
69 | Crop = False |
---|
70 | qmin = self.getPropertyValue('Qmin') |
---|
71 | qmin = float(qmin) |
---|
72 | qmax = self.getPropertyValue('Qmax') |
---|
73 | qmax = float(qmax) |
---|
74 | if qmin > xmin: |
---|
75 | Crop = True |
---|
76 | if qmax < xmax: |
---|
77 | Crop = True |
---|
78 | if Crop: |
---|
79 | CropWorkspace(InputWorkspace=samWS, OutputWorkspace=samWS, |
---|
80 | XMin=qmin, XMax=qmax) |
---|
81 | if verbOp: |
---|
82 | logger.notice('Cropping from Q= ' + str(qmin) +' to '+ str(qmax)) |
---|
83 | JumpRun(samWS,jump,verbOp,plotOp,saveOp) |
---|
84 | |
---|
85 | AlgorithmFactory.subscribe(JumpFit) # Register algorithm with Mantid |
---|