Skip to content

Commit

Permalink
plots appopriate graph and cleaner code
Browse files Browse the repository at this point in the history
refs #14477
  • Loading branch information
Shahroz Ahmed committed Feb 11, 2016
1 parent e8aa707 commit 1cbabd2
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ protected slots:
// plots workspace according to the user selection
void plotFocusedWorkspace(std::string outWSName);

void plotCalibWorkspace(std::vector<double> difc, std::vector<double> tzero);

// algorithms to save the generated workspace
void saveGSS(std::string inputWorkspace, std::string bank, std::string runNo);
void saveFocusedXYE(std::string inputWorkspace, std::string bank,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class MANTIDQT_CUSTOMINTERFACES_DLL EnggDiffractionViewQtGUI

virtual void plotVanCurvesCalibOutput();

virtual void plotDifcZeroCalibOutput(const std::string &wsName,
double &difc, double &tzero);
virtual void plotDifcZeroCalibOutput(std::vector<double> &difc,
std::vector<double> &tzero);

virtual bool saveFocusedOutputFiles() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ class IEnggDiffractionView {
*/
virtual bool focusedOutWorkspace() const = 0;

/**
* Check box to consider when calibrating
* whether to plot focused workspace
*
* @return bool
*/
virtual bool plotCalibWorkspace() const = 0;

/**
* Reset all focus inputs/options
*/
Expand Down Expand Up @@ -343,7 +351,22 @@ class IEnggDiffractionView {
*
* @return bool
*/
virtual bool saveOutputFiles() const = 0;
virtual bool saveFocusedOutputFiles() const = 0;

/**
* Produces vanadium curves graph with three spectrum for calib
* output. Runsm plotSpectrum function via python.
*
*/
virtual void plotVanCurvesCalibOutput() = 0;

/**
* Produces ceria peaks graph with two spectrum for calib
* output. Runs the plotSpectrum function via python.
*
*/
virtual void plotDifcZeroCalibOutput(std::vector<double> &difc,
std::vector<double> &tzero) = 0;

/**
* Produces a single spectrum graph for focused output. Runs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,10 @@ void EnggDiffractionPresenter::doCalib(const EnggDiffCalibSettings &cs,
g_log.notice() << " * Bank " << i + 1 << " calibrated, "
<< "difc: " << difc[i] << ", zero: " << tzero[i]
<< std::endl;

}
// plots the calibrated workspaces
plotCalibWorkspace(difc, tzero);

// Creates appropriate directory
Poco::Path saveDir = outFilesDir("Calibration");
Expand Down Expand Up @@ -1582,7 +1585,7 @@ void EnggDiffractionPresenter::doFocusing(const EnggDiffCalibSettings &cs,
g_log.notice() << "Saved focused workspace as file: " << fullFilename
<< std::endl;

bool saveOutputFiles = m_view->saveOutputFiles();
bool saveOutputFiles = m_view->saveFocusedOutputFiles();

if (saveOutputFiles) {
try {
Expand Down Expand Up @@ -2099,6 +2102,24 @@ void EnggDiffractionPresenter::plotFocusedWorkspace(std::string outWSName) {
}
}

/**
* Check if the plot calibration check-box is ticked
* python script is passed on to mantid python window
* which plots the workspaces with customisation
*
* @param difc vector of double passed on to py script
* @param tzero vector of double to plot graph
*/
void EnggDiffractionPresenter::plotCalibWorkspace(std::vector<double> difc,
std::vector<double> tzero) {
const bool plotCalibWS = m_view->plotCalibWorkspace();
if (plotCalibWS) {
m_view->plotDifcZeroCalibOutput(difc, tzero);
m_view->plotVanCurvesCalibOutput();

}
}

/**
* Convert the generated output files and saves them in
* FocusedXYE format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,52 +617,65 @@ void EnggDiffractionViewQtGUI::plotReplacingWindow(const std::string &wsName) {

// shahroz
void EnggDiffractionViewQtGUI::plotVanCurvesCalibOutput() {
std::string pyCode =
std::string pyCode1 =
"van_curves_ws = workspace(\"engggui_vanadium_curves_ws\")\n"
"plot(van_curves_ws, [0, 1, 2])";

std::string status =
runPythonCode(QString::fromStdString(pyCode), false).toStdString();
runPythonCode(QString::fromStdString(pyCode1), false).toStdString();

m_logMsgs.push_back(
"Plotted output calibration vanadium curves, with status string " +
status);
m_presenter->notify(IEnggDiffractionPresenter::LogMsg);
};

void EnggDiffractionViewQtGUI::plotDifcZeroCalibOutput(
const std::string &wsName, double &difc, double &tzero) {
void EnggDiffractionViewQtGUI::plotDifcZeroCalibOutput(std::vector<double> &difc,
std::vector<double> &tzero) {

auto bank1 = size_t(1);
auto bank2 = size_t(2);

std::string pyCode =
"bank_ws = workspace(" + wsName +
")\n"
"xVal = []\n"
"yVal = []\n"
"y2Val = []\n"

"for i in range(0, bank_ws.rowCount()):\n"
" xVal.append(bank_ws.cell()i, 0))\n"
" yVal.append(bank_ws.cell()i, 5))\n"
" difc=" +
boost::lexical_cast<std::string>(difc) + "\n" + " tzero=" +
boost::lexical_cast<std::string>(tzero) + "\n" +
" y2Val.append(xVal[i] * difc + tzero)\n"

"ws1 = CreateWorkspace(DataX=xVal, DataY=yVal, UnitX=\"Expected Peaks "
"Centre(dSpacing, A)\", YUnitLabel = \"Fitted Peaks Centre(TOF, us)\")\n"
"ws2 = CreateWorkspace(DataX=xVal, DataY=y2Val)\n"
"AppendSpectra(ws1, ws2, OutputWorkspace=\"engggui_difc_zero_peaks\")\n"

"DeleteWorkspace(ws1)\n"
"DeleteWorkspace(ws1)\n"

"engggui_difc_zero_peaks = workspace(\"engggui_difc_zero_peaks\")\n"
"calWin = plotSpectrum(engggui_difc_zero_peaks, [0, 1]).activeLayer()\n"

"calWin.setTitle(\"Engg Gui Difc Zero Peaks\")\n"
"calWin.setAxisTitle(Layer.Bottom, \"Expected Peaks Centre(dSpacing, "
"A)\")\n"
"calWin.setCurveLineStyle(0, QtCore.Qt.DotLine)\n";
"for i in range(1, 3):\n"
" bank_ws = workspace(\"engggui_calibration_bank_\" + str(i))\n"

" xVal = []\n"
" yVal = []\n"
" y2Val = []\n"

" for irow in range(0, bank_ws.rowCount()):\n"
" xVal.append(bank_ws.cell(irow, 0))\n"
" yVal.append(bank_ws.cell(irow, 5))\n"

" if (i == 1):\n"
" difc=" + boost::lexical_cast<std::string>(difc[bank1]) + "\n" +
" tzero=" + boost::lexical_cast<std::string>(tzero[bank1]) + "\n" +
" else:\n"
" difc=" + boost::lexical_cast<std::string>(difc[bank2]) + "\n" +
" tzero=" + boost::lexical_cast<std::string>(tzero[bank2]) + "\n" +

" y2Val.append(xVal[irow] * difc + tzero)\n"

" ws1 = CreateWorkspace(DataX=xVal, DataY=yVal, UnitX=\"Expected Peaks "
" Centre(dSpacing, A)\", YUnitLabel = \"Fitted Peaks Centre(TOF, us)\")\n"
" ws2 = CreateWorkspace(DataX=xVal, DataY=y2Val)\n"
" output_ws = \"engggui_difc_zero_peaks_bank_\" + str(i)\n"
" AppendSpectra(ws1, ws2, OutputWorkspace=output_ws)\n"

" DeleteWorkspace(ws1)\n"
" DeleteWorkspace(ws2)\n"

" DifcZeroWs = \"engggui_difc_zero_peaks_bank_\" + str(i)\n"

" DifcZeroWs = workspace(DifcZeroWs)\n"
" DifcZeroWs = plotSpectrum(DifcZeroWs, [0, 1]).activeLayer()\n"

" DifcZeroWs.setTitle(\"Engg Gui Difc Zero Peaks Bank \" + str(i))\n"
" DifcZeroWs.setAxisTitle(Layer.Bottom, \"Expected Peaks "
"Centre(dSpacing, "
" A)\")\n"
" DifcZeroWs.setCurveLineStyle(0, QtCore.Qt.DotLine)\n";

std::string status =
runPythonCode(QString::fromStdString(pyCode), false).toStdString();
Expand Down
20 changes: 15 additions & 5 deletions MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,36 @@ class MockEnggDiffractionView
// virtual bool focusedOutWorkspace() const;
MOCK_CONST_METHOD0(focusedOutWorkspace, bool());

// virtual bool plotCalibWorkspace
MOCK_CONST_METHOD0(plotCalibWorkspace, bool());

// void saveSettings() const;
MOCK_CONST_METHOD0(saveSettings, void());

// std::string saveOutputFiles
MOCK_CONST_METHOD0(saveOutputFiles, bool());

// virtual void plotFocusedSpectrum();
MOCK_METHOD1(plotFocusedSpectrum, void(const std::string &));
// virtual bool saveFocusedOutputFiles
MOCK_CONST_METHOD0(saveFocusedOutputFiles, bool());

// void plotFocusStatus();
MOCK_METHOD0(plotFocusStatus, void());

// void plotRepChanged();
MOCK_METHOD1(plotRepChanged, void(int idx));

// virtual void plotFocusedSpectrum();
MOCK_METHOD1(plotFocusedSpectrum, void(const std::string &));

// virtual void plotWaterfallSpectrum
MOCK_METHOD1(plotWaterfallSpectrum, void(const std::string &wsName));

// virtual void plotReplacingWindow
MOCK_METHOD1(plotReplacingWindow, void(const std::string &wsName));

// virtual void plotVanCurvesCalibOutput();
MOCK_METHOD0(plotVanCurvesCalibOutput, void());

// virtual void plotDifcZeroCalibOutput();
MOCK_METHOD2(plotDifcZeroCalibOutput,
void(std::vector<double> &difc, std::vector<double> &tzero));
};

#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONVIEWMOCK_H

0 comments on commit 1cbabd2

Please sign in to comment.