Skip to content
Snippets Groups Projects
Commit 330205e3 authored by Peter Parker's avatar Peter Parker
Browse files

Merge remote-tracking branch 'origin/feature/9171_stitch1d_limit'

parents b4295c0a 36689270
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,9 @@ class Stitch1D(PythonAlgorithm):
def name(self):
return "Stitch1D"
def version(self):
return 3
def PyInit(self):
......@@ -88,8 +91,11 @@ class Stitch1D(PythonAlgorithm):
def __get_start_overlap(self, range_tolerance):
start_overlap_property = self.getProperty('StartOverlap')
start_overlap = start_overlap_property.value - range_tolerance
if start_overlap_property.isDefault:
min, max = self.__calculate_x_intersection()
min, max = self.__calculate_x_intersection()
start_overlap_beyond_range = (start_overlap < min) or (start_overlap > max)
if start_overlap_property.isDefault or start_overlap_beyond_range:
if start_overlap_beyond_range and not start_overlap_property.isDefault:
logger.warning("StartOverlap is outside range at %0.4f, Min is %0.4f, Max is %0.4f . Forced to be: %0.4f" % (start_overlap, min, max, min))
start_overlap = min
logger.information("StartOverlap calculated to be: %0.4f" % start_overlap)
return start_overlap
......@@ -97,8 +103,11 @@ class Stitch1D(PythonAlgorithm):
def __get_end_overlap(self, range_tolerance):
end_overlap_property = self.getProperty('EndOverlap')
end_overlap = end_overlap_property.value + range_tolerance
if end_overlap_property.isDefault:
min, max = self.__calculate_x_intersection()
min, max = self.__calculate_x_intersection()
end_overlap_beyond_range = (end_overlap < min) or (end_overlap > max)
if end_overlap_property.isDefault or end_overlap_beyond_range:
if end_overlap_beyond_range and not end_overlap_property.isDefault:
logger.warning("EndOverlap is outside range at %0.4f, Min is %0.4f, Max is %0.4f. Forced to be: %0.4f" % (end_overlap, min, max, max))
end_overlap = max
logger.information("EndOverlap calculated to be: %0.4f" % end_overlap)
return end_overlap
......@@ -133,7 +142,7 @@ class Stitch1D(PythonAlgorithm):
outScaleFactor = self.getProperty('OutScaleFactor').value
params = self.__create_rebin_parameters()
print params
lhs_rebinned = self.__run_as_child("Rebin", InputWorkspace=self.getProperty("LHSWorkspace").value, Params=params)
rhs_rebinned = self.__run_as_child("Rebin", InputWorkspace=self.getProperty("RHSWorkspace").value, Params=params)
......@@ -146,7 +155,7 @@ class Stitch1D(PythonAlgorithm):
raise RuntimeError("Stitch1D EndOverlap is outside the X range after rebinning. EndOverlap: %0.9f, X max: %0.9f" % (endOverlap, maxX))
if(startOverlap > endOverlap):
raise RuntimeError("Stitch1D cannot have a StartOverlap > EndOverlap")
raise RuntimeError("Stitch1D cannot have a StartOverlap > EndOverlap. StartOverlap: %0.9f, EndOverlap: %0.9f" % (startOverlap, endOverlap))
a1, a2 = self.__find_indexes_start_end(startOverlap, endOverlap, lhs_rebinned)
......
......@@ -195,7 +195,7 @@ class ReflectometryReductionOneBaseTest(object):
alg.set_FirstTransmissionRun(trans_run1)
alg.set_SecondTransmissionRun(trans_run2)
alg.set_Params([1.5, 0.02, 17])
alg.set_Params([0.0, 0.02, 5])
alg.set_StartOverlap( 10.0 )
alg.set_EndOverlap( 12.0 )
alg.set_ThetaIn(0.2)
......
......@@ -27,20 +27,6 @@ class Stitch1DTest(unittest.TestCase):
DeleteWorkspace(self.a)
DeleteWorkspace(self.b)
def test_endoverap_outside_range_throws(self):
try:
stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=self.x[0], EndOverlap=self.x[-1] + 0.001, Params='0.2')
self.assertTrue(False, "Should have thrown with EndOverlap > x max")
except RuntimeError:
pass
def test_startoverap_outside_range_throws(self):
try:
stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=self.x[0]-0.001, EndOverlap=self.x[-1], Params='0.2')
self.assertTrue(False, "Should have thrown with StartOverlap < x max")
except RuntimeError:
pass
def test_startoverap_greater_than_end_overlap_throws(self):
try:
stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=self.x[-1], EndOverlap=self.x[0], Params='0.2')
......@@ -110,6 +96,7 @@ class Stitch1DTest(unittest.TestCase):
DeleteWorkspace(stitched)
DeleteWorkspace(ws1)
DeleteWorkspace(ws2)
def test_stitching_determines_start_and_end_overlap(self):
x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2
......@@ -130,6 +117,50 @@ class Stitch1DTest(unittest.TestCase):
print start_overlap_determined, end_overlap_determined
self.assertAlmostEqual(start_overlap_determined, -0.4, places=9)
self.assertAlmostEqual(end_overlap_determined, 0.2, places=9)
def test_stitching_forces_start_overlap(self):
x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2
x2 = numpy.arange(-0.4, 1.2, 0.2) # Produces x from -0.4 to 1 in steps of 0.2
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,3,3,3,3], NSpec=1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,3,3,3], NSpec=1)
# Overlap region is only physically between -0.4 and 0.4
stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, Params=[-1, 0.2, 1], StartOverlap=-0.5) # Start overlap is out of range!!
stitched_y = stitched.readY(0)
stitched_x = stitched.readX(0)
overlap_indexes = numpy.where((stitched_y >= 1.0009) & (stitched_y <= 3.0001))[0]
start_overlap_determined = stitched_x[overlap_indexes[0]]
end_overlap_determined = stitched_x[overlap_indexes[-1]]
print start_overlap_determined, end_overlap_determined
self.assertAlmostEqual(start_overlap_determined, -0.4, places=9)
self.assertAlmostEqual(end_overlap_determined, 0.2, places=9)
def test_stitching_forces_end_overlap(self):
x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2
x2 = numpy.arange(-0.4, 1.2, 0.2) # Produces x from -0.4 to 1 in steps of 0.2
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,3,3,3,3], NSpec=1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,3,3,3], NSpec=1)
# Overlap region is only physically between -0.4 and 0.4
stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, Params=[-1, 0.2, 1], EndOverlap=0.5) # End overlap is out of range!!
stitched_y = stitched.readY(0)
stitched_x = stitched.readX(0)
overlap_indexes = numpy.where((stitched_y >= 1.0009) & (stitched_y <= 3.0001))[0]
start_overlap_determined = stitched_x[overlap_indexes[0]]
end_overlap_determined = stitched_x[overlap_indexes[-1]]
print start_overlap_determined, end_overlap_determined
self.assertAlmostEqual(start_overlap_determined, -0.4, places=9)
self.assertAlmostEqual(end_overlap_determined, 0.2, places=9)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment