Skip to content

Commit

Permalink
Merge branch 'master' into feature/9840_reflectometryreductionone_pol…
Browse files Browse the repository at this point in the history
…arizationcorrection

Refs #9840

This merge is to incorporate the changes from #10524 into #9840.
  • Loading branch information
Harry Jeffery committed Nov 26, 2014
2 parents da0c61c + d289cb7 commit 8f25e48
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 69 deletions.
9 changes: 7 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ namespace API
/// Populate the parameter map given a string
void readParameterMap(const std::string & parameterStr);

/// Returns the start date for this experiment
std::string getWorkspaceStartDate();
/// Returns the start date for this experiment (or current time if no info available)
std::string getWorkspaceStartDate() const;

// run/experiment stat time if available, empty otherwise
std::string getAvailableWorkspaceStartDate() const;
// run end time if available, empty otherwise
std::string getAvailableWorkspaceEndDate() const;

/// Utility to retrieve the validity dates for the given IDF
static void getValidFromTo(const std::string& IDFfilename, std::string& outValidFrom, std::string& outValidTo);
Expand Down
59 changes: 56 additions & 3 deletions Code/Mantid/Framework/API/src/ExperimentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ namespace API
<< inst->getValidFromDate().toFormattedString("%Y-%b-%d")
<< " to " << inst->getValidToDate().toFormattedString("%Y-%b-%d") << ")";
out << "\n";

std::string runStart = getAvailableWorkspaceStartDate();
std::string runEnd = getAvailableWorkspaceEndDate();
std::string msgNA = "not available";
if (runStart.empty())
runStart = msgNA;
if (runEnd.empty())
runEnd = msgNA;
out << "Run start: " << runStart << "\n";
out << "Run end: " << runEnd << "\n"; // note extra space for pseudo/approx-alignment

if (this->sample().hasOrientedLattice())
{
const Geometry::OrientedLattice & latt = this->sample().getOrientedLattice();
Expand Down Expand Up @@ -766,11 +777,11 @@ namespace API

//---------------------------------------------------------------------------------------
/** Return workspace start date as an ISO 8601 string. If this info not stored in workspace the
* method returns current date.
* method returns current date. This date is used for example to retrieve the instrument file.
*
* @return workspace start date as a string
* @return workspace start date as a string (current time if start date not available)
*/
std::string ExperimentInfo::getWorkspaceStartDate()
std::string ExperimentInfo::getWorkspaceStartDate() const
{
std::string date;
try
Expand All @@ -785,6 +796,48 @@ namespace API
return date;
}

//---------------------------------------------------------------------------------------
/** Return workspace start date as a formatted string (strftime, as
* returned by Kernel::DateAndTime) string, if available. If
* unavailable, an empty string is returned
*
* @return workspace start date as a string (empty if no date available)
*/
std::string ExperimentInfo::getAvailableWorkspaceStartDate() const
{
std::string date;
try
{
date = run().startTime().toFormattedString();
}
catch (std::runtime_error &)
{
g_log.information("Note: run_start/start_time not stored in workspace.");
}
return date;
}

//---------------------------------------------------------------------------------------
/** Return workspace end date as a formatted string (strftime style,
* as returned by Kernel::DateAdnTime) string, if available. If
* unavailable, an empty string is returned
*
* @return workspace end date as a string (empty if no date available)
*/
std::string ExperimentInfo::getAvailableWorkspaceEndDate() const
{
std::string date;
try
{
date = run().endTime().toFormattedString();
}
catch (std::runtime_error &)
{
g_log.information("Note: run_start/start_time not stored in workspace.");
}
return date;
}

//---------------------------------------------------------------------------------------
/** A given instrument may have multiple IDFs associated with it. This method return an
* identifier which identify a given IDF for a given instrument. An IDF filename is
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite
"X axis: Time-of-flight / microsecond\n"
"Y axis: Counts\n"
"Distribution: False\n"
"Instrument: (1990-Jan-01 to 1990-Jan-01)\n";
"Instrument: (1990-Jan-01 to 1990-Jan-01)\n"
"Run start: not available\n"
"Run end: not available\n"
;

TS_ASSERT_EQUALS(expected, testWS->toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ namespace Mantid
/// Load the logs
void runLoadLogs(const std::string filename,
API::MatrixWorkspace_sptr localWorkspace);
/// is it possible to open the file?
bool canOpenAsNeXus(const std::string& fname);

/// The name and path of the input file
std::string filename;
/// The workspace being filled out
Expand Down
35 changes: 35 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusMonitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ void LoadNexusMonitors::exec()

API::Progress prog1(this, 0.0, 0.2, 2);

if (!canOpenAsNeXus(this->filename))
{
throw std::runtime_error("Failed to recognize this file as a NeXus file, cannot continue.");
}

// top level file information
::NeXus::File file(this->filename);

Expand Down Expand Up @@ -160,6 +165,9 @@ void LoadNexusMonitors::exec()
if (numHistMon == this->nMonitors)
{
useEventMon = false;
if (this->nMonitors == 0)
throw std::runtime_error("Not loading event data. Trying to load histogram data but failed to find monitors with histogram data or could not interpret the data. This file may be corrupted or it may not be supported");

this->WS = API::WorkspaceFactory::Instance().create("Workspace2D",
this->nMonitors, 1, 1);
// if there is a distinct monitor number for each monitor sort them by that number
Expand Down Expand Up @@ -486,5 +494,32 @@ void LoadNexusMonitors::runLoadLogs(const std::string filename, API::MatrixWorks
}
}

/**
* Helper method to make sure that a file is / can be openend as a NeXus file
*
* @param fname :: name of the file
* @return True if opening the file as NeXus and retrieving entries succeeds
**/
bool LoadNexusMonitors::canOpenAsNeXus(const std::string& fname)
{
bool res = true;
::NeXus::File* f = NULL;
try
{
f = new ::NeXus::File(fname);
if (f)
f->getEntries();
}
catch(::NeXus::Exception& e)
{
g_log.error() << "Failed to open as a NeXus file: '" << fname <<
"', error description: " << e.what() << std::endl;
res = false;
}
if (f)
delete f;
return res;
}

} // end DataHandling
} // end Mantid
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def PyExec(self):
OutputWorkspace=self._samSqwWs,
QAxisBinning=self._qBins, EMode='Indirect',
EFixed='2.0826')
# Clear mask from reduced file. Needed for binary operations involving this S(Q,w)
api.ClearMaskFlag(Workspace=self._samSqwWs)

