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: 2 additions & 0 deletions gallery/tutorials/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
# For the general ``CTFFilter``,
# we provide defocus along two perpendicular axes u and v separately,
# along with the angle the u-axis makes with the horizontal (x) axis.
# Note that we chose an extreme astigmatism for demonstration,
# and the values more typically differ by a few percent.

ctf_filter = CTFFilter(
pixel_size=1, # Angstrom
Expand Down
18 changes: 10 additions & 8 deletions src/aspire/ctf/ctf_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def background_subtract_1d(
Estimate and subtract the background from the power spectrum

:param amplitude_spectrum: Estimated power spectrum
:param linprog_method: Method passed to linear progam solver (scipy.optimize.linprog). Defaults to 'interior-point'.
:param linprog_method: Method passed to linear program solver (scipy.optimize.linprog).
:param n_low_freq_cutoffs: Low frequency cutoffs (loop iterations).
:return: 2-tuple of NumPy arrays (PSD after noise subtraction and estimated noise)
"""
Expand Down Expand Up @@ -358,20 +358,22 @@ def background_subtract_1d(
axis=0,
)

x_bound_lst = [
(signal[i], signal[i], -1 * np.inf, np.inf)
for i in range(signal.shape[0])
]
x_bound = np.asarray(x_bound_lst, A.dtype)
x_bound = np.concatenate((x_bound[:, :2], x_bound[:, 2:]), axis=0)
# The original code used `bounds`,
# but for many problems, linprog reports infeasable constraints.
# In practice for a micrograph from the paper, and our tutorial,
# the code seems to work better without it...
# ASPIRE #417

x = linprog(
f,
A_ub=A,
b_ub=np.zeros(A.shape[0]),
bounds=x_bound,
method=linprog_method,
)

if not x.success:
raise RuntimeError("Linear program did not succeed. Halting")

background = x.x[N:]

bs_psd = signal - background
Expand Down
4 changes: 2 additions & 2 deletions tests/test_CtfEstimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def testEstimateCTF(self):
# defocusV
self.assertTrue(
np.allclose(
result["defocus_u"],
self.test_output["defocus_u"],
result["defocus_v"],
self.test_output["defocus_v"],
rtol=0.05,
)
)
Expand Down