Skip to content

Commit

Permalink
Refactoring, restrict IDR UI to reduced files/ws
Browse files Browse the repository at this point in the history
Refs #7860
  • Loading branch information
DanNixon committed Sep 3, 2014
1 parent 9801cb6 commit de5e537
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
Expand Up @@ -36,7 +36,7 @@ def PyExec(self):

StartTime('Symmetrise')
self._setup()
num_spectra, num_pts = CheckHistZero(self._sample)
num_spectra, sample_aray_len = CheckHistZero(self._sample)
sample_x = mtd[self._sample].readX(0)

if math.fabs(self._x_cut) < 1e-5:
Expand All @@ -47,28 +47,29 @@ def PyExec(self):

negative_diff = np.absolute(sample_x + self._x_cut)
negative_index = np.where(negative_diff < delta_x)[0][-1]
self._check_bounds(negative_index, num_pts, label='Negative')
self._check_bounds(negative_index, sample_aray_len, label='Negative')

positive_diff = np.absolute(sample_x + sample_x[negative_index])
positive_index = np.where(positive_diff < delta_x)[0][-1]
self._check_bounds(positive_index, num_pts, label='Positive')
self._check_bounds(positive_index, sample_aray_len, label='Positive')

new_data_size = 2 * num_pts - (positive_index + negative_index) + 1
new_array_len = 2 * sample_aray_len - (positive_index + negative_index) + 1

if self._verbose:
logger.notice('No. points = %d' % num_pts)
logger.notice('No. points = %d' % sample_aray_len)
logger.notice('Negative : at i =%d; x = %f'
% (negative_index, sample_x[negative_index]))
logger.notice('Positive : at i =%d; x = %f'
% (positive_index, sample_x[positive_index]))
logger.notice('New array size = %d' % new_array_len)

zeros = np.zeros(new_data_size * num_spectra)
zeros = np.zeros(new_array_len * num_spectra)
CreateWorkspace(OutputWorkspace=self._output_workspace,
DataX=zeros, DataY=zeros, DataE=zeros,
NSpec=num_spectra)

CopyLogs(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)
# CopyInstrumentParameters(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)
CopyInstrumentParameters(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)
# CopySample(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)

# For each spectrum copy positive values to the negative
Expand All @@ -77,24 +78,27 @@ def PyExec(self):
y_in = mtd[self._sample].readY(index)
e_in = mtd[self._sample].readE(index)

x_out = np.zeros(new_data_size)
y_out = np.zeros(new_data_size)
e_out = np.zeros(new_data_size)
x_out = np.zeros(new_array_len)
y_out = np.zeros(new_array_len)
e_out = np.zeros(new_array_len)

# Left hand side of cut
x_out[:num_pts - positive_index] = -x_in[num_pts:positive_index:-1]
y_out[:num_pts - positive_index] = y_in[num_pts:positive_index:-1]
e_out[:num_pts - positive_index] = e_in[num_pts:positive_index:-1]
x_out[:sample_aray_len - positive_index] = -x_in[sample_aray_len:positive_index:-1]
y_out[:sample_aray_len - positive_index] = y_in[sample_aray_len:positive_index:-1]
e_out[:sample_aray_len - positive_index] = e_in[sample_aray_len:positive_index:-1]

# Right hand side of cut
x_out[num_pts - positive_index:] = x_in[negative_index:]
y_out[num_pts - positive_index:] = y_in[negative_index:]
e_out[num_pts - positive_index:] = e_in[negative_index:]
x_out[sample_aray_len - positive_index:] = x_in[negative_index:]
y_out[sample_aray_len - positive_index:] = y_in[negative_index:]
e_out[sample_aray_len - positive_index:] = e_in[negative_index:]

mtd[self._output_workspace].setX(index, x_out)
mtd[self._output_workspace].setY(index, y_out)
mtd[self._output_workspace].setE(index, e_out)

logger.information('Spectra %d out of %d done'
% (index, num_spectra))

if self._save:
self._save_output()

Expand Down Expand Up @@ -149,8 +153,8 @@ def _plot_output(self):
Plot the first spectrum of the input and output workspace together.
"""
from IndirectImport import import_mantidplot
mp = import_mantidplot()
mp.plotSpectrum([self._output_workspace, self._sample], 0)
mtd_plot = import_mantidplot()
mtd_plot.plotSpectrum([self._output_workspace, self._sample], 0)

# Register algorithm with Mantid
AlgorithmFactory.subscribe(Symmetrise)
Expand Up @@ -1757,6 +1757,12 @@ Later steps in the process (saving, renaming) will not be done.</string>
<property name="showLoad" stdset="0">
<bool>false</bool>
</property>
<property name="workspaceSuffixes" stdset="0">
<string>_red</string>
</property>
<property name="fileBrowserSuffixes" stdset="0">
<string>_red.nxs</string>
</property>
</widget>
</item>
</layout>
Expand Down
Expand Up @@ -47,8 +47,8 @@ namespace CustomInterfaces
m_plots["SymmRawPlot"] = new QwtPlot(m_parentWidget);
m_curves["SymmRawPlot"] = new QwtPlotCurve();

m_rangeSelectors["NegativeXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE);
m_rangeSelectors["PositiveXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE);
m_rangeSelectors["NegativeXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE, true, false);
m_rangeSelectors["PositiveXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE, true, false);

m_rangeSelectors["CentreMark"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"],
MantidWidgets::RangeSelector::XSINGLE, true, true);
Expand Down Expand Up @@ -78,14 +78,14 @@ namespace CustomInterfaces
std::pair<double, double> defaultRange(-1.0, 1.0);
setAxisRange("SymmRawPlot", QwtPlot::xBottom, defaultRange);
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
IndirectSymmetrise::~IndirectSymmetrise()
{
}

void IndirectSymmetrise::setup()
{
}
Expand Down

0 comments on commit de5e537

Please sign in to comment.