Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDR calibration show pre and post smooth #171

Merged
merged 4 commits into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def PyInit(self):

self.declareProperty(name='RebinParam', defaultValue='', doc='Rebinning parameters (min,width,max)')
self.declareProperty(name='ScaleFactor', defaultValue=1.0, doc='Factor to scale resolution curve by')
self.declareProperty(name='Smooth', defaultValue=False, doc='Apply WienerSmooth to resolution')

self.declareProperty(name='Plot', defaultValue=False, doc='Plot resolution curve')
self.declareProperty(name='Save', defaultValue=False, doc='Save resolution workspace as a Nexus file')
Expand Down Expand Up @@ -74,11 +73,6 @@ def PyExec(self):

Rebin(InputWorkspace=self._out_ws, OutputWorkspace=self._out_ws, Params=self._rebin_string)

if self._smooth:
WienerSmooth(InputWorkspace=self._out_ws, OutputWorkspace='__smooth_temp')
CopyLogs(InputWorkspace=self._out_ws, OutputWorkspace='__smooth_temp')
RenameWorkspace(InputWorkspace='__smooth_temp', OutputWorkspace=self._out_ws)

self._post_process()
self.setProperty('OutputWorkspace', self._out_ws)

Expand All @@ -101,7 +95,6 @@ def _setup(self):
self._background = self.getProperty('BackgroundRange').value
self._rebin_string = self.getProperty('RebinParam').value
self._scale_factor = self.getProperty('ScaleFactor').value
self._smooth = self.getProperty('Smooth').value

self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value
Expand All @@ -117,8 +110,6 @@ def _post_process(self):
if use_scale_factor:
AddSampleLog(Workspace=self._out_ws, LogName='scale_factor', LogType='Number', LogText=str(self._scale_factor))

AddSampleLog(Workspace=self._out_ws, LogName='res_smoothing_applied', LogType='String', LogText=str(self._smooth))

AddSampleLog(Workspace=self._out_ws, LogName='back_start', LogType='Number', LogText=str(self._background[0]))
AddSampleLog(Workspace=self._out_ws, LogName='back_end', LogType='Number', LogText=str(self._background[1]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace CustomInterfaces
virtual bool validate();

private slots:
void algorithmsComplete(bool error);
void algorithmComplete(bool error);
void calPlotRaw();
void calPlotEnergy();
void calMinChanged(double);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<property name="maximum">
<double>999.990000000000009</double>
</property>
<property name="value">
<double>1.0</double>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -161,6 +164,9 @@
<property name="maximum">
<double>999.990000000000009</double>
</property>
<property name="value">
<double>1.0</double>
</property>
</widget>
</item>
</layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ namespace CustomInterfaces

// Nudge resCheck to ensure res range selectors are only shown when Create RES file is checked
resCheck(m_uiForm.ckCreateResolution->isChecked());

connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool)));
}

//----------------------------------------------------------------------------------------------
Expand All @@ -165,8 +167,6 @@ namespace CustomInterfaces

void IndirectCalibration::run()
{
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmsComplete(bool)));

// Get properties
QString firstFile = m_uiForm.leRunNo->getFirstFilename();
QString filenames = m_uiForm.leRunNo->getFilenames().join(",");
Expand All @@ -184,7 +184,7 @@ namespace CustomInterfaces
QString calibrationWsName = outputWorkspaceNameStem + "_calib";

// Configure the calibration algorithm
IAlgorithm_sptr calibrationAlg = AlgorithmManager::Instance().create("CreateCalibrationWorkspace", -1);
IAlgorithm_sptr calibrationAlg = AlgorithmManager::Instance().create("CreateCalibrationWorkspace");
calibrationAlg->initialize();

