Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python and Numpy binary variants #1765

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Wrappers/Python/test/test_DataProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand All @@ -606,21 +606,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand Down Expand Up @@ -1343,21 +1343,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand All @@ -1375,21 +1375,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand Down Expand Up @@ -1770,7 +1770,7 @@ def test_process_acquisition_geometry(self):
proc.set_input(geometry)
geometry_padded = proc._process_acquisition_geometry()

self.assertEquals(geometry_padded, self.ag_padded,
self.assertEqual(geometry_padded, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ag_padded))


Expand All @@ -1784,7 +1784,7 @@ def test_process_acquisition_geometry(self):
0., 90., 180., 270.,\
360., 450., 540., 630., 720.]

self.assertEquals(geometry_padded, geometry_gold,
self.assertEqual(geometry_padded, geometry_gold,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, geometry_gold))


Expand All @@ -1795,7 +1795,7 @@ def test_process_acquisition_geometry_origin(self):
proc.set_input(geometry)
geometry_padded = proc._process_acquisition_geometry()

self.assertEquals(geometry_padded, self.ag2_padded,
self.assertEqual(geometry_padded, self.ag2_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ag2_padded))


Expand All @@ -1807,7 +1807,7 @@ def test_process_image_geometry(self):
proc.set_input(geometry)
geometry_padded = proc._process_image_geometry()

self.assertEquals(geometry_padded, self.ig_padded,
self.assertEqual(geometry_padded, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ig_padded))


Expand Down Expand Up @@ -1846,21 +1846,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, self.ag_padded,
self.assertEqual(geometry_out, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, self.ag_padded))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ag_padded,
self.assertEqual(data_out.geometry, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ag_padded))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ag_padded,
self.assertEqual(data_out.geometry, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ag_padded))


Expand All @@ -1880,21 +1880,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, self.ig_padded,
self.assertEqual(geometry_out, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, self.ig_padded))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ig_padded,
self.assertEqual(data_out.geometry, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ig_padded))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ig_padded,
self.assertEqual(data_out.geometry, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ig_padded))


Expand Down
12 changes: 6 additions & 6 deletions Wrappers/Python/test/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ def test_PDHG_strongly_convex_gamma_g(self):
pdhg = PDHG(f=f, g=g, operator=operator, sigma = sigma, tau=tau,
max_iteration=5, gamma_g=0.5)
pdhg.run(1, verbose=0)
self.assertAlmostEquals(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_g * tau))
self.assertAlmostEquals(pdhg.tau, tau * pdhg.theta)
self.assertAlmostEquals(pdhg.sigma, sigma / pdhg.theta)
self.assertAlmostEqual(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_g * tau))
self.assertAlmostEqual(pdhg.tau, tau * pdhg.theta)
self.assertAlmostEqual(pdhg.sigma, sigma / pdhg.theta)
pdhg.run(4, verbose=0)
self.assertNotEqual(pdhg.sigma, sigma)
self.assertNotEqual(pdhg.tau, tau)
Expand Down Expand Up @@ -555,9 +555,9 @@ def test_PDHG_strongly_convex_gamma_fcong(self):
pdhg = PDHG(f=f, g=g, operator=operator, sigma = sigma, tau=tau,
max_iteration=5, gamma_fconj=0.5)
pdhg.run(1, verbose=0)
self.assertEquals(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_fconj * sigma))
self.assertEquals(pdhg.tau, tau / pdhg.theta)
self.assertEquals(pdhg.sigma, sigma * pdhg.theta)
self.assertEqual(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_fconj * sigma))
self.assertEqual(pdhg.tau, tau / pdhg.theta)
self.assertEqual(pdhg.sigma, sigma * pdhg.theta)
pdhg.run(4, verbose=0)
self.assertNotEqual(pdhg.sigma, sigma)
self.assertNotEqual(pdhg.tau, tau)
Expand Down
48 changes: 24 additions & 24 deletions Wrappers/Python/test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,17 +1121,17 @@ def setUp(self) -> None:
self.alpha_arr = self.ig_real.allocate(0.15)

