Skip to content

Commit ecf1243

Browse files
committed
Refactor using property
1 parent 229ae1e commit ecf1243

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/aspire/abinitio/commonline_base.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(
5757
self.shift_step = shift_step
5858
self.mask = mask
5959
self.rotations = None
60+
self._pf = None
6061

6162
self._build()
6263

@@ -77,6 +78,12 @@ def _build(self):
7778
logger.error(msg)
7879
raise NotImplementedError(msg)
7980

81+
@property
82+
def pf(self):
83+
if self._pf is None:
84+
self._pf = self._prepare_pf()
85+
return self._pf
86+
8087
def _prepare_pf(self):
8188
"""
8289
Prepare the polar Fourier transform used for correlations.
@@ -88,15 +95,17 @@ def _prepare_pf(self):
8895
imgs = imgs * fuzz_mask
8996

9097
# Obtain coefficients of polar Fourier transform for input 2D images
91-
self.pft = PolarFT(
98+
pft = PolarFT(
9299
(self.n_res, self.n_res), self.n_rad, self.n_theta, dtype=self.dtype
93100
)
94-
self.pf = self.pft.transform(imgs)
101+
pf = pft.transform(imgs)
95102

96103
# We remove the DC the component. pf has size (n_img) x (n_theta/2) x (n_rad-1),
97104
# with pf[:, :, 0] containing low frequency content and pf[:, :, -1] containing
98105
# high frequency content.
99-
self.pf = self.pf[:, :, 1:]
106+
pf = pf[:, :, 1:]
107+
108+
return pf
100109

101110
def estimate_rotations(self):
102111
"""
@@ -110,8 +119,6 @@ def build_clmatrix(self):
110119
"""
111120
Build common-lines matrix from Fourier stack of 2D images
112121
"""
113-
self._prepare_pf()
114-
115122
n_img = self.n_img
116123
n_check = self.n_check
117124

src/aspire/abinitio/commonline_c2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ def build_clmatrix(self):
9494
Build common-lines matrix for molecules with C2 symmetry from Fourier stack of 2D images.
9595
This consists of finding for each pair of images the two common-lines induced by the 2-fold symmetry.
9696
"""
97-
self._prepare_pf()
98-
9997
n_img = self.n_img
10098

10199
if self.n_theta % 2 == 1:

src/aspire/abinitio/commonline_cn.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def estimate_rotations(self):
104104

105105
def _estimate_relative_viewing_directions(self):
106106
logger.info(f"Estimating relative viewing directions for {self.n_img} images.")
107-
self._prepare_pf()
108107
pf = self.pf
109108

110109
# Generate candidate rotation matrices and the common-line and

tests/test_orient_symmetric.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def test_self_relative_rotations(n_img, L, order, dtype):
173173
src, cl_symm = source_orientation_objs(n_img, L, order, dtype)
174174

175175
# Estimate self-relative viewing directions, Riis.
176-
cl_symm._prepare_pf() # Required to compute self_clmatrix.
177176
scl = cl_symm._self_clmatrix_c3_c4()
178177
Riis = cl_symm._estimate_all_Riis_c3_c4(scl)
179178

@@ -302,7 +301,6 @@ def test_self_commonlines(n_img, L, order, dtype):
302301
n_theta = cl_symm.n_theta
303302

304303
# Initialize common-lines orientation estimation object and compute self-common-lines matrix.
305-
cl_symm._prepare_pf() # Requires polar Fourier transform.
306304
scl = cl_symm._self_clmatrix_c3_c4()
307305

308306
# Compute ground truth self-common-lines matrix.

0 commit comments

Comments
 (0)