Skip to content

Commit

Permalink
Refs #5421 Updates to Quest and QLRun.
Browse files Browse the repository at this point in the history
Also swapped using SaveNexus to SaveProcessedNexus.
  • Loading branch information
Samuel Jackson committed Sep 24, 2013
1 parent 2688eec commit 3f819a7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 49 deletions.
24 changes: 7 additions & 17 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,15 @@ namespace MantidQt
// in some places
QString verbose("False");
QString save("False");
QString elasticPeak("0");
QString elasticPeak("False");
QString sequence("False");

QString fixedWidth("0");
QString fixedWidth("False");
QString fixedWidthFile("");

QString useResNorm("0");
QString useResNorm("False");
QString resNormFile("");

QString background("0");

QString pyInput =
"from IndirectBayes import QLRun\n";

Expand All @@ -122,28 +120,20 @@ namespace MantidQt
}

// Collect input from fit options section
QString backgroundTxt = m_uiForm.cbBackground->currentText();
if(backgroundTxt == "Sloping")
{
background = "2";
}
else if( backgroundTxt == "Flat")
{
background = "1";
}
QString background = m_uiForm.cbBackground->currentText();

if(m_uiForm.chkElasticPeak->isChecked()) { elasticPeak = "1"; }
if(m_uiForm.chkElasticPeak->isChecked()) { elasticPeak = "True"; }
if(m_uiForm.chkSequentialFit->isChecked()) { sequence = "True"; }

if(m_uiForm.chkFixWidth->isChecked())
{
fixedWidth = "1";
fixedWidth = "True";
fixedWidthFile = m_uiForm.mwFixWidthDat->getFirstFilename();
}

if(m_uiForm.chkUseResNorm->isChecked())
{
useResNorm = "1";
useResNorm = "True";
resNormFile = m_uiForm.dsResNorm->getCurrentDataName();
}

Expand Down
17 changes: 4 additions & 13 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ namespace MantidQt
QString save("False");
QString verbose("False");

QString elasticPeak("0");
QString background("0");
QString elasticPeak("False");
QString sequence("False");

QString pyInput =
Expand All @@ -88,17 +87,9 @@ namespace MantidQt
QString resName = m_uiForm.dsResolution->getCurrentDataName();

// Collect input from options section
QString backgroundTxt = m_uiForm.cbBackground->currentText();
if(backgroundTxt == "Sloping")
{
background = "2";
}
else if( backgroundTxt == "Flat")
{
background = "1";
}

if(m_uiForm.chkElasticPeak->isChecked()) { elasticPeak = "1"; }
QString background = m_uiForm.cbBackground->currentText();

if(m_uiForm.chkElasticPeak->isChecked()) { elasticPeak = "True"; }
if(m_uiForm.chkSequentialFit->isChecked()) { sequence = "True"; }

QString fitOps = "[" + elasticPeak + ", " + background + ", 0, 0]";
Expand Down
81 changes: 62 additions & 19 deletions Code/Mantid/scripts/Inelastic/IndirectBayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def GetXYE(inWS,n,array_len):
E=PadArray(Ein,array_len)
return N,X,Y,E

def ReadNormFile(o_res,nsam,resnormWS,Verbose): # get norm & scale values
if o_res == 1: # use ResNorm file option=o_res
def ReadNormFile(resnorm,nsam,resnormWS,Verbose): # get norm & scale values
if resnorm == 1: # use ResNorm file
if Verbose:
logger.notice('ResNorm file is ' + resnormWS)
dtnorm = mtd[resnormWS+'_Intensity'].readX(0)
Expand Down Expand Up @@ -80,9 +80,9 @@ def ReadNormFile(o_res,nsam,resnormWS,Verbose): # get norm & scale va
xsc=PadArray(xscale,51)
return dtn,xsc

