From 67ebd5fefbde46a4defb3ff82772e600d6304ccf Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Mon, 3 May 2021 14:29:21 -0400 Subject: [PATCH 1/3] Adds simulation test class for length 1 sim --- tests/test_simulation.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 1c42eadd1d..5894f59e6a 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -13,6 +13,20 @@ DATA_DIR = os.path.join(os.path.dirname(__file__), "saved_test_data") +class SingleSimTestCase(TestCase): + """Test we can construct a length 1 Sim.""" + + def setUp(self): + self.sim = Simulation( + n=1, + L=8, + ) + + def testImage(self): + """Test we can get an Image from a length 1 Sim.""" + _ = self.sim.images(0, 1) + + class SimTestCase(TestCase): def setUp(self): self.sim = Simulation( From 7591f9159cca64bde23b8c8ef5d91713a6a07fad Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Mon, 3 May 2021 14:30:00 -0400 Subject: [PATCH 2/3] Fix some attributes of ImageSource/Simuation for n=1 case --- src/aspire/source/image.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/aspire/source/image.py b/src/aspire/source/image.py index 62d7ba2a1a..c30696f0e7 100644 --- a/src/aspire/source/image.py +++ b/src/aspire/source/image.py @@ -119,7 +119,7 @@ def __init__(self, L, n, dtype="double", metadata=None, memory=None): @property def states(self): - return self.get_metadata("_rlnClassNumber") + return np.atleast_1d(self.get_metadata("_rlnClassNumber")) @states.setter def states(self, values): @@ -164,7 +164,9 @@ def filter_indices(self, indices): @property def offsets(self): - return self.get_metadata(["_rlnOriginX", "_rlnOriginY"], default_value=0.0) + return np.atleast_2d( + self.get_metadata(["_rlnOriginX", "_rlnOriginY"], default_value=0.0) + ) @offsets.setter def offsets(self, values): @@ -172,7 +174,7 @@ def offsets(self, values): @property def amplitudes(self): - return self.get_metadata("_rlnAmplitude", default_value=1.0) + return np.atleast_1d(self.get_metadata("_rlnAmplitude", default_value=1.0)) @amplitudes.setter def amplitudes(self, values): From b9d99eae506a8ec6b138d691d068007336f0d635 Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Mon, 3 May 2021 14:31:57 -0400 Subject: [PATCH 3/3] Updated black formatting. --- src/aspire/apple/picking.py | 2 +- src/aspire/reconstruction/estimator.py | 2 +- src/aspire/volume/__init__.py | 2 +- tests/test_BlkDiagMatrix.py | 10 +++++----- tests/test_volume.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/aspire/apple/picking.py b/src/aspire/apple/picking.py index 4f190e3171..dfdd7f0d68 100644 --- a/src/aspire/apple/picking.py +++ b/src/aspire/apple/picking.py @@ -23,7 +23,7 @@ class Picker: - """ This class does the actual picking with help from PickerHelper class. """ + """This class does the actual picking with help from PickerHelper class.""" def __init__( self, diff --git a/src/aspire/reconstruction/estimator.py b/src/aspire/reconstruction/estimator.py index 6c6e1c2d93..aa7fa01663 100644 --- a/src/aspire/reconstruction/estimator.py +++ b/src/aspire/reconstruction/estimator.py @@ -63,7 +63,7 @@ def compute_kernel(self): raise NotImplementedError("Subclasses must implement the compute_kernel method") def estimate(self, b_coeff=None, tol=None): - """ Return an estimate as a Volume instance. """ + """Return an estimate as a Volume instance.""" if b_coeff is None: b_coeff = self.src_backward() est_coeff = self.conj_grad(b_coeff, tol=tol) diff --git a/src/aspire/volume/__init__.py b/src/aspire/volume/__init__.py index 68b6e345ef..8e7c033541 100644 --- a/src/aspire/volume/__init__.py +++ b/src/aspire/volume/__init__.py @@ -176,7 +176,7 @@ def project(self, vol_idx, rot_matrices): return aspire.image.Image(np.real(im_f)) def to_vec(self): - """ Returns an N x resolution ** 3 array.""" + """Returns an N x resolution ** 3 array.""" return self._data.reshape((self.n_vols, self.resolution ** 3)) @staticmethod diff --git a/tests/test_BlkDiagMatrix.py b/tests/test_BlkDiagMatrix.py index 9ca3d03524..bae1f9e68f 100644 --- a/tests/test_BlkDiagMatrix.py +++ b/tests/test_BlkDiagMatrix.py @@ -56,16 +56,16 @@ def tearDown(self): pass def allallfunc(self, A, B, func=np.allclose): - """ Checks assertTrue(func()) as it iterates through A, B. """ + """Checks assertTrue(func()) as it iterates through A, B.""" for (a, b) in zip(A, B): self.assertTrue(func(a, b)) def allallid(self, A, B_ids, func=np.allclose): - """ Checks id(a) matches b_id for (a, b_id) in zip(A, B_ids). """ + """Checks id(a) matches b_id for (a, b_id) in zip(A, B_ids).""" return self.allallfunc(A, B_ids, func=lambda x, y: id(x) == y) def testBlkDiagMatrixCompat(self): - """ Check incompatible matrix raises exception. """ + """Check incompatible matrix raises exception.""" # Create a differently shaped matrix x = BlkDiagMatrix.from_list(self.blk_a[1:-1]) # code should raise @@ -208,7 +208,7 @@ def testBlkDiagMatrixDeepCopy(self): self.allallfunc(blk_a_copy_2, self.blk_a) def testBlkDiagMatrixInPlace(self): - """ Tests sequence of in place optimized arithmetic (add, sub, mul) """ + """Tests sequence of in place optimized arithmetic (add, sub, mul)""" _ = [x + x + 10.0 for x in self.blk_a] _ = [np.ones(x.shape) * 5.0 for x in self.blk_a] @@ -316,7 +316,7 @@ def testBlkDiagMatrixIsFinite(self): self.assertFalse(blk_nan.isfinite) def testBlkDiagMatrixDense(self): - """ Test we correctly compute the right shape and array. """ + """Test we correctly compute the right shape and array.""" self.assertTrue(np.allclose(self.dense, self.blk_a.dense())) def testBlkDiagMatrixArith(self): diff --git a/tests/test_volume.py b/tests/test_volume.py index 2a8063b0b2..5d481ea2de 100644 --- a/tests/test_volume.py +++ b/tests/test_volume.py @@ -121,19 +121,19 @@ def testProject(self): self.assertTrue(np.allclose(vol_along_axis, prj_along_axis)) def to_vec(self): - """ Compute the to_vec method and compare. """ + """Compute the to_vec method and compare.""" result = self.vols_1.to_vec() self.assertTrue(result == self.vec) self.assertTrue(isinstance(result, np.ndarray)) def testFromVec(self): - """ Compute Volume from_vec method and compare. """ + """Compute Volume from_vec method and compare.""" vol = Volume.from_vec(self.vec) self.assertTrue(np.allclose(vol, self.vols_1)) self.assertTrue(isinstance(vol, Volume)) def testVecId1(self): - """ Test composition of from_vec(to_vec). """ + """Test composition of from_vec(to_vec).""" # Construct vec vec = self.vols_1.to_vec() @@ -141,7 +141,7 @@ def testVecId1(self): self.assertTrue(np.allclose(Volume.from_vec(vec), self.vols_1)) def testVecId2(self): - """ Test composition of to_vec(from_vec). """ + """Test composition of to_vec(from_vec).""" # Construct Volume vol = Volume.from_vec(self.vec)