Skip to content

Commit a4deec8

Browse files
authored
Merge pull request #640 from ComputationalCryoEM/lifes_a_batch
Batch over large coef transform in FSPCA
2 parents 1bff8d3 + 6d374e7 commit a4deec8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/aspire/basis/fspca.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ class FSPCABasis(SteerableBasis2D):
3131
3232
"""
3333

34-
def __init__(self, src, basis=None, noise_var=None, components=400):
34+
def __init__(self, src, basis=None, noise_var=None, components=400, batch_size=512):
3535
"""
3636
3737
:param src: Source instance
3838
:param basis: Optional Fourier Bessel Basis (usually FFBBasis2D)
3939
:param noise_var: None estimates noise (default).
40+
:param batch_size: Batch size for computing basis coefficients.
4041
0 forces "clean" treatment (no weighting).
4142
Other values assigned to noise_var.
4243
"""
4344

4445
self.src = src
46+
self.batch_size = batch_size
4547

4648
# Automatically generate basis if needed.
4749
if basis is None:
@@ -117,7 +119,13 @@ def build(self):
117119
This may take some time for large image stacks.
118120
"""
119121

120-
coef = self.basis.evaluate_t(self.src.images(0, self.src.n))
122+
coef = np.empty((self.src.n, self.basis.count), dtype=self.dtype)
123+
num_batches = (self.src.n + self.batch_size - 1) // self.batch_size
124+
for i in range(num_batches):
125+
start = i * self.batch_size
126+
finish = min((i + 1) * self.batch_size, self.src.n)
127+
n = finish - start
128+
coef[start:finish] = self.basis.evaluate_t(self.src.images(start, n))
121129

122130
if self.noise_var is None:
123131
from aspire.noise import WhiteNoiseEstimator

0 commit comments

Comments
 (0)