def test_configure_tv_defaults(self):
self.assertEquals(self.tv.warm_start, True)
self.assertEquals(self.tv.iterations, 10)
self.assertEquals(self.tv.correlation, "Space")
self.assertEquals(self.tv.backend, "c")
self.assertEquals(self.tv.lower, -np.inf)
self.assertEquals(self.tv.upper, np.inf)
self.assertEquals(self.tv.isotropic, True)
self.assertEquals(self.tv.split, False)
self.assertEquals(self.tv.info, False)
self.assertEquals(self.tv.strong_convexity_constant, 0)
self.assertEquals(self.tv.tolerance, None)
self.assertEqual(self.tv.warm_start, True)
self.assertEqual(self.tv.iterations, 10)
self.assertEqual(self.tv.correlation, "Space")
self.assertEqual(self.tv.backend, "c")
self.assertEqual(self.tv.lower, -np.inf)
self.assertEqual(self.tv.upper, np.inf)
self.assertEqual(self.tv.isotropic, True)
self.assertEqual(self.tv.split, False)
self.assertEqual(self.tv.info, False)
self.assertEqual(self.tv.strong_convexity_constant, 0)
self.assertEqual(self.tv.tolerance, None)

def test_configure_tv_not_defaults(self):
tv=TotalVariation( max_iteration=100,
Expand All @@ -1145,17 +1145,17 @@ def test_configure_tv_not_defaults(self):
info = True,
strong_convexity_constant = 1.,
warm_start=False)
self.assertEquals(tv.warm_start, False)
self.assertEquals(tv.iterations, 100)
self.assertEquals(tv.correlation, "SpaceChannels")
self.assertEquals(tv.backend, "numpy")
self.assertEquals(tv.lower, 0.)
self.assertEquals(tv.upper, 1.)
self.assertEquals(tv.isotropic, False)
self.assertEquals(tv.split, True)
self.assertEquals(tv.info, True)
self.assertEquals(tv.strong_convexity_constant, 1.)
self.assertEquals(tv.tolerance, 1e-5)
self.assertEqual(tv.warm_start, False)
self.assertEqual(tv.iterations, 100)
self.assertEqual(tv.correlation, "SpaceChannels")
self.assertEqual(tv.backend, "numpy")
self.assertEqual(tv.lower, 0.)
self.assertEqual(tv.upper, 1.)
self.assertEqual(tv.isotropic, False)
self.assertEqual(tv.split, True)
self.assertEqual(tv.info, True)
self.assertEqual(tv.strong_convexity_constant, 1.)
self.assertEqual(tv.tolerance, 1e-5)



Expand Down Expand Up @@ -1410,7 +1410,7 @@ def test_non_scalar_tau_cil_tv(self):
def test_get_p2_with_warm_start(self):
data = dataexample.SHAPES.get(size=(16, 16))
tv=TotalVariation(warm_start=True, max_iteration=10)
self.assertEquals(tv._p2, None, msg="tv._p2 not initialised to None")
self.assertEqual(tv._p2, None, msg="tv._p2 not initialised to None")
tv(data)
checkp2=tv.gradient_operator.range_geometry().allocate(0)
for i, x in enumerate(tv._get_p2()):
Expand All @@ -1427,7 +1427,7 @@ def test_get_p2_with_warm_start(self):
def test_get_p2_without_warm_start(self):
data = dataexample.SHAPES.get(size=(16, 16))
tv=TotalVariation(warm_start=False)
self.assertEquals(tv._p2, None, msg="tv._p2 not initialised to None")
self.assertEqual(tv._p2, None, msg="tv._p2 not initialised to None")
tv(data)
checkp2=tv.gradient_operator.range_geometry().allocate(0)
for i, x in enumerate(tv._get_p2()):
Expand Down
2 changes: 1 addition & 1 deletion Wrappers/Python/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_get_dataset_metadata(self):
dset_dict = HDF5_utilities.get_dataset_metadata(self.path, self.dset_path)

dict_by_hand ={'ndim': 3, 'shape': (91, 135, 160), 'size': 1965600, 'dtype': np.float32, 'compression': None, 'chunks': None, 'is_virtual': False}
self.assertDictContainsSubset(dict_by_hand,dset_dict)
self.assertEqual(dset_dict, dict_by_hand | dset_dict)


def test_read(self):
Expand Down
32 changes: 16 additions & 16 deletions Wrappers/Python/test/test_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ def test_DataContainer(self):
arr = numpy.arange(0,120).reshape(2,3,4,5)
data = DataContainer(arr, True,dimension_labels=['c','z','y','x'])
data.reorder(['x','y','z','c'])
self.assertEquals(data.shape,(5,4,3,2))
self.assertEqual(data.shape,(5,4,3,2))
numpy.testing.assert_array_equal(data.array, arr.transpose(3,2,1,0))

def test_ImageData(self):
ig = ImageGeometry(voxel_num_x=5, voxel_num_y=4, voxel_num_z=3, channels=2, dimension_labels=['channel','vertical','horizontal_y','horizontal_x'])
data = ig.allocate(None)
new_order = ['horizontal_x', 'horizontal_y','vertical', 'channel']
data.reorder(new_order)
self.assertEquals(data.shape,(5,4,3,2))
self.assertEquals(data.geometry.dimension_labels,tuple(new_order))
self.assertEqual(data.shape,(5,4,3,2))
self.assertEqual(data.geometry.dimension_labels,tuple(new_order))

