Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/aspire/apple/picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/aspire/reconstruction/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/aspire/source/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -164,15 +164,17 @@ 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):
return self.set_metadata(["_rlnOriginX", "_rlnOriginY"], 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):
Expand Down
2 changes: 1 addition & 1 deletion src/aspire/volume/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_BlkDiagMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,27 @@ 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()

# Convert back to Volume and compare
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)

Expand Down