Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/10277_indirect_bayes_fit…
Browse files Browse the repository at this point in the history
…_preview_plots'
  • Loading branch information
mantid-roman committed Nov 7, 2014
2 parents bf6d611 + a35020d commit 248d17f
Show file tree
Hide file tree
Showing 18 changed files with 818 additions and 619 deletions.
Expand Up @@ -12,7 +12,7 @@ def category(self):

def PyInit(self):
self.declareProperty(WorkspaceProperty('InputWorkspace', '', direction=Direction.Input),
doc='Input workspace')
doc='Input workspace in HWHM')

valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater']
self.declareProperty(name='Function', defaultValue=valid_functions[0],
Expand Down Expand Up @@ -51,9 +51,6 @@ def PyExec(self):
spectrum_ws = "__" + self._in_ws
ExtractSingleSpectrum(InputWorkspace=self._in_ws, OutputWorkspace=spectrum_ws, WorkspaceIndex=self._width)

# Convert to HWHM
Scale(InputWorkspace=spectrum_ws, Factor=0.5, OutputWorkspace=spectrum_ws)

if self._verbose:
logger.notice('Cropping from Q= ' + str(self._q_min) + ' to ' + str(self._q_max))
in_run = mtd[self._in_ws].getRun()
Expand Down Expand Up @@ -105,7 +102,8 @@ def PyExec(self):

# Run fit function
if self._out_name is "":
self._out_name = self._in_ws[:-10] + '_' + self._jump_function + 'fit'
ws_suffix_index = self._in_ws.rfind('_')
self._out_name = self._in_ws[:ws_suffix_index] + '_' + self._jump_function + '_fit'

Fit(Function=function, InputWorkspace=spectrum_ws, CreateOutput=True, Output=self._out_name,
StartX=self._q_min, EndX=self._q_max)
Expand Down Expand Up @@ -142,6 +140,7 @@ def _setup(self):
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value


def _process_output(self, workspace):
if self._save:
from mantid.simpleapi import SaveNexusProcessed
Expand All @@ -158,5 +157,6 @@ def _process_output(self, workspace):
mtd_plot = import_mantidplot()
mtd_plot.plotSpectrum(workspace, [0, 1, 2], True)


# Register algorithm with Mantid
AlgorithmFactory.subscribe(JumpFit)
9 changes: 6 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
Expand Up @@ -27,9 +27,10 @@ set ( SRC_FILES
src/IndirectNeutron.cpp
src/IndirectSimulation.cpp
src/IndirectSimulationTab.cpp
src/IndirectSqw.cpp
src/IndirectSqw.cpp
src/IndirectSymmetrise.cpp
src/IndirectTransmission.cpp
src/IndirectTab.cpp
src/IndirectTransmission.cpp
src/JumpFit.cpp
src/MSDFit.cpp
src/MantidEV.cpp
Expand Down Expand Up @@ -106,7 +107,8 @@ set ( INC_FILES
inc/MantidQtCustomInterfaces/IndirectSimulationTab.h
inc/MantidQtCustomInterfaces/IndirectSqw.h
inc/MantidQtCustomInterfaces/IndirectSymmetrise.h
inc/MantidQtCustomInterfaces/IndirectTransmission.h
inc/MantidQtCustomInterfaces/IndirectTransmission.h
inc/MantidQtCustomInterfaces/IndirectTab.h
inc/MantidQtCustomInterfaces/IReflPresenter.h
inc/MantidQtCustomInterfaces/JumpFit.h
inc/MantidQtCustomInterfaces/MSDFit.h
Expand Down Expand Up @@ -189,6 +191,7 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h
inc/MantidQtCustomInterfaces/IndirectSqw.h
inc/MantidQtCustomInterfaces/IndirectSymmetrise.h
inc/MantidQtCustomInterfaces/IndirectTransmission.h
inc/MantidQtCustomInterfaces/IndirectTab.h
inc/MantidQtCustomInterfaces/JumpFit.h
inc/MantidQtCustomInterfaces/MSDFit.h
inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingPresenter.h
Expand Down
Expand Up @@ -2,6 +2,7 @@
#define MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidQtCustomInterfaces/IndirectTab.h"
#include "MantidQtMantidWidgets/RangeSelector.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ namespace MantidQt
/// precision for integer properties in bayes tabs
static const unsigned int INT_DECIMALS = 0;

class DLLExport IndirectBayesTab : public QWidget
class DLLExport IndirectBayesTab : public IndirectTab
{
Q_OBJECT

Expand All @@ -83,10 +84,8 @@ namespace MantidQt
/// Returns a URL for the wiki help page for this interface
QString tabHelpURL();

/// Base methods implemented in derived classes
/// Base methods implemented in derived classes
virtual QString help() = 0;
virtual bool validate() = 0;
virtual void run() = 0;
virtual void loadSettings(const QSettings& settings) = 0;

signals:
Expand All @@ -95,54 +94,24 @@ namespace MantidQt
/// Send signal to parent window to show a message box to user
void showMessageBox(const QString& message);

protected slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min) = 0;
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max) = 0;
/// Slot to handle when a user edits a property
protected slots:
/// Slot to update the guides when the range properties change
virtual void updateProperties(QtProperty* prop, double val) = 0;

protected:
/// Function to plot a workspace to the miniplot using a workspace name
void plotMiniPlot(const QString& workspace, size_t index);
/// Function to plot a workspace to the miniplot using a workspace pointer
void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex);
/// Function to set the range selector on the mini plot
void setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);
/// Function to run a string as python code
void runPythonScript(const QString& pyInput);
/// Function to read an instrument's resolution from the IPF using a string
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res);
/// Function to set the range limits of the plot
void setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
/// Function to set the position of the lower guide on the plot
void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value);
void updateLowerGuide(MantidQt::MantidWidgets::RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value);
/// Function to set the position of the upper guide on the plot
void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value);
/// Function to get the range of the curve displayed on the mini plot
std::pair<double,double> getCurveRange();
/// Run an algorithm async
void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);

