Skip to content

Commit 004ba5e

Browse files
authored
Merge pull request #414 from ComputationalCryoEM/fix_413
Simulation n=1
2 parents 015992e + b9d99ea commit 004ba5e

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

src/aspire/apple/picking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
class Picker:
26-
""" This class does the actual picking with help from PickerHelper class. """
26+
"""This class does the actual picking with help from PickerHelper class."""
2727

2828
def __init__(
2929
self,

src/aspire/reconstruction/estimator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def compute_kernel(self):
6363
raise NotImplementedError("Subclasses must implement the compute_kernel method")
6464

6565
def estimate(self, b_coeff=None, tol=None):
66-
""" Return an estimate as a Volume instance. """
66+
"""Return an estimate as a Volume instance."""
6767
if b_coeff is None:
6868
b_coeff = self.src_backward()
6969
est_coeff = self.conj_grad(b_coeff, tol=tol)

src/aspire/source/image.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(self, L, n, dtype="double", metadata=None, memory=None):
119119

120120
@property
121121
def states(self):
122-
return self.get_metadata("_rlnClassNumber")
122+
return np.atleast_1d(self.get_metadata("_rlnClassNumber"))
123123

124124
@states.setter
125125
def states(self, values):
@@ -164,15 +164,17 @@ def filter_indices(self, indices):
164164

165165
@property
166166
def offsets(self):
167-
return self.get_metadata(["_rlnOriginX", "_rlnOriginY"], default_value=0.0)
167+
return np.atleast_2d(
168+
self.get_metadata(["_rlnOriginX", "_rlnOriginY"], default_value=0.0)
169+
)
168170

169171
@offsets.setter
170172
def offsets(self, values):
171173
return self.set_metadata(["_rlnOriginX", "_rlnOriginY"], values)
172174

173175
@property
174176
def amplitudes(self):
175-
return self.get_metadata("_rlnAmplitude", default_value=1.0)
177+
return np.atleast_1d(self.get_metadata("_rlnAmplitude", default_value=1.0))
176178

177179
@amplitudes.setter
178180
def amplitudes(self, values):

src/aspire/volume/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def project(self, vol_idx, rot_matrices):
176176
return aspire.image.Image(np.real(im_f))
177177

178178
def to_vec(self):
179-
""" Returns an N x resolution ** 3 array."""
179+
"""Returns an N x resolution ** 3 array."""
180180
return self._data.reshape((self.n_vols, self.resolution ** 3))
181181

182182
@staticmethod

tests/test_BlkDiagMatrix.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ def tearDown(self):
5656
pass
5757

5858
def allallfunc(self, A, B, func=np.allclose):
59-
""" Checks assertTrue(func()) as it iterates through A, B. """
59+
"""Checks assertTrue(func()) as it iterates through A, B."""
6060
for (a, b) in zip(A, B):
6161
self.assertTrue(func(a, b))
6262

6363
def allallid(self, A, B_ids, func=np.allclose):
64-
""" Checks id(a) matches b_id for (a, b_id) in zip(A, B_ids). """
64+
"""Checks id(a) matches b_id for (a, b_id) in zip(A, B_ids)."""
6565
return self.allallfunc(A, B_ids, func=lambda x, y: id(x) == y)
6666

6767
def testBlkDiagMatrixCompat(self):
68-
""" Check incompatible matrix raises exception. """
68+
"""Check incompatible matrix raises exception."""
6969
# Create a differently shaped matrix
7070
x = BlkDiagMatrix.from_list(self.blk_a[1:-1])
7171
# code should raise
@@ -208,7 +208,7 @@ def testBlkDiagMatrixDeepCopy(self):
208208
self.allallfunc(blk_a_copy_2, self.blk_a)
209209

210210
def testBlkDiagMatrixInPlace(self):
211-
""" Tests sequence of in place optimized arithmetic (add, sub, mul) """
211+
"""Tests sequence of in place optimized arithmetic (add, sub, mul)"""
212212
_ = [x + x + 10.0 for x in self.blk_a]
213213
_ = [np.ones(x.shape) * 5.0 for x in self.blk_a]
214214

@@ -316,7 +316,7 @@ def testBlkDiagMatrixIsFinite(self):
316316
self.assertFalse(blk_nan.isfinite)
317317

318318
def testBlkDiagMatrixDense(self):
319-
""" Test we correctly compute the right shape and array. """
319+
"""Test we correctly compute the right shape and array."""
320320
self.assertTrue(np.allclose(self.dense, self.blk_a.dense()))
321321

322322
def testBlkDiagMatrixArith(self):

tests/test_simulation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
DATA_DIR = os.path.join(os.path.dirname(__file__), "saved_test_data")
1414

1515

16+
class SingleSimTestCase(TestCase):
17+
"""Test we can construct a length 1 Sim."""
18+
19+
def setUp(self):
20+
self.sim = Simulation(
21+
n=1,
22+
L=8,
23+
)
24+
25+
def testImage(self):
26+
"""Test we can get an Image from a length 1 Sim."""
27+
_ = self.sim.images(0, 1)
28+
29+
1630
class SimTestCase(TestCase):
1731
def setUp(self):
1832
self.sim = Simulation(

tests/test_volume.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,27 @@ def testProject(self):
121121
self.assertTrue(np.allclose(vol_along_axis, prj_along_axis))
122122

123123
def to_vec(self):
124-
""" Compute the to_vec method and compare. """
124+
"""Compute the to_vec method and compare."""
125125
result = self.vols_1.to_vec()
126126
self.assertTrue(result == self.vec)
127127
self.assertTrue(isinstance(result, np.ndarray))
128128

129129
def testFromVec(self):
130-
""" Compute Volume from_vec method and compare. """
130+
"""Compute Volume from_vec method and compare."""
131131
vol = Volume.from_vec(self.vec)
132132
self.assertTrue(np.allclose(vol, self.vols_1))
133133
self.assertTrue(isinstance(vol, Volume))
134134

135135
def testVecId1(self):
136-
""" Test composition of from_vec(to_vec). """
136+
"""Test composition of from_vec(to_vec)."""
137137
# Construct vec
138138
vec = self.vols_1.to_vec()
139139

140140
# Convert back to Volume and compare
141141
self.assertTrue(np.allclose(Volume.from_vec(vec), self.vols_1))
142142

143143
def testVecId2(self):
144-
""" Test composition of to_vec(from_vec). """
144+
"""Test composition of to_vec(from_vec)."""
145145
# Construct Volume
146146
vol = Volume.from_vec(self.vec)
147147

0 commit comments

Comments
 (0)