-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4867 - Addition of several PyAlgs from Spencer.
- Loading branch information
1 parent
3441a70
commit f3e1daa
Showing
5 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/ILLines.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Algorithm to start Bayes programs | ||
from MantidFramework import * | ||
from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform | ||
|
||
if is_supported_f2py_platform(): | ||
import IndirectBayes as Main | ||
|
||
class ILLines(PythonAlgorithm): | ||
|
||
def category(self): | ||
return "Workflow\\MIDAS;PythonAlgorithms" | ||
|
||
def PyInit(self): | ||
self.declareProperty(Name='InputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of data input - File (*.nxs) or Workspace') | ||
self.declareProperty(Name='Instrument',DefaultValue='IN10',Validator=ListValidator(['IN10','IN16']),Description = 'Instrument') | ||
self.declareProperty(Name='Program',DefaultValue='QL',Validator=ListValidator(['QL','QSe']),Description = 'Name of program to run') | ||
self.declareProperty(Name='SamNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') | ||
self.declareProperty(Name='ResInputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of res input - File (*_res.nxs) or Workspace') | ||
self.declareProperty(Name='ResType',DefaultValue='Res',Validator=ListValidator(['Res','Data']),Description = 'Format of Resolution file') | ||
self.declareProperty(Name='ResNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Resolution run number') | ||
self.declareProperty(Name='BackgroundOption',DefaultValue='Sloping',Validator=ListValidator(['Sloping','Flat','Zero']),Description = 'Form of background to fit') | ||
self.declareProperty(Name='ElasticOption',DefaultValue=True,Description = 'Include elastic peak in fit') | ||
self.declareProperty(Name='FixWidth',DefaultValue=False,Description = 'Fix one of the widths') | ||
self.declareProperty(Name='WidthFile', DefaultValue='',Description = 'Name of file containing fixed width values') | ||
self.declareProperty(Name='ResNorm',DefaultValue=False,Description = 'Use ResNorm output file') | ||
self.declareProperty(Name='ResNormNumber', DefaultValue='',Description = 'Name of file containing fixed width values') | ||
self.declareProperty(Name='EnergyMin', DefaultValue=-0.5,Description = 'Minimum energy for fit. Default=-0.5') | ||
self.declareProperty(Name='EnergyMax', DefaultValue=0.5,Description = 'Maximum energy for fit. Default=0.5') | ||
self.declareProperty(Name='SamBinning', DefaultValue=1,Description = 'Binning value (integer) for sample. Default=1') | ||
self.declareProperty(Name='ResBinning', DefaultValue=1,Description = 'Binning value (integer) for resolution - QLd only. Default=1') | ||
self.declareProperty(Name='Plot',DefaultValue='None',Validator=ListValidator(['None','ProbBeta','Intensity','FwHm','Fit','All']),Description = 'Plot options') | ||
self.declareProperty(Name='Verbose',DefaultValue=True,Description = 'Switch Verbose Off/On') | ||
self.declareProperty(Name='Save',DefaultValue=False,Description = 'Switch Save result to nxs file Off/On') | ||
|
||
def PyExec(self): | ||
run_f2py_compatibility_test() | ||
|
||
self.log().information('ILLines input') | ||
inType = self.getPropertyValue('InputType') | ||
instr = self.getPropertyValue('Instrument') | ||
prog = self.getPropertyValue('Program') | ||
sam = self.getPropertyValue('SamNumber') | ||
rinType = self.getPropertyValue('ResInputType') | ||
rtype = self.getPropertyValue('ResType') | ||
res = self.getPropertyValue('ResNumber') | ||
elastic = self.getProperty('ElasticOption') | ||
bgd = self.getPropertyValue('BackgroundOption') | ||
width = self.getProperty('FixWidth') | ||
wfile = self.getPropertyValue('WidthFile') | ||
resnorm = self.getProperty('ResNorm') | ||
resn = self.getPropertyValue('ResNormNumber') | ||
emin = self.getPropertyValue('EnergyMin') | ||
emax = self.getPropertyValue('EnergyMax') | ||
nbin = self.getPropertyValue('SamBinning') | ||
nrbin = self.getPropertyValue('ResBinning') | ||
nbins = [nbin, nrbin] | ||
|
||
sname = instr+'_'+sam | ||
rname = instr+'_'+res | ||
rsname = instr+resn | ||
erange = [emin, emax] | ||
if elastic: | ||
o_el = 1 | ||
else: | ||
o_el = 0 | ||
if bgd == 'Sloping': | ||
o_bgd = 2 | ||
if bgd == 'Flat': | ||
o_bgd = 1 | ||
if bgd == 'Zero': | ||
o_bgd = 0 | ||
if width: | ||
o_w1 = 1 | ||
else: | ||
o_w1 = 0 | ||
if resnorm: | ||
o_res = 1 | ||
else: | ||
o_res = 0 | ||
fitOp = [o_el, o_bgd, o_w1, o_res] | ||
verbOp = self.getProperty('Verbose') | ||
plotOp = self.getPropertyValue('Plot') | ||
saveOp = self.getProperty('Save') | ||
Main.QLStart(prog,inType,sname,rinType,rname,rtype,rsname,erange,nbins,fitOp,wfile,verbOp,plotOp,saveOp) | ||
#def QLStart(program,ana,samWS,resWS,rtype,rsname,erange,nbins,fitOp,wfile,Verbose,Plot,Save): | ||
|
||
mantid.registerPyAlgorithm(ILLines()) # Register algorithm with Mantid |
47 changes: 47 additions & 0 deletions
47
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/JumpFit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Algorithm to start Jump fit programs | ||
from MantidFramework import * | ||
from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform | ||
|
||
if is_supported_f2py_platform(): | ||
import IndirectBayes as Main | ||
|
||
class JumpFit(PythonAlgorithm): | ||
|
||
def category(self): | ||
return "Workflow\\MIDAS;PythonAlgorithms" | ||
|
||
def PyInit(self): | ||
self.declareProperty(Name='InputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of data input - File (*.nxs) or Workspace') | ||
self.declareProperty(Name='Instrument',DefaultValue='IRIS',Validator=ListValidator(['IRIS','OSIRIS']),Description = 'Instrument name') | ||
self.declareProperty(Name='Analyser',DefaultValue='graphite002',Validator=ListValidator(['graphite002','graphite004']),Description = 'Analyser & reflection') | ||
self.declareProperty(Name='QLprogram',DefaultValue='QLr',Validator=ListValidator(['QLr','QLd']),Description = 'QL output from Res or Data') | ||
self.declareProperty(Name='Fit',DefaultValue='CE',Validator=ListValidator(['CE','SS']),Description = 'Chudley-Elliott or Singwi-Sjolander') | ||
self.declareProperty(Name='Width',DefaultValue='FW11',Validator=ListValidator(['FW11','FW21','FW22']),Description = 'FullWidth type') | ||
self.declareProperty(Name='SamNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') | ||
self.declareProperty(Name='Plot',DefaultValue=False,Description = 'Switch Plot Off/On') | ||
self.declareProperty(Name='Verbose',DefaultValue=True,Description = 'Switch Verbose Off/On') | ||
self.declareProperty(Name='Save',DefaultValue=False,Description = 'Switch Save result to nxs file Off/On') | ||
|
||
def PyExec(self): | ||
run_f2py_compatibility_test() | ||
|
||
self.log().information('Jump input') | ||
inType = self.getPropertyValue('InputType') | ||
instr = self.getPropertyValue('Instrument') | ||
if instr == 'IRIS': | ||
prefix = 'irs' | ||
if instr == 'OSIRIS': | ||
prefix = 'osi' | ||
ana = self.getPropertyValue('Analyser') | ||
prog = self.getPropertyValue('QLprogram') | ||
jump = self.getPropertyValue('Fit') | ||
fw = self.getPropertyValue('Width') | ||
sam = self.getPropertyValue('SamNumber') | ||
|
||
sname = prefix+sam+'_'+ana+'_'+prog | ||
verbOp = self.getProperty('Verbose') | ||
plotOp = self.getProperty('Plot') | ||
saveOp = self.getProperty('Save') | ||
Main.JumpStart(inType,sname,jump,prog,fw,verbOp,plotOp,saveOp) | ||
|
||
mantid.registerPyAlgorithm(JumpFit()) # Register algorithm with Mantid |
40 changes: 40 additions & 0 deletions
40
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/Symmetrise.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Algorithm to start Symmetrise | ||
from MantidFramework import * | ||
import IndirectSymm as Main | ||
|
||
class Symmetrise(PythonAlgorithm): | ||
|
||
def category(self): | ||
return "Workflow\\MIDAS;PythonAlgorithms" | ||
|
||
def PyInit(self): | ||
self.declareProperty(Name='InputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of data input - File (_red.nxs) or Workspace') | ||
self.declareProperty(Name='Instrument',DefaultValue='IRIS',Validator=ListValidator(['IRIS','OSIRIS']),Description = 'Instrument') | ||
self.declareProperty(Name='Analyser',DefaultValue='graphite002',Validator=ListValidator(['graphite002','graphite004']),Description = 'Analyser & reflection') | ||
self.declareProperty(Name='SamNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') | ||
self.declareProperty(Name='Xcut',DefaultValue='',Validator=MandatoryValidator(),Description = 'X cutoff value') | ||
self.declareProperty('Verbose',DefaultValue=True,Description = 'Switch Verbose Off/On') | ||
self.declareProperty('Plot',DefaultValue=True,Description = 'Switch Plot Off/On') | ||
self.declareProperty('Save',DefaultValue=False,Description = 'Switch Save result to nxs file Off/On') | ||
|
||
def PyExec(self): | ||
|
||
self.log().information('Symmetrise') | ||
inType = self.getPropertyValue('InputType') | ||
instr = self.getPropertyValue('Instrument') | ||
if instr == 'IRIS': | ||
prefix = 'irs' | ||
if instr == 'OSIRIS': | ||
prefix = 'osi' | ||
ana = self.getPropertyValue('Analyser') | ||
sn = self.getPropertyValue('SamNumber') | ||
sam = prefix+sn+'_'+ana+'_red' | ||
cut = self.getPropertyValue('Xcut') | ||
cut = float(cut) | ||
|
||
verbOp = self.getProperty('Verbose') | ||
plotOp = self.getProperty('Plot') | ||
saveOp = self.getProperty('Save') | ||
Main.SymmStart(inType,sam,cut,verbOp,plotOp,saveOp) | ||
|
||
mantid.registerPyAlgorithm(Symmetrise()) # Register algorithm with Mantid |
43 changes: 43 additions & 0 deletions
43
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/iFudge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Algorithm to start Bayes programs | ||
from MantidFramework import * | ||
from mantid.simpleapi import * | ||
from mantid import config, logger, mtd | ||
|
||
class iFudge(PythonAlgorithm): | ||
|
||
def category(self): | ||
return "Workflow\\MIDAS;PythonAlgorithms" | ||
|
||
def PyInit(self): | ||
self.declareProperty(Name='InputType',DefaultValue='File',Validator=ListValidator(['File','Workspace']),Description = 'Origin of data input - File (_red.nxs) or Workspace') | ||
self.declareProperty(Name='Instrument',DefaultValue='IRIS',Validator=ListValidator(['IRIS','OSIRIS']),Description = 'Instrument') | ||
self.declareProperty(Name='Analyser',DefaultValue='graphite002',Validator=ListValidator(['graphite002','graphite004']),Description = 'Analyser & reflection') | ||
self.declareProperty(Name='InNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') | ||
self.declareProperty(Name='MultiplyBy',DefaultValue='',Validator=MandatoryValidator(),Description = 'Multiplicative scale factor') | ||
self.declareProperty(Name='OutNumber',DefaultValue='',Validator=MandatoryValidator(),Description = 'Sample run number') | ||
|
||
def PyExec(self): | ||
|
||
self.log().information('Scale input') | ||
workdir = config['defaultsave.directory'] | ||
inType = self.getPropertyValue('InputType') | ||
instr = self.getPropertyValue('Instrument') | ||
if instr == 'IRIS': | ||
prefix = 'irs' | ||
if instr == 'OSIRIS': | ||
prefix = 'osi' | ||
ana = self.getPropertyValue('Analyser') | ||
InNumb = self.getPropertyValue('InNumber') | ||
inWS = prefix+InNumb+'_'+ana+'_red' | ||
factor = self.getPropertyValue('MultiplyBy') | ||
if inType == 'File': | ||
spath = os.path.join(workdir, inWS+'.nxs') # path name for sample nxs file | ||
logger.notice('Input from File : '+spath) | ||
LoadNexusProcessed(Filename=spath, OutputWorkspace=inWS) | ||
else: | ||
logger.notice('Input from Workspace : '+inWS) | ||
OutNumb = self.getPropertyValue('OutNumber') | ||
outWS = prefix+OutNumb+'_'+ana+'_red' | ||
Scale(InputWorkspace=inWS, OutputWorkspace=outWS, Factor=float(factor), Operation='Multiply') | ||
|
||
mantid.registerPyAlgorithm(iFudge()) # Register algorithm with Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# SYMMetrise | ||
# | ||
from mantid.simpleapi import * | ||
from mantid import config, logger, mtd | ||
from IndirectCommon import * | ||
from IndirectImport import import_mantidplot | ||
import sys, platform, math, os.path, numpy as np | ||
mp = import_mantidplot() | ||
|
||
def SymmRun(sample,cut,Verbose,Plot,Save): | ||
workdir = config['defaultsave.directory'] | ||
symWS = sample[:-3] + 'sym' | ||
hist = mtd[sample].getNumberHistograms() # no. of hist/groups in sam | ||
Xin = mtd[sample].readX(0) | ||
npt = len(Xin)-1 | ||
delx = Xin[1]-Xin[0] | ||
for n in range(0,npt): | ||
x = Xin[n]-cut | ||
if math.fabs(x) < delx: | ||
ineg = n | ||
for n in range(0,npt): | ||
x = Xin[n]+Xin[ineg] | ||
if math.fabs(x) < delx: | ||
ipos = n | ||
ncut = npt-ipos+1 | ||
if Verbose: | ||
logger.notice('No. points = '+str(npt)) | ||
logger.notice('Negative : at i ='+str(ineg)+' ; x = '+str(Xin[ineg])) | ||
logger.notice('Positive : at i ='+str(ipos)+' ; x = '+str(Xin[ipos])) | ||
logger.notice('Cut points = '+str(ncut)) | ||
for m in range(0,hist): | ||
Xin = mtd[sample].readX(m) | ||
Yin = mtd[sample].readY(m) | ||
Ein = mtd[sample].readE(m) | ||
Xout = [] | ||
Yout = [] | ||
Eout = [] | ||
for n in range(0,ncut): | ||
icut = npt-n-1 | ||
Xout.append(-Xin[icut]) | ||
Yout.append(Yin[icut]) | ||
Eout.append(Ein[icut]) | ||
for n in range(ncut,npt): | ||
Xout.append(Xin[n]) | ||
Yout.append(Yin[n]) | ||
Eout.append(Ein[n]) | ||
if m == 0: | ||
CreateWorkspace(OutputWorkspace=symWS, DataX=Xout, DataY=Yout, DataE=Eout, | ||
Nspec=1, UnitX='DeltaE') | ||
else: | ||
CreateWorkspace(OutputWorkspace='__tmp', DataX=Xout, DataY=Yout, DataE=Eout, | ||
Nspec=1, UnitX='DeltaE') | ||
ConjoinWorkspaces(InputWorkspace1=symWS, InputWorkspace2='__tmp',CheckOverlapping=False) | ||
# Nspec=nt, UnitX='MomentumTransfer', VerticalAxisUnit='Text', VerticalAxisValues='Taxis') | ||
# start output | ||
if Save: | ||
path = os.path.join(workdir,symWS+'.nxs') | ||
SaveNexusProcessed(InputWorkspace=symWS, Filename=path) | ||
if Verbose: | ||
logger.notice('Output file : ' + path) | ||
if Plot: | ||
plotSymm('','',Plot) | ||
|
||
def SymmStart(inType,sname,cut,Verbose,Plot,Save): | ||
StartTime('Symmetrise') | ||
workdir = config['defaultsave.directory'] | ||
if inType == 'File': | ||
spath = os.path.join(workdir, sname+'.nxs') # path name for sample nxs file | ||
LoadNexusProcessed(FileName=spath, OutputWorkspace=sname) | ||
message = 'Input from File : '+spath | ||
else: | ||
message = 'Input from Workspace : '+sname | ||
if Verbose: | ||
logger.notice(message) | ||
SymmRun(sname,cut,Verbose,Plot,Save) | ||
EndTime('Symmetrise') | ||
|
||
def plotSymm(inWS,spec_list,Plot): | ||
if (Plot == 'Totals' or Plot == 'All'): | ||
tot_plot=mp.plotSpectrum(inWS+'_Totals',spec_list) | ||
if (Plot == 'Scat1' or Plot == 'All'): | ||
mp.importMatrixWorkspace(inWS+'_1').plotGraph2D() |