Skip to content

Commit

Permalink
FIX: Updated unit tests after mods to self_assembly/misc/read_image
Browse files Browse the repository at this point in the history
  • Loading branch information
mptino committed Aug 30, 2024
1 parent 39774fd commit 3109e15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 8 additions & 8 deletions shapelets/tests/test_self_assembly_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def test_a_read_image(self) -> None:
self.assertTrue(isinstance(self.lamSIM, np.ndarray))
self.assertEqual(self.lamSIM.min(), -1)
self.assertEqual(self.lamSIM.max(), 1)
self.assertEqual(self.lamSIM.shape, (296, 296))
self.assertEqual(self.lamSIM.shape, (883, 883))

self.assertTrue(isinstance(self.hexSIM, np.ndarray))
self.assertEqual(self.hexSIM.min(), -1)
self.assertEqual(self.hexSIM.max(), 1)
self.assertEqual(self.hexSIM.shape, (507, 507))
self.assertEqual(self.hexSIM.shape, (876, 876))

# Test get_wavelength
def test_scaling(self) -> None:
Expand All @@ -63,27 +63,27 @@ def test_scaling(self) -> None:

lamSIM_wvl = get_wavelength(image = self.lamSIM, verbose = False)
self.assertTrue(isinstance(lamSIM_wvl, numbers.Real))
self.assertAlmostEqual(lamSIM_wvl, 10.231, places = 3)
self.assertAlmostEqual(lamSIM_wvl, 30.42, places = 2)

lamSIM_beta_n0 = lambda_to_beta_n0(3, lamSIM_wvl)
self.assertTrue(isinstance(lamSIM_beta_n0, numbers.Real))
self.assertAlmostEqual(lamSIM_beta_n0, 3.41, places = 2)
self.assertAlmostEqual(lamSIM_beta_n0, 10.14, places = 2)

lamSIM_beta_n1 = lambda_to_beta_n1(3, lamSIM_wvl)
self.assertTrue(isinstance(lamSIM_beta_n1, numbers.Real))
self.assertAlmostEqual(lamSIM_beta_n1, 7.3, places = 5)
self.assertAlmostEqual(lamSIM_beta_n1, 22.9, places = 5)

hexSIM_wvl = get_wavelength(image = self.hexSIM, verbose = False)
self.assertTrue(isinstance(hexSIM_wvl, numbers.Real))
self.assertAlmostEqual(hexSIM_wvl, 16.882, places = 3)
self.assertAlmostEqual(hexSIM_wvl, 29.24, places = 2)

hexSIM_beta_n0 = lambda_to_beta_n0(6, hexSIM_wvl)
self.assertTrue(isinstance(hexSIM_beta_n0, numbers.Real))
self.assertAlmostEqual(hexSIM_beta_n0, 6.89, places = 2)
self.assertAlmostEqual(hexSIM_beta_n0, 11.94, places = 2)

hexSIM_beta_n1 = lambda_to_beta_n1(6, hexSIM_wvl)
self.assertTrue(isinstance(hexSIM_beta_n1, numbers.Real))
self.assertAlmostEqual(hexSIM_beta_n1, 9.1, places = 5)
self.assertAlmostEqual(hexSIM_beta_n1, 16.0, places = 1)

if __name__ == "__main__":
unittest.main()
10 changes: 7 additions & 3 deletions shapelets/tests/test_self_assembly_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ def setUpClass(cls) -> None:
cls.dir = __file__.replace(os.path.basename(__file__), 'images/')

# Ensure core functions have appropriate outputs before proceeding.
# Note that read_image and get_wavelength are not tested here, so inline asserts
# are used to ensure correct output.
# NOTE: read_image & get_wavelength are not tested here, so inline asserts are used to ensure correct output.

cls.image = read_image(image_name="hexSIM1.png", image_path=cls.dir, verbose=False)
cls.image_nonresized = read_image(image_name="hexSIM1.png", image_path=cls.dir, do_rescale=False, verbose=False)

assert isinstance(cls.image, np.ndarray)
assert isinstance(cls.image_nonresized, np.ndarray)

cls.omega, cls.phi = convresponse_n0(cls.image, shapelet_order='default', verbose=False)

Expand Down Expand Up @@ -105,7 +108,8 @@ def test_orientation(self) -> None:
with self.assertRaises(TypeError):
orientation(self.image, pattern_order=1.)

mask, dilate, orient_result, _ = orientation(self.image, pattern_order='hexagonal', verbose=False)
# use non resized image since orientation method has long compute times
mask, dilate, orient_result, _ = orientation(self.image_nonresized, pattern_order='hexagonal', verbose=False)

self.assertTrue(isinstance(mask, np.ndarray))
self.assertTrue(isinstance(dilate, np.ndarray))
Expand Down

0 comments on commit 3109e15

Please sign in to comment.