Skip to content

Commit

Permalink
Small Symmetrise improvements, added validation checks to unit test
Browse files Browse the repository at this point in the history
Refs #7860
  • Loading branch information
DanNixon committed Sep 22, 2014
1 parent 7efc8f6 commit 79a58fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Expand Up @@ -53,13 +53,26 @@ def PyExec(self):
len_x = len(mtd[self._sample].readX(0))
len_y = len(mtd[self._sample].readY(0))
len_e = len(mtd[self._sample].readE(0))
sample_array_len = min(len_x, len_y, len_e) - 1
sample_array_len = min(len_x, len_y, len_e)

sample_x = mtd[self._sample].readX(0)

if self._x_max > sample_x[len(sample_x) - 1]:
raise ValueError('XMax value (%f) is greater than largest X value (%f)' %
(self._x_max, sample_x[len(sample_x) - 1]))

if self._x_min < sample_x[0]:
raise ValueError('XMin value (%f) is less than smallest X value (%f)' %
(self._x_min, sample_x[0]))

self._calculate_array_points(sample_x, sample_array_len)

output_cut_index = sample_array_len - self._positive_min_index - (sample_array_len - self._positive_max_index)
new_array_len = 2 * sample_array_len - (self._positive_min_index + self._negative_min_index) - 2 * (sample_array_len - self._positive_max_index)
max_sample_index = sample_array_len - 1
centre_range_len = self._positive_min_index + self._negative_min_index
posiive_diff_range_len = max_sample_index - self._positive_max_index

output_cut_index = max_sample_index - self._positive_min_index - posiive_diff_range_len
new_array_len = 2 * max_sample_index - centre_range_len - 2 * posiive_diff_range_len

if self._verbose:
logger.notice('Sample array length = %d' % sample_array_len)
Expand Down Expand Up @@ -96,9 +109,9 @@ def PyExec(self):
spectrum_index = mtd[self._sample].getIndexFromSpectrumNumber(spectrum_no)

# Strip any additional array cells
x_in = mtd[self._sample].readX(spectrum_index)[:sample_array_len + 1]
y_in = mtd[self._sample].readY(spectrum_index)[:sample_array_len + 1]
e_in = mtd[self._sample].readE(spectrum_index)[:sample_array_len + 1]
x_in = mtd[self._sample].readX(spectrum_index)[:sample_array_len]
y_in = mtd[self._sample].readY(spectrum_index)[:sample_array_len]
e_in = mtd[self._sample].readE(spectrum_index)[:sample_array_len]

# Get some zeroed data to overwrite with copies from sample
x_out = np.zeros(new_array_len)
Expand Down Expand Up @@ -203,7 +216,8 @@ def _calculate_array_points(self, sample_x, sample_array_len):

# Find array index of positive XMax
positive_max_diff = np.absolute(sample_x - self._x_max)
self._positive_max_index = np.where(positive_max_diff < delta_x)[0][-1]
indicies = np.where(positive_max_diff < delta_x)[0]
self._positive_max_index = indicies[-1]
self._check_bounds(self._positive_max_index, sample_array_len, label='Positive')

def _check_bounds(self, index, num_pts, label=''):
Expand All @@ -228,13 +242,9 @@ def _generate_props_table(self):

props_table.addColumn('int', 'NegativeXMinIndex')
props_table.addColumn('int', 'PositiveXMinIndex')
props_table.addColumn('int', 'NegativeXMaxIndex')
props_table.addColumn('int', 'PositiveXMaxIndex')

if self._negative_max_index is None:
props_table.addRow([self._negative_min_index, self._positive_min_index, -1, self._positive_max_index])
else:
props_table.addRow([self._negative_min_index, self._positive_min_index, self._negative_max_index, self._positive_max_index])
props_table.addRow([self._negative_min_index, self._positive_min_index, self._positive_max_index])

self.setProperty('OutputPropertiesTable', self._props_output_workspace)

Expand Down
Expand Up @@ -10,7 +10,19 @@ def setUp(self):
self._sample_ws = self._generate_sample_ws('symm_test_sample_ws')

def test_basic(self):
symm_test_out_ws= Symmetrise(Sample=self._sample_ws, XMin=0.05, XMax=0.2)
symm_test_out_ws = Symmetrise(Sample=self._sample_ws, XMin=0.05, XMax=0.2)

def test_failure_lower_range(self):
"""
Tests validation on entering an XMin value lower than the smallest value in the X range.
"""
self.assertRaises(RuntimeError, Symmetrise, Sample=self._sample_ws, OutputWOrkspace='__Symmetrise_TestWS', XMin=-5, XMax=0.2)

def test_failure_upper_range(self):
"""
Tests validation on entering an XMax value greater than the largest value in the X range.
"""
self.assertRaises(RuntimeError, Symmetrise, Sample=self._sample_ws, OutputWOrkspace='__Symmetrise_TestWS', XMin=0.05, XMax=15)

def _rayleigh(self, x, sigma):
return (x / sigma ** 2) * np.exp(-x ** 2 / (2 * sigma ** 2))
Expand Down
Expand Up @@ -24,6 +24,8 @@ namespace CustomInterfaces
IndirectSymmetrise::IndirectSymmetrise(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
IndirectDataReductionTab(uiForm, parent)
{
int numDecimals = 6;

// Property Trees
m_propTrees["SymmPropTree"] = new QtTreePropertyBrowser();
m_uiForm.symm_properties->addWidget(m_propTrees["SymmPropTree"]);
Expand All @@ -37,8 +39,10 @@ namespace CustomInterfaces

// Raw Properties
m_properties["EMin"] = m_dblManager->addProperty("EMin");
m_dblManager->setDecimals(m_properties["EMin"], numDecimals);
m_propTrees["SymmPropTree"]->addProperty(m_properties["EMin"]);
m_properties["EMax"] = m_dblManager->addProperty("EMax");
m_dblManager->setDecimals(m_properties["EMax"], numDecimals);
m_propTrees["SymmPropTree"]->addProperty(m_properties["EMax"]);

QtProperty* rawPlotProps = m_grpManager->addProperty("Raw Plot");
Expand All @@ -54,12 +58,15 @@ namespace CustomInterfaces
// Preview Properties
// Mainly used for display rather than getting user input
m_properties["NegativeYValue"] = m_dblManager->addProperty("Negative Y");
m_dblManager->setDecimals(m_properties["NegativeYValue"], numDecimals);
m_propTrees["SymmPVPropTree"]->addProperty(m_properties["NegativeYValue"]);

m_properties["PositiveYValue"] = m_dblManager->addProperty("Positive Y");
m_dblManager->setDecimals(m_properties["PositiveYValue"], numDecimals);
m_propTrees["SymmPVPropTree"]->addProperty(m_properties["PositiveYValue"]);

m_properties["DeltaY"] = m_dblManager->addProperty("Delta Y");
m_dblManager->setDecimals(m_properties["DeltaY"], numDecimals);
m_propTrees["SymmPVPropTree"]->addProperty(m_properties["DeltaY"]);

// Raw plot
Expand Down

0 comments on commit 79a58fb

Please sign in to comment.