Skip to content

Commit

Permalink
Edited algo to act as intended
Browse files Browse the repository at this point in the history
Refs #7860
  • Loading branch information
DanNixon committed Sep 3, 2014
1 parent 1267f5a commit a134ee0
Showing 1 changed file with 30 additions and 20 deletions.
@@ -1,7 +1,7 @@
from mantid import logger, mtd
from mantid.api import PythonAlgorithm, AlgorithmFactory, WorkspaceProperty
from mantid.kernel import Direction
from mantid.simpleapi import CloneWorkspace, SaveNexusProcessed
from mantid.simpleapi import CreateWorkspace, CopyLogs, CopySample, CopyInstrumentParameters, SaveNexusProcessed

import math
import os.path
Expand Down Expand Up @@ -42,7 +42,7 @@ def PyExec(self):
if math.fabs(self._x_cut) < 1e-5:
raise ValueError('XCut point is Zero')

# find range of values to flip
# Find range of values to flip
delta_x = sample_x[1] - sample_x[0]

negative_diff = np.absolute(sample_x - self._x_cut)
Expand All @@ -53,33 +53,43 @@ def PyExec(self):
positive_index = np.where(positive_diff < delta_x)[0][-1]
self._check_bounds(positive_index, num_pts, label='Positive')

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

if self._verbose:
logger.notice('No. points = %d' % num_pts)
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]))

CloneWorkspace(InputWorkspace=self._sample,
OutputWorkspace=self._output_workspace)

# for each spectrum copy positive values to the negative
for index in xrange(num_spectra):
x_in = mtd[self._output_workspace].readX(index)
y_in = mtd[self._output_workspace].readY(index)
e_in = mtd[self._output_workspace].readE(index)
zeros = np.zeros(new_data_size * num_spectra)
CreateWorkspace(OutputWorkspace=self._output_workspace,
DataX=zeros, DataY=zeros, DataE=zeros,
NSpec=num_spectra)

x_out = np.zeros(x_in.size)
y_out = np.zeros(y_in.size)
e_out = np.zeros(e_in.size)
CopyLogs(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)
# CopyInstrumentParameters(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)
# CopySample(InputWorkspace=self._sample, OutputWorkspace=self._output_workspace)

x_out[:positive_index] = -x_in[negative_index + positive_index:negative_index:-1]
y_out[:positive_index] = y_in[negative_index + positive_index:negative_index:-1]
e_out[:positive_index] = e_in[negative_index + positive_index:negative_index:-1]

x_out[positive_index:] = x_in[positive_index:]
y_out[positive_index:] = y_in[positive_index:]
e_out[positive_index:] = e_in[positive_index:]
# For each spectrum copy positive values to the negative
for index in xrange(num_spectra):
x_in = mtd[self._sample].readX(index)
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)

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

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

mtd[self._output_workspace].setX(index, x_out)
mtd[self._output_workspace].setY(index, y_out)
Expand Down

0 comments on commit a134ee0

Please sign in to comment.