def ReadWidthFile(op_w1,wfile,ngrp,Verbose): # reads width file ASCII
def ReadWidthFile(width,wfile,ngrp,Verbose): # reads width file ASCII
workdir = config['defaultsave.directory']
if op_w1 == 1: # use width1 data option=o_w1
if width: # use width1 data option=o_w1
if Verbose:
w_path = os.path.join(workdir, wfile) # path name for nxs file
logger.notice('Width file is ' + w_path)
Expand Down Expand Up @@ -128,7 +128,7 @@ def CheckBinning(nbins):
return nbin,nrbin

# QLines programs
def QLRun(program,samWS,resWS,resnormWS,erange,nbins,fitOp,wfile,Loop,Verbose=False,Plot='None',Save=False):
def QLRun(program,samWS,resWS,resnormWS,erange,nbins,Fit,wfile,Loop,Verbose=False,Plot='None',Save=False):
StartTime(program)
workdir = config['defaultsave.directory']
facility = config['default.facility']
Expand All @@ -146,6 +146,32 @@ def QLRun(program,samWS,resWS,resnormWS,erange,nbins,fitOp,wfile,Loop,Verbose=Fa
if Loop != True:
nsam = 1
nres,ntr = CheckHistZero(resWS)
if Fit[0]:
elastic = True
o_el = 1
else:
elastic = False
o_el = 0
if Fit[1] == 'Sloping':
o_bgd = 2
if Fit[1] == 'Flat':
o_bgd = 1
if Fit[1] == 'Zero':
o_bgd = 0
background = Fit[1]
if Fit[2]:
width = True
o_w1 = 1
else:
width = False
o_w1 = 0
if Fit[3]:
resnorm = True
o_res = 1
else:
resnorm = False
o_res = 0
fitOp = [o_el, o_bgd, o_w1, o_res]
if program == 'QL':
if nres == 1:
prog = 'QLr' # res file
Expand All @@ -163,8 +189,8 @@ def QLRun(program,samWS,resWS,resnormWS,erange,nbins,fitOp,wfile,Loop,Verbose=Fa
logger.notice('Version is ' +prog)
logger.notice(' Number of spectra = '+str(nsam))
logger.notice(' Erange : '+str(erange[0])+' to '+str(erange[1]))
Wy,We = ReadWidthFile(fitOp[2],wfile,nsam,Verbose)
dtn,xsc = ReadNormFile(fitOp[3],nsam,resnormWS,Verbose)
Wy,We = ReadWidthFile(width,wfile,nsam,Verbose)
dtn,xsc = ReadNormFile(resnorm,nsam,resnormWS,Verbose)
fname = samWS[:-4] + '_'+ prog
probWS = fname + '_Prob'
fitWS = fname + '_Fit'
Expand Down Expand Up @@ -292,9 +318,19 @@ def QLRun(program,samWS,resWS,resnormWS,erange,nbins,fitOp,wfile,Loop,Verbose=Fa
outWS = C2Se(fname)
if (Plot != 'None'):
QLPlotQSe(fname,Plot,res_plot,Loop)

#Add some sample logs to the output workspace
AddSampleLog(Workspace=outWS, LogName="Fit Program", LogType="String", LogText=prog)
AddSampleLog(Workspace=outWS, LogName="Energy min", LogType="String", LogText=str(erange[0]))
AddSampleLog(Workspace=outWS, LogName="Energy max", LogType="String", LogText=str(erange[1]))
AddSampleLog(Workspace=outWS, LogName="Energy min", LogType="Number", LogText=str(erange[0]))
AddSampleLog(Workspace=outWS, LogName="Energy max", LogType="Number", LogText=str(erange[1]))
AddSampleLog(Workspace=outWS, LogName="Elastic", LogType="String", LogText=str(elastic))
AddSampleLog(Workspace=outWS, LogName="ResNorm", LogType="String", LogText=str(resnorm))
if resnorm:
AddSampleLog(Workspace=outWS, LogName="ResNorm file", LogType="String", LogText=resnormWS)
AddSampleLog(Workspace=outWS, LogName="Width", LogType="String", LogText=str(width))
if width:
AddSampleLog(Workspace=outWS, LogName="Width file", LogType="String", LogText=wfile)

if Save:
fit_path = os.path.join(workdir,fitWS+'.nxs')
SaveNexusProcessed(InputWorkspace=fitWS, Filename=fit_path)
Expand Down Expand Up @@ -639,7 +675,7 @@ def CheckBetSig(nbs):
sys.exit(error)
return Nbet,Nsig

def QuestRun(samWS,resWS,nbs,erange,nbins,fitOp,Loop,Verbose,Plot,Save):
def QuestRun(samWS,resWS,nbs,erange,nbins,Fit,Loop,Verbose,Plot,Save):
StartTime('Quest')
workdir = config['defaultsave.directory']
array_len = 4096 # length of array in Fortran
Expand All @@ -652,6 +688,20 @@ def QuestRun(samWS,resWS,nbs,erange,nbins,fitOp,Loop,Verbose,Plot,Save):
nsam,ntc = CheckHistZero(samWS)
if Loop != True:
nsam = 1
if Fit[0]:
elastic = True
o_el = 1
else:
elastic = False
o_el = 0
if Fit[1] == 'Sloping':
o_bgd = 2
if Fit[1] == 'Flat':
o_bgd = 1
if Fit[1] == 'Zero':
o_bgd = 0
background = Fit[1]
fitOp = [o_el, o_bgd, 0, 0]
efix = getEfixed(samWS)
theta,Q = GetThetaQ(samWS)
nres,ntr = CheckHistZero(resWS)
Expand All @@ -664,6 +714,7 @@ def QuestRun(samWS,resWS,nbs,erange,nbins,fitOp,Loop,Verbose,Plot,Save):
if Verbose:
logger.notice(' Number of spectra = '+str(nsam))
logger.notice(' Erange : '+str(erange[0])+' to '+str(erange[1]))
# dtn,xsc = ReadNormFile(fitOp[3],nsam,Verbose)
fname = samWS[:-4] + '_'+ prog
wrks=workdir + samWS[:-4]
if Verbose:
Expand Down Expand Up @@ -745,14 +796,6 @@ def QuestRun(samWS,resWS,nbs,erange,nbins,fitOp,Loop,Verbose,Plot,Save):
QuestPlot(fname,Plot)
EndTime('Quest')

def QuestPlot(inputWS,Plot):
if (Plot == 'Sigma' or Plot == 'All'):
s_graph = mp.importMatrixWorkspace(inputWS+'_Sigma').plotGraph2D()
s_layer = s_graph.activeLayer().setAxisTitle(2, 'Sigma')
if (Plot == 'Beta' or Plot == 'All'):
b_graph = mp.importMatrixWorkspace(inputWS+'_Beta').plotGraph2D()
b_layer = b_graph.activeLayer().setAxisTitle(2, 'Beta')

# ResNorm programs

def ResNormRun(vname,rname,erange,nbin,Verbose=False,Plot=False,Save=False):
Expand Down Expand Up @@ -823,7 +866,7 @@ def ResNormRun(vname,rname,erange,nbin,Verbose=False,Plot=False,Save=False):
GroupWorkspaces(InputWorkspaces='Data,Fit',OutputWorkspace=fname+'_ResNorm_Fit')
if Save:
par_path = os.path.join(workdir,fname+'_ResNorm.nxs')
SaveNexus(InputWorkspace=fname+'_ResNorm', Filename=par_path)
SaveNexusProcessed(InputWorkspace=fname+'_ResNorm', Filename=par_path)
fit_path = os.path.join(workdir,fname+'_ResNorm_Fit.nxs')
SaveNexusProcessed(InputWorkspace=fname+'_ResNorm_Fit', Filename=fit_path)
if Verbose:
Expand Down

0 comments on commit 3f819a7

Please sign in to comment.