def test_AcquisitionData(self):
ag = AcquisitionGeometry.create_Parallel3D().set_panel([5,4]).set_angles([0,1,2]).set_channels(2).set_labels(['channel','angle','vertical','horizontal'])
data = ag.allocate(None)
new_order = ['horizontal', 'vertical','angle', 'channel']
data.reorder(new_order)
self.assertEquals(data.shape,(5,4,3,2))
self.assertEquals(data.geometry.dimension_labels,tuple(new_order))
self.assertEqual(data.shape,(5,4,3,2))
self.assertEqual(data.geometry.dimension_labels,tuple(new_order))

def test_AcquisitionData_forastra(self):
ag = AcquisitionGeometry.create_Parallel3D().set_panel([5,4]).set_angles([0,1,2]).set_channels(2).set_labels(['horizontal','vertical', 'angle', 'channel'])
Expand Down Expand Up @@ -154,44 +154,44 @@ def test_DataContainer(self):
data = DataContainer(arr, True,dimension_labels=['c','z','y','x'])

data_new = data.get_slice(c=1)
self.assertEquals(data_new.shape,(3,4,5))
self.assertEqual(data_new.shape,(3,4,5))
numpy.testing.assert_array_equal(data_new.array, arr[1])

data_new = data.get_slice(c=1,y=3)
self.assertEquals(data_new.shape,(3,5))
self.assertEqual(data_new.shape,(3,5))
numpy.testing.assert_array_equal(data_new.array, arr[1,:,3,:])

data_new = data.get_slice(c=1,y=3,z=1)
self.assertEquals(data_new.shape,(5,))
self.assertEqual(data_new.shape,(5,))
numpy.testing.assert_array_equal(data_new.array, arr[1,1,3,:])

def test_ImageData(self):
ig = ImageGeometry(voxel_num_x=5, voxel_num_y=4, voxel_num_z=3, channels=2, dimension_labels=['channel','vertical','horizontal_y','horizontal_x'])
data = ig.allocate(None)
data_new = data.get_slice(vertical=1)
self.assertEquals(data_new.shape,(2,4,5))
self.assertEquals(data_new.geometry.dimension_labels,('channel','horizontal_y','horizontal_x'))
self.assertEqual(data_new.shape,(2,4,5))
self.assertEqual(data_new.geometry.dimension_labels,('channel','horizontal_y','horizontal_x'))

def test_AcquisitionData(self):
ag = AcquisitionGeometry.create_Parallel3D().set_panel([5,4]).set_angles([0,1,2]).set_channels(2).set_labels(['channel','angle','vertical','horizontal'])
data = ag.allocate(None)
data_new = data.get_slice(angle=2)
self.assertEquals(data_new.shape,(2,4,5))
self.assertEquals(data_new.geometry.dimension_labels,('channel','vertical','horizontal'))
self.assertEqual(data_new.shape,(2,4,5))
self.assertEqual(data_new.geometry.dimension_labels,('channel','vertical','horizontal'))

#won't return a geometry for un-reconstructable slice
ag = AcquisitionGeometry.create_Cone3D([0,-200,0],[0,200,0]).set_panel([5,4]).set_angles([0,1,2]).set_channels(2).set_labels(['channel','angle','vertical','horizontal'])
data = ag.allocate('random')
data_new = data.get_slice(vertical=1,force=True)
self.assertEquals(data_new.shape,(2,3,5))
self.assertEqual(data_new.shape,(2,3,5))
self.assertTrue(isinstance(data_new,(DataContainer)))
self.assertIsNone(data_new.geometry)
self.assertEquals(data_new.dimension_labels,('channel','angle','horizontal'))
self.assertEqual(data_new.dimension_labels,('channel','angle','horizontal'))

#if 'centre' is between pixels interpolates
data_new = data.get_slice(vertical='centre')
self.assertEquals(data_new.shape,(2,3,5))
self.assertEquals(data_new.geometry.dimension_labels,('channel','angle','horizontal'))
self.assertEqual(data_new.shape,(2,3,5))
self.assertEqual(data_new.geometry.dimension_labels,('channel','angle','horizontal'))
numpy.testing.assert_allclose(data_new.array, (data.array[:,:,1,:] +data.array[:,:,2,:])/2 )

class TestSubset(unittest.TestCase):
Expand Down
Loading
Loading