/// Plot of the input
QwtPlot* m_plot;
/// Curve on the plot
QwtPlotCurve* m_curve;
/// Range selector widget for mini plot
MantidQt::MantidWidgets::RangeSelector* m_rangeSelector;
void updateUpperGuide(MantidQt::MantidWidgets::RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value);

/// Tree of the properties
QtTreePropertyBrowser* m_propTree;
/// Internal list of the properties
QMap<QString, QtProperty*> m_properties;
/// Double manager to create properties
QtDoublePropertyManager* m_dblManager;
/// Double editor facotry for the properties browser
DoubleEditorFactory* m_dblEdFac;
/// Algorithm runner object to execute algorithms on a seperate thread from the gui
MantidQt::API::AlgorithmRunner* m_algRunner;

};
} // namespace CustomInterfaces
Expand Down
Expand Up @@ -9,6 +9,7 @@
#include "MantidQtAPI/PythonRunner.h"
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
#include "MantidQtCustomInterfaces/IndirectDataReduction.h"
#include "MantidQtCustomInterfaces/IndirectTab.h"
#include "MantidQtMantidWidgets/RangeSelector.h"

#include <QDoubleValidator>
Expand Down Expand Up @@ -41,7 +42,9 @@ namespace MantidQt
{
namespace CustomInterfaces
{
/** IndirectDataReductionTab : TODO: DESCRIPTION
/** IndirectDataReductionTab
This class defines common functionality of tabs used in the Indirect Data Reduction interface.
@author Samuel Jackson
@date 13/08/2013
Expand All @@ -66,7 +69,7 @@ namespace CustomInterfaces
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport IndirectDataReductionTab : public QObject
class DLLExport IndirectDataReductionTab : public IndirectTab
{
Q_OBJECT

Expand All @@ -76,105 +79,24 @@ namespace CustomInterfaces

public slots:
void runTab();
void setupTab();
void validateTab();

protected slots:
/// Slot to handle when an algorithm finishes running
virtual void algorithmFinished(bool error);

protected:
/// Run the load algorithm with the given file name, output name and spectrum range
bool loadFile(const QString& filename, const QString& outputName, const int specMin = -1, const int specMax = -1);

Mantid::API::MatrixWorkspace_sptr loadInstrumentIfNotExist(std::string instrumentName, std::string analyser="", std::string reflection="");
/// Function to get details about the instrument configuration defined on C2E tab
std::map<QString, QString> getInstrumentDetails();

/// Function to plot a workspace to the miniplot using a workspace name
void plotMiniPlot(const QString& workspace, size_t index, const QString& plotID, const QString& curveID = "");
/// Function to plot a workspace to the miniplot using a workspace pointer
void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex, const QString& plotID, const QString& curveID = "");
/// Function to replot a miniplot
void replot(const QString& plotID);

/// Function to get the range of the curve displayed on the mini plot
std::pair<double, double> getCurveRange(const QString& plotID);
/// Function to set the range of an axis on a plot
void setAxisRange(const QString& plotID, QwtPlot::Axis axis, std::pair<double, double> range);
/// Function to autoscale a given axis based on the data in a curve
void setXAxisToCurve(const QString& plotID, const QString& curveID);

/// Function to set the range limits of the plot
void setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
/// Function to set the range selector on the mini plot
void setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);

/// Function to run an algorithm on a seperate thread
void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);

std::map<std::string, double> getRangesFromInstrument(QString instName = "", QString analyser = "", QString reflection = "");

/// Parent QWidget (if applicable)
QWidget *m_parentWidget;

/// Plot of the input
std::map<QString, QwtPlot *> m_plots;
/// Curve on the plot
std::map<QString, QwtPlotCurve *> m_curves;
/// Range selector widget for mini plot
std::map<QString, MantidQt::MantidWidgets::RangeSelector *> m_rangeSelectors;
/// Tree of the properties
std::map<QString, QtTreePropertyBrowser *> m_propTrees;

/// If algorithms are currently running on this tab
bool m_tabRunning;

/// Internal list of the properties
QMap<QString, QtProperty*> m_properties;

/// Double manager to create properties
QtDoublePropertyManager* m_dblManager;
/// Boolean manager to create properties
QtBoolPropertyManager* m_blnManager;
/// Group manager to create properties
QtGroupPropertyManager* m_grpManager;

/// Double editor facotry for the properties browser
DoubleEditorFactory* m_dblEdFac;

/// Algorithm runner object to execute chains algorithms on a seperate thread from the GUI
MantidQt::API::BatchAlgorithmRunner *m_batchAlgoRunner;

/// Use a Python runner for when we need the output of a script
MantidQt::API::PythonRunner m_pythonRunner;

/// Validator for int inputs
QIntValidator *m_valInt;
/// Validator for double inputs
QDoubleValidator *m_valDbl;
/// Validator for positive double inputs
QDoubleValidator *m_valPosDbl;

Ui::IndirectDataReduction m_uiForm;

signals:
/// Send signal to parent window to show a message box to user
void showMessageBox(const QString& message);
/// Run a python script
void runAsPythonScript(const QString & code, bool no_output);
/// Update the Run button on the IDR main window
void updateRunButton(bool enabled = true, QString message = "Run", QString tooltip = "");
/// Emitted when the instrument setup is changed
void newInstrumentConfiguration();

private:
/// Overidden by child class.
virtual void setup() = 0;
/// Overidden by child class.
virtual void run() = 0;
/// Overidden by child class.
virtual bool validate() = 0;
bool m_tabRunning;

QString getInstrumentParameterFrom(Mantid::Geometry::IComponent_const_sptr comp, std::string param);

Expand Down

0 comments on commit 248d17f

Please sign in to comment.