| 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 JumpConvFit(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='SamNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Sample run number') |
|---|
| 18 | self.declareProperty(name='Analyser',defaultValue='graphite002',validator=StringListValidator(['graphite002','graphite004']), doc='Analyser & reflection') |
|---|
| 19 | self.declareProperty(name='Function',defaultValue='',validator=StringMandatoryValidator(),doc = 'Fit function code') |
|---|
| 20 | self.declareProperty(name='First spectrum',defaultValue='',validator=StringMandatoryValidator(),doc = 'First spectrum number') |
|---|
| 21 | self.declareProperty(name='Last spectrum',defaultValue='',validator=StringMandatoryValidator(),doc = 'Last spectrum number') |
|---|
| 22 | self.declareProperty(name='Fit',defaultValue='CE',validator=StringListValidator(['CE','SS']), doc='Chudley-Elliott or Singwi-Sjolander') |
|---|
| 23 | self.declareProperty(name='CropQ',defaultValue=False, doc='Switch CropQ Off/On') |
|---|
| 24 | self.declareProperty(name='Qmin',defaultValue='', doc='Qmin for cropping') |
|---|
| 25 | self.declareProperty(name='Qmax',defaultValue='', doc='Qmax for cropping') |
|---|
| 26 | self.declareProperty(name='Plot',defaultValue=False, doc='Switch Plot Off/On') |
|---|
| 27 | self.declareProperty(name='Verbose',defaultValue=True, doc='Switch Verbose Off/On') |
|---|
| 28 | self.declareProperty(name='Save',defaultValue=False, doc='Switch Save result to nxs file Off/On') |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | def PyExec(self): |
|---|
| 32 | |
|---|
| 33 | self.log().information('Jump input') |
|---|
| 34 | inType = self.getPropertyValue('InputType') |
|---|
| 35 | prefix = self.getPropertyValue('Instrument') |
|---|
| 36 | sam = self.getPropertyValue('SamNumber') |
|---|
| 37 | ana = self.getPropertyValue('Analyser') |
|---|
| 38 | func = self.getPropertyValue('Function') |
|---|
| 39 | first = self.getPropertyValue('First spectrum') |
|---|
| 40 | last = self.getPropertyValue('Last spectrum') |
|---|
| 41 | jump = self.getPropertyValue('Fit') |
|---|
| 42 | |
|---|
| 43 | samWS = prefix+sam+'_'+ana+'_conv_'+func+'_s'+first+'_to_'+last |
|---|
| 44 | prog = 'conv' |
|---|
| 45 | cropOp = self.getProperty('CropQ').value |
|---|
| 46 | verbOp = self.getProperty('Verbose').value |
|---|
| 47 | plotOp = self.getProperty('Plot').value |
|---|
| 48 | saveOp = self.getProperty('Save').value |
|---|
| 49 | |
|---|
| 50 | workdir = config['defaultsave.directory'] |
|---|
| 51 | if inType == 'File': |
|---|
| 52 | path = os.path.join(workdir, samWS+'_Workspace.nxs') # path name for nxs file |
|---|
| 53 | LoadNexus(Filename=path, OutputWorkspace=samWS) |
|---|
| 54 | message = 'Input from File : '+path |
|---|
| 55 | else: |
|---|
| 56 | message = 'Input from Workspace : '+samWS |
|---|
| 57 | ExtractSingleSpectrum(InputWorkspace=samWS, OutputWorkspace=samWS, WorkspaceIndex=1) |
|---|
| 58 | inGR = mtd[samWS].getRun() |
|---|
| 59 | val = inGR.getLogData('Fit Program').value |
|---|
| 60 | if verbOp: |
|---|
| 61 | logger.notice(message) |
|---|
| 62 | logger.notice('Fit program was : '+val) |
|---|
| 63 | x = mtd[samWS].readX(0) |
|---|
| 64 | xmin = x[0] |
|---|
| 65 | xmax = x[len(x)-1] |
|---|
| 66 | if cropOp: |
|---|
| 67 | Crop = False |
|---|
| 68 | qmin = self.getPropertyValue('Qmin') |
|---|
| 69 | qmin = float(qmin) |
|---|
| 70 | qmax = self.getPropertyValue('Qmax') |
|---|
| 71 | qmax = float(qmax) |
|---|
| 72 | if qmin > xmin: |
|---|
| 73 | Crop = True |
|---|
| 74 | if qmax < xmax: |
|---|
| 75 | Crop = True |
|---|
| 76 | if Crop: |
|---|
| 77 | CropWorkspace(InputWorkspace=samWS, OutputWorkspace=samWS, |
|---|
| 78 | XMin=qmin, XMax=qmax) |
|---|
| 79 | if verbOp: |
|---|
| 80 | logger.notice('Cropping from Q= ' + str(qmin) +' to '+ str(qmax)) |
|---|
| 81 | JumpRun(samWS,jump,verbOp,plotOp,saveOp) |
|---|
| 82 | |
|---|
| 83 | AlgorithmFactory.subscribe(JumpConvFit) # Register algorithm with Mantid |
|---|