dave_grp_filename = self._makeRunName(self._samWsRun,
False) + ".dat"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def PyInit(self):
self.declareProperty("VanadiumPeakTol", 0.05,
"How far from the ideal position a vanadium peak can be during StripVanadiumPeaks. Default=0.05, negative turns off")
self.declareProperty("VanadiumSmoothParams", "20,2", "Default=20,2")
self.declareProperty("BackgroundSmoothParams", "", "Default=off, suggested 20,2")
self.declareProperty("FilterBadPulses", 95.,
doc="Filter out events measured while proton charge is more than 5% below average")
self.declareProperty("ScaleData", defaultValue=1., validator=FloatBoundedValidator(lower=0., exclusive=True),
Expand All @@ -99,13 +100,13 @@ def PyInit(self):

self.declareProperty("NormalizeByCurrent", True, "Normalize by current")

self.declareProperty("CompressTOFTolerance", 0.01, "Tolerance to compress events in TOF.")
self.declareProperty(StringArrayProperty("FrequencyLogNames", ["SpeedRequest1", "Speed1", "frequency"],
self.declareProperty("CompressTOFTolerance", 0.01, "Tolerance to compress events in TOF.")

self.declareProperty(StringArrayProperty("FrequencyLogNames", ["SpeedRequest1", "Speed1", "frequency"],
direction=Direction.Input),
"Possible log names for frequency.")

self.declareProperty(StringArrayProperty("WaveLengthLogNames", ["LambdaRequest", "lambda"],
self.declareProperty(StringArrayProperty("WaveLengthLogNames", ["LambdaRequest", "lambda"],
direction=Direction.Input),
"Candidate log names for wave length.")

Expand Down Expand Up @@ -300,6 +301,12 @@ def PyExec(self):
canRun = self._focusChunks(canRun, SUFFIX, canFilterWall, calib,
preserveEvents=preserveEvents)
canRun = api.ConvertUnits(InputWorkspace=canRun, OutputWorkspace=canRun, Target="TOF")

smoothParams = self.getProperty("BackgroundSmoothParams").value
if smoothParams != None and len(smoothParams)>0:
canRun = api.FFTSmooth(InputWorkspace=canRun, OutputWorkspace=canRun, Filter="Butterworth",
Params=smoothParams,IgnoreXBins=True,AllSpectra=True)

workspacelist.append(str(canRun))
else:
canRun = None
Expand Down Expand Up @@ -388,6 +395,9 @@ def PyExec(self):
return
# the final bit of math
if canRun is not None:
# must convert the sample to a matrix workspace if the can run isn't one
if canRun.id() != EVENT_WORKSPACE_ID and samRun.id() == EVENT_WORKSPACE_ID:
samRun = api.ConvertToMatrixWorkspace(InputWorkspace=samRun, OutputWorkspace=samRun)
samRun = api.Minus(LHSWorkspace=samRun, RHSWorkspace=canRun, OutputWorkspace=samRun)
if samRun.id() == EVENT_WORKSPACE_ID:
samRun = api.CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
Expand Down Expand Up @@ -493,7 +503,7 @@ def _loadData(self, runnumber, extension, filterWall=None, outname=None, **chunk
LowerCutoff=self._filterBadPulses)

if isEventWS is True:
# Event workspace
# Event workspace
self.log().information("FilterBadPulses reduces number of events from %d to %d (under %s percent) of workspace %s." % (
numeventsbefore, wksp.getNumberEvents(), str(self._filterBadPulses), str(wksp)))

Expand Down Expand Up @@ -664,7 +674,7 @@ def _focusChunks(self, runnumber, extension, filterWall, calib, splitwksp=None,
self.log().debug("[DBx131] ws %d: spectrum ID = %d. " % (iws, spec.getSpectrumNo()))

if preserveEvents is True and isinstance(temp, mantid.api._api.IEventWorkspace) is True:
self.log().information("After being aligned and focussed workspace %s; Number of events = %d of chunk %d " % (str(temp),
self.log().information("After being aligned and focussed workspace %s; Number of events = %d of chunk %d " % (str(temp),
temp.getNumberEvents(), ichunk))

# Rename and/or add to workspace of same splitter but different chunk
Expand Down
46 changes: 38 additions & 8 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3076,8 +3076,37 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

const QString& firstWsName = toPlot.constBegin().key();
const QString& firstWsName = toPlot.constBegin().key();;
QString plotTitle;
// If the first workspace selected in the tree is a WorkspaceGroup,
// use its name directly, rather than the first in the list 'toPlot'
// (which will be the first workspace included in the group - not
// the best title).
const QString& sel = m_exploreMantid->getSelectedWorkspaceName();
WorkspaceGroup_const_sptr gWs;
if (!sel.isEmpty() && AnalysisDataService::Instance().doesExist(sel.toStdString()))
{
try
{
gWs = boost::dynamic_pointer_cast<const WorkspaceGroup>
(Mantid::API::AnalysisDataService::Instance().retrieve(sel.toStdString()));
}
catch(std::exception&)
{
// can happen, nothing to worry about
gWs = WorkspaceGroup_const_sptr(); // make sure, anyway
}
}
if (gWs)
{
plotTitle = sel;
}
else
{
plotTitle = firstWsName;
}

// Limit to 1 window for this type of plot -> reuse plot/graph window
if(workspacesDockPlot1To1())
{
if (m_lastShown1DPlotWin)
Expand All @@ -3087,8 +3116,8 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum
}
}
bool isGraphNew = false;
MultiLayer* ml = appWindow()->prepareMultiLayer(isGraphNew, plotWindow, firstWsName, clearWindow);
ml->setName(appWindow()->generateUniqueName(firstWsName + "-"));
MultiLayer* ml = appWindow()->prepareMultiLayer(isGraphNew, plotWindow, plotTitle, clearWindow);
ml->setName(appWindow()->generateUniqueName(plotTitle + "-"));
m_lastShown1DPlotWin = ml;

Graph *g = ml->activeGraph();
Expand All @@ -3113,7 +3142,12 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum
}
}

if(isGraphNew)
if(!isGraphNew)
{
// Replot graph is we've added curves to existing one
g->replot();
}
else
{
if(!firstCurve)
{
Expand All @@ -3137,10 +3171,6 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum
g->checkValuesInAxisRange(firstCurve);
}

if(!isGraphNew)
// Replot graph is we've added curves to existing one
g->replot();

// Check if window does not contain any curves and should be closed
ml->maybeNeedToClose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace CustomDialogs
///Constructor
StartLiveDataDialog::StartLiveDataDialog(QWidget *parent) :
AlgorithmDialog(parent),
m_useProcessAlgo(false), m_useProcessScript(NULL),
m_useProcessAlgo(false), m_useProcessScript(false),
m_usePostProcessAlgo(false), m_usePostProcessScript(false)
{
// Create the input history. This loads it too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidQtCustomInterfaces/IReflPresenter.h"
#include "MantidQtCustomInterfaces/IReflSearcher.h"
Expand Down Expand Up @@ -83,13 +82,13 @@ namespace MantidQt
//get an unused group id
int getUnusedGroup(std::set<int> ignoredRows = std::set<int>()) const;
//make a transmission workspace
Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString);
Mantid::API::Workspace_sptr makeTransWS(const std::string& transString);
//Validate a row
void validateRow(int rowNo) const;
//Autofill a row with sensible values
void autofillRow(int rowNo);
//calculates qmin and qmax
std::vector<double> calcQRange(Mantid::API::MatrixWorkspace_sptr ws, double theta);
std::vector<double> calcQRange(Mantid::API::Workspace_sptr ws, double theta);
//get the number of rows in a group
size_t numRowsInGroup(int groupId) const;
//Stitch some rows
Expand Down

0 comments on commit 8f25e48

Please sign in to comment.