calibrationAlg->setProperty("InputFiles", filenames.toStdString());
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace CustomInterfaces
// Add save algorithm to queue if ticked
if( m_uiForm.ckSave->isChecked() )
{
IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create("SaveNexus", -1);
IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create("SaveNexusProcessed");
saveAlg->initialize();
saveAlg->setProperty("Filename", calibrationWsName.toStdString() + ".nxs");

Expand All @@ -224,10 +224,6 @@ namespace CustomInterfaces
{
QString resolutionWsName = outputWorkspaceNameStem + "_res";

QString scaleFactor("1.0");
if(m_uiForm.ckResolutionScale->isChecked() && !m_uiForm.spResolutionScale->text().isEmpty())
scaleFactor = m_uiForm.spResolutionScale->text();

QString resDetectorRange = QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + ","
+ QString::number(m_dblManager->value(m_properties["ResSpecMax"]));

Expand All @@ -238,44 +234,78 @@ namespace CustomInterfaces
QString background = QString::number(m_dblManager->value(m_properties["ResStart"])) + ","
+ QString::number(m_dblManager->value(m_properties["ResEnd"]));

Mantid::API::IAlgorithm_sptr resAlg = Mantid::API::AlgorithmManager::Instance().create("IndirectResolution", -1);
bool smooth = m_uiForm.ckSmoothResolution->isChecked();
bool save = m_uiForm.ckSave->isChecked();

IAlgorithm_sptr resAlg = AlgorithmManager::Instance().create("IndirectResolution", -1);
resAlg->initialize();

resAlg->setProperty("InputFiles", filenames.toStdString());
resAlg->setProperty("OutputWorkspace", resolutionWsName.toStdString());
resAlg->setProperty("Instrument", getInstrumentConfiguration()->getInstrumentName().toStdString());
resAlg->setProperty("Analyser", getInstrumentConfiguration()->getAnalyserName().toStdString());
resAlg->setProperty("Reflection", getInstrumentConfiguration()->getReflectionName().toStdString());
resAlg->setProperty("RebinParam", rebinString.toStdString());
resAlg->setProperty("DetectorRange", resDetectorRange.toStdString());
resAlg->setProperty("BackgroundRange", background.toStdString());
resAlg->setProperty("ScaleFactor", m_uiForm.spScale->value());
resAlg->setProperty("Smooth", m_uiForm.ckSmoothResolution->isChecked());
resAlg->setProperty("Plot", m_uiForm.ckPlot->isChecked());
resAlg->setProperty("Save", m_uiForm.ckSave->isChecked());
resAlg->setProperty("Save", save);

if(m_uiForm.ckResolutionScale->isChecked())
resAlg->setProperty("ScaleFactor", m_uiForm.spScale->value());

if(smooth)
{
resAlg->setProperty("OutputWorkspace", resolutionWsName.toStdString() + "_pre_smooth");
}
else
{
resAlg->setProperty("OutputWorkspace", resolutionWsName.toStdString());
resAlg->setProperty("Plot", m_uiForm.ckPlot->isChecked());
}

m_batchAlgoRunner->addAlgorithm(resAlg);

if(smooth)
{
IAlgorithm_sptr smoothAlg = AlgorithmManager::Instance().create("WienerSmooth");
smoothAlg->initialize();
smoothAlg->setProperty("OutputWorkspace", resolutionWsName.toStdString());

BatchAlgorithmRunner::AlgorithmRuntimeProps smoothAlgInputProps;
smoothAlgInputProps["InputWorkspace"] = resolutionWsName.toStdString() + "_pre_smooth";

m_batchAlgoRunner->addAlgorithm(smoothAlg, smoothAlgInputProps);

if(save)
{
IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create("SaveNexusProcessed");
saveAlg->initialize();

BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromSmoothProps;
inputFromSmoothProps["InputWorkspace"] = calibrationWsName.toStdString();
saveAlg->setProperty("Filename", resolutionWsName.toStdString() + ".nxs");

m_batchAlgoRunner->addAlgorithm(saveAlg, inputFromSmoothProps);
}
}

// When creating resolution file take the resolution workspace as the result
m_pythonExportWsName = resolutionWsName.toStdString();
}

m_batchAlgoRunner->executeBatchAsync();
}

void IndirectCalibration::algorithmsComplete(bool error)
void IndirectCalibration::algorithmComplete(bool error)
{
if(error)
return;

QString firstFile = m_uiForm.leRunNo->getFirstFilename();
QFileInfo firstFileInfo(firstFile);
/* QString calFileName = firstFileInfo.baseName() + "_" + m_uiForm.iicInstrumentConfiguration->getAnalyserName() + m_uiForm.iicInstrumentConfiguration->getReflectionName() + "_calib.nxs"; */

/* m_uiForm.ind_calibFile->setFileTextWithSearch(calFileName); */
/* m_uiForm.ckUseCalib->setChecked(true); */

disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmsComplete(bool)));
// Plot the smoothed workspace if required
if(m_uiForm.ckSmoothResolution->isChecked() && m_uiForm.ckPlot->isChecked())
{
std::string pyInput = "from mantidplot import plotSpectrum\nplotSpectrum(['" + m_pythonExportWsName + "', '" + m_pythonExportWsName + "_pre_smooth'], 0)\n";
m_pythonRunner.runPythonCode(QString::fromStdString(pyInput));
}
}

bool IndirectCalibration::validate()
Expand Down Expand Up @@ -370,8 +400,8 @@ namespace CustomInterfaces
return;
}

Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve(wsname.toStdString()));

const Mantid::MantidVec & dataX = input->readX(0);
std::pair<double, double> range(dataX.front(), dataX.back());
Expand Down Expand Up @@ -455,7 +485,7 @@ namespace CustomInterfaces
*
* @param ws :: Mantid workspace containing the loaded instument
*/
void IndirectCalibration::calSetDefaultResolution(Mantid::API::MatrixWorkspace_const_sptr ws)
void IndirectCalibration::calSetDefaultResolution(MatrixWorkspace_const_sptr ws)
{
auto inst = ws->getInstrument();
auto analyser = inst->getStringParameter("analyser");
Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/docs/source/algorithms/IndirectResolution-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Description

Creates a resolution workspace for an inelastic indirect sample run.

See `Indirect:Calibration <http://www.mantidproject.org/Indirect:Calibration>`_.

Usage
-----

Expand Down