Skip to content

Commit

Permalink
Ranem ElasticWindow ranges Refs #11870
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Jun 1, 2015
1 parent 1216797 commit 012a1ae
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 67 deletions.
30 changes: 15 additions & 15 deletions Code/Mantid/Framework/Algorithms/src/ElasticWindow.cpp
Expand Up @@ -26,25 +26,25 @@ void ElasticWindow::init() {
declareProperty(
new WorkspaceProperty<>("OutputInQSquared", "", Direction::Output),
"The name for output workspace with the X axis in units of Q^2.");
declareProperty("Range1Start", EMPTY_DBL(),
declareProperty("IntegrationRangeStart", EMPTY_DBL(),
boost::make_shared<MandatoryValidator<double>>(),
"Start Point of Range 1");
declareProperty("Range1End", EMPTY_DBL(),
declareProperty("IntegrationRangeEnd", EMPTY_DBL(),
boost::make_shared<MandatoryValidator<double>>(),
"End Point of Range 1");
declareProperty("Range2Start", EMPTY_DBL(), "Start Point of Range 2",
declareProperty("BackgroundRangeStart", EMPTY_DBL(), "Start Point of Range 2",
Direction::Input);
declareProperty("Range2End", EMPTY_DBL(), "End Point of Range 2.",
declareProperty("BackgroundRangeEnd", EMPTY_DBL(), "End Point of Range 2.",
Direction::Input);
}

void ElasticWindow::exec() {
MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");

double enR1S = getProperty("Range1Start");
double enR1E = getProperty("Range1End");
double enR2S = getProperty("Range2Start");
double enR2E = getProperty("Range2End");
double intRangeStart = getProperty("IntegrationRangeStart");
double intRangeEnd = getProperty("IntegrationRangeEnd");
double bgRangeStart = getProperty("BackgroundRangeStart");
double bgRangeEnd = getProperty("BackgroundRangeEnd");

// Create the output workspaces
MatrixWorkspace_sptr integWS;
Expand All @@ -62,7 +62,7 @@ void ElasticWindow::exec() {

// Determine if we need to use the second time range...
const bool backgroundSubtraction =
!((enR2S == enR2E) && (enR2S == EMPTY_DBL()));
!((bgRangeStart == bgRangeEnd) && (bgRangeStart == EMPTY_DBL()));
g_log.information() << "Use background subtraction: " << backgroundSubtraction
<< std::endl;

Expand All @@ -80,8 +80,8 @@ void ElasticWindow::exec() {
IAlgorithm_sptr flatBG = createChildAlgorithm(
"CalculateFlatBackground", startProgress, endProgress, childAlgLogging);
flatBG->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWorkspace);
flatBG->setProperty<double>("StartX", enR2S);
flatBG->setProperty<double>("EndX", enR2E);
flatBG->setProperty<double>("StartX", bgRangeStart);
flatBG->setProperty<double>("EndX", bgRangeEnd);
flatBG->setPropertyValue("Mode", "Mean");
flatBG->setPropertyValue("OutputWorkspace", "flatBG");
flatBG->execute();
Expand All @@ -93,8 +93,8 @@ void ElasticWindow::exec() {
IAlgorithm_sptr integ = createChildAlgorithm("Integration", startProgress,
endProgress, childAlgLogging);
integ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", flatBGws);
integ->setProperty<double>("RangeLower", enR1S);
integ->setProperty<double>("RangeUpper", enR1E);
integ->setProperty<double>("RangeLower", intRangeStart);
integ->setProperty<double>("RangeUpper", intRangeEnd);
integ->setPropertyValue("OutputWorkspace", "integ");
integ->execute();

Expand All @@ -104,8 +104,8 @@ void ElasticWindow::exec() {
IAlgorithm_sptr integ = createChildAlgorithm("Integration", startProgress,
endProgress, childAlgLogging);
integ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWorkspace);
integ->setProperty<double>("RangeLower", enR1S);
integ->setProperty<double>("RangeUpper", enR1E);
integ->setProperty<double>("RangeLower", intRangeStart);
integ->setProperty<double>("RangeUpper", intRangeEnd);
integ->setPropertyValue("OutputWorkspace", "integ");
integ->execute();

Expand Down
16 changes: 8 additions & 8 deletions Code/Mantid/Framework/Algorithms/test/ElasticWindowTest.h
Expand Up @@ -109,8 +109,8 @@ class ElasticWindowTest : public CxxTest::TestSuite
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeStart", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeEnd", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

Expand All @@ -133,8 +133,8 @@ class ElasticWindowTest : public CxxTest::TestSuite
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeStart", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeEnd", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

Expand All @@ -154,10 +154,10 @@ class ElasticWindowTest : public CxxTest::TestSuite
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range2Start", 0.05) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range2End", 0.06) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeStart", -0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("IntegrationRangeEnd", 0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("BackgroundRangeStart", 0.05) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("BackgroundRangeEnd", 0.06) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

Expand Down
Expand Up @@ -25,15 +25,16 @@ class ElasticWindowMultiple(DataProcessorAlgorithm):

_plot = None
_sample_log_name = None
_sample_log_value = None
_input_workspaces = None
_q_workspace = None
_q2_workspace = None
_elf_workspace = None
_elt_workspace = None
_range_1_start = None
_range_1_end = None
_range_2_start = None
_range_2_end = None
_integration_range_start = None
_integration_range_end = None
_background_range_start = None
_background_range_end = None
_mtd_plot = None

def category(self):
Expand All @@ -48,11 +49,11 @@ def PyInit(self):
self.declareProperty(WorkspaceGroupProperty('InputWorkspaces', '', Direction.Input),
doc='Grouped input workspaces')

self.declareProperty(name='Range1Start', defaultValue=0.0, doc='Range 1 start')
self.declareProperty(name='Range1End', defaultValue=0.0, doc='Range 1 end')
self.declareProperty(name='IntegrationRangeStart', defaultValue=0.0, doc='Range 1 start')
self.declareProperty(name='IntegrationRangeEnd', defaultValue=0.0, doc='Range 1 end')

self.declareProperty(name='Range2Start', defaultValue='', doc='Range 2 start')
self.declareProperty(name='Range2End', defaultValue='', doc='Range 2 end')
self.declareProperty(name='BackgroundRangeStart', defaultValue='', doc='Range 2 start')
self.declareProperty(name='BackgroundRangeEnd', defaultValue='', doc='Range 2 end')

self.declareProperty(name='SampleEnvironmentLogName', defaultValue='sample',
doc='Name of the sample environment log entry')
Expand Down Expand Up @@ -82,26 +83,26 @@ def PyInit(self):
def validateInputs(self):
issues = dict()

range_2_start = self.getPropertyValue('Range2Start')
range_2_end = self.getPropertyValue('Range2End')
range_2_start = self.getPropertyValue('BackgroundRangeStart')
range_2_end = self.getPropertyValue('BackgroundRangeEnd')

if range_2_start != '' and range_2_end == '':
issues['Range2End'] = 'If range 2 start was given and range 2 end must also be provided.'
issues['BackgroundRangeEnd'] = 'If range 2 start was given and range 2 end must also be provided.'

if range_2_start == '' and range_2_end != '':
issues['Range2Start'] = 'If range 2 end was given and range 2 start must also be provided.'
issues['BackgroundRangeStart'] = 'If range 2 end was given and range 2 start must also be provided.'

if range_2_start != '':
try:
_ = float(range_2_start)
except ValueError:
issues['Range2Start'] = 'Range 2 start is not a double number'
issues['BackgroundRangeStart'] = 'Range 2 start is not a double number'

if range_2_end != '':
try:
_ = float(range_2_end)
except ValueError:
issues['Range2End'] = 'Range 2 end is not a double number'
issues['BackgroundRangeEnd'] = 'Range 2 end is not a double number'

This comment has been minimized.

Copy link
@raquelalvarezbanos

raquelalvarezbanos Jun 2, 2015

Contributor

Would it make sense to rename ranges here as well? I guess the above messages are visible to the user...

return issues

Expand Down Expand Up @@ -131,18 +132,23 @@ def PyExec(self):
q_ws = '__' + input_ws + '_q'
q2_ws = '__' + input_ws + '_q2'

if self._range_2_start != '' and self._range_2_end != '':
if self._background_range_start != '' and self._background_range_end != '':
ElasticWindow(InputWorkspace=input_ws,
OutputInQ=q_ws, OutputInQSquared=q2_ws,
Range1Start=self._range_1_start,
Range1End=self._range_1_end,
Range2Start=float(self._range_2_start),
Range2End=float(self._range_2_end))
OutputInQ=q_ws,
OutputInQSquared=q2_ws,
IntegrationRangeStart=self._integration_range_start,
IntegrationRangeEnd=self._integration_range_end,
BackgroundRangeStart=float(self._background_range_start),
BackgroundRangeEnd=float(self._background_range_end))
else:
ElasticWindow(InputWorkspace=input_ws, OutputInQ=q_ws, OutputInQSquared=q2_ws,
Range1Start=self._range_1_start, Range1End=self._range_1_end)
ElasticWindow(InputWorkspace=input_ws,
OutputInQ=q_ws,
OutputInQSquared=q2_ws,
IntegrationRangeStart=self._integration_range_start,
IntegrationRangeEnd=self._integration_range_end)

Logarithm(InputWorkspace=q2_ws, OutputWorkspace=q2_ws)
Logarithm(InputWorkspace=q2_ws,
OutputWorkspace=q2_ws)

q_workspaces.append(q_ws)
q2_workspaces.append(q2_ws)
Expand All @@ -163,13 +169,17 @@ def PyExec(self):

if len(input_workspace_names) == 1:
# Just rename single workspaces
RenameWorkspace(InputWorkspace=q_workspaces[0], OutputWorkspace=self._q_workspace)
RenameWorkspace(InputWorkspace=q2_workspaces[0], OutputWorkspace=self._q2_workspace)
RenameWorkspace(InputWorkspace=q_workspaces[0],
OutputWorkspace=self._q_workspace)
RenameWorkspace(InputWorkspace=q2_workspaces[0],
OutputWorkspace=self._q2_workspace)
else:
# Append the spectra of the first two workspaces
AppendSpectra(InputWorkspace1=q_workspaces[0], InputWorkspace2=q_workspaces[1],
AppendSpectra(InputWorkspace1=q_workspaces[0],
InputWorkspace2=q_workspaces[1],
OutputWorkspace=self._q_workspace)
AppendSpectra(InputWorkspace1=q2_workspaces[0], InputWorkspace2=q2_workspaces[1],
AppendSpectra(InputWorkspace1=q2_workspaces[0],
InputWorkspace2=q2_workspaces[1],
OutputWorkspace=self._q2_workspace)

# Append to the spectra of each remaining workspace
Expand Down Expand Up @@ -218,8 +228,10 @@ def PyExec(self):
if self._elf_workspace != '':
logger.information('Creating ELF workspace')

Transpose(InputWorkspace=self._q_workspace, OutputWorkspace=self._elf_workspace)
SortXAxis(InputWorkspace=self._elf_workspace, OutputWorkspace=self._elf_workspace)
Transpose(InputWorkspace=self._q_workspace,
OutputWorkspace=self._elf_workspace)
SortXAxis(InputWorkspace=self._elf_workspace,
OutputWorkspace=self._elf_workspace)

self.setProperty('OutputELF', self._elf_workspace)

Expand All @@ -230,8 +242,10 @@ def PyExec(self):
# If the ELT workspace was not already created then create it here,
# otherwise just clone it
if self._elf_workspace == '':
Transpose(InputWorkspace=self._q_workspace, OutputWorkspace=self._elt_workspace)
SortXAxis(InputWorkspace=self._elt_workspace, OutputWorkspace=self._elt_workspace)
Transpose(InputWorkspace=self._q_workspace,
OutputWorkspace=self._elt_workspace)
SortXAxis(InputWorkspace=self._elt_workspace,
OutputWorkspace=self._elt_workspace)
else:
CloneWorkspace(InputWorkspace=self._elf_workspace,
OutputWorkspace=self._elt_workspace)
Expand Down Expand Up @@ -273,11 +287,11 @@ def _setup(self):
self._elf_workspace = self.getPropertyValue('OutputELF')
self._elt_workspace = self.getPropertyValue('OutputELT')

self._range_1_start = self.getProperty('Range1Start').value
self._range_1_end = self.getProperty('Range1End').value
self._integration_range_start = self.getProperty('IntegrationRangeStart').value
self._integration_range_end = self.getProperty('IntegrationRangeEnd').value

self._range_2_start = self.getPropertyValue('Range2Start')
self._range_2_end = self.getPropertyValue('Range2End')
self._background_range_start = self.getPropertyValue('BackgroundRangeStart')
self._background_range_end = self.getPropertyValue('BackgroundRangeEnd')


def _plot_spectra(self, ws_name):
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Elwin.cpp
Expand Up @@ -148,13 +148,13 @@ namespace IDA
elwinMultAlg->setProperty("SampleEnvironmentLogName", m_uiForm.leLogName->text().toStdString());
elwinMultAlg->setProperty("SampleEnvironmentLogValue", m_uiForm.leLogValue->currentText().toStdString());

elwinMultAlg->setProperty("Range1Start", m_dblManager->value(m_properties["IntegrationStart"]));
elwinMultAlg->setProperty("Range1End", m_dblManager->value(m_properties["IntegrationEnd"]));
elwinMultAlg->setProperty("IntegrationRangeStart", m_dblManager->value(m_properties["IntegrationStart"]));
elwinMultAlg->setProperty("IntegrationRangeEnd", m_dblManager->value(m_properties["IntegrationEnd"]));

if(m_blnManager->value(m_properties["BackgroundSubtraction"]))
{
elwinMultAlg->setProperty("Range2Start", boost::lexical_cast<std::string>(m_dblManager->value(m_properties["BackgroundStart"])));
elwinMultAlg->setProperty("Range2End", boost::lexical_cast<std::string>(m_dblManager->value(m_properties["BackgroundEnd"])));
elwinMultAlg->setProperty("BackgroundRangeStart", boost::lexical_cast<std::string>(m_dblManager->value(m_properties["BackgroundStart"])));
elwinMultAlg->setProperty("BackgroundRangeEnd", boost::lexical_cast<std::string>(m_dblManager->value(m_properties["BackgroundEnd"])));
}

if(m_blnManager->value(m_properties["Normalise"]))
Expand Down
Expand Up @@ -10,10 +10,10 @@ def runTest(self):
OutputWorkspace='__ElWinMulti_InputWS')

ElasticWindowMultiple(InputWorkspaces='__ElWinMulti_InputWS',
Range1Start=-0.2,
Range1End=0.2,
Range2Start='-0.24',
Range2End='-0.22',
IntegrationRangeStart=-0.2,
IntegrationRangeEnd=0.2,
BackgroundRangeStart='-0.24',
BackgroundRangeEnd='-0.22',
OutputInQ='eq',
OutputInQSquared='eq2',
OutputELF='elf',
Expand Down
Expand Up @@ -742,7 +742,7 @@ def _run(self):
GroupWorkspaces(InputWorkspaces=self.files, OutputWorkspace=elwin_input)

ElasticWindowMultiple(InputWorkspaces=elwin_input, Plot=False,
Range1Start=self.eRange[0], Range1End=self.eRange[1],
IntegrationRangeStart=self.eRange[0], IntegrationRangeEnd=self.eRange[1],
OutputInQ=elwin_results[0], OutputInQSquared=elwin_results[1],
OutputELF=elwin_results[2])

Expand Down

0 comments on commit 012a1ae

Please sign in to comment.