aspire.ctf package

Submodules

aspire.ctf.ctf_estimator module

Contains code supporting CTF parameter estimation. Generally, this is a port of ASPIRE-CTF from MATLAB.

See paper:

“Reducing bias and variance for CTF estimation in single particle cryo-EM”
Ayelet Heimowitz, Joakim Andén, Amit Singer
Ultramicroscopy, Volume 212, 2020

Note: CtfEstimator computes the background as a monotonically decreasing function of spatial frequency. This practice may lead to an inaccurate background estimation for experimental images produced using a K2 camera in counting mode, as the background in this case is not monotonically decreasing. Despite this, CTF parameters are captured successfully in such situations.

Created on Sep 10, 2019 @author: Ayelet Heimowitz, Amit Moscovich

Integrated into ASPIRE-Python by Garrett Wright Feb 2021.

class aspire.ctf.ctf_estimator.CtfEstimator(pixel_size, cs, amplitude_contrast, voltage, psd_size, num_tapers, dtype=<class 'numpy.float32'>)

Bases: object

CtfEstimator Class …

Instantiate a CtfEstimator instance.

Parameters:
  • pixel_size – Size of the pixel in Å (angstrom).

  • cs – Spherical aberration in mm.

  • amplitude_contrast – Amplitude contrast.

  • voltage – Voltage of electron microscope.

  • psd_size – Block size (in pixels) for PSD estimation.

  • num_tapers – Number of tapers to apply in PSD estimation.

Returns:

CtfEstimator instance.

background_subtract_1d(amplitude_spectrum, linprog_method='highs', n_low_freq_cutoffs=14)

Estimate and subtract the background from the power spectrum

Parameters:
  • amplitude_spectrum – Estimated power spectrum

  • linprog_method – Method passed to linear program solver (scipy.optimize.linprog).

  • n_low_freq_cutoffs – Low frequency cutoffs (loop iterations).

Returns:

2-tuple of NumPy arrays (PSD after noise subtraction and estimated noise)

background_subtract_2d(signal, background_p1, max_col)

Subtract background from estimated power spectrum

Parameters:
  • signal – Estimated power spectrum

  • background_p1 – 1-D background estimation

  • max_col – Internal variable, returned as the second parameter from opt1d.

Returns:

2-tuple of NumPy arrays (Estimated PSD without noise and estimated noise).

elliptical_average(ffbbasis, amplitude_spectrum, circular)

Computes radial/elliptical average of the power spectrum

Parameters:
  • ffbbasis – FFBBasis instance.

  • amplitude_spectrum – Power spectrum.

  • circular – True for radial averaging and False for elliptical averaging.

Returns:

PSD and noise as 2-tuple of NumPy arrays.

estimate_psd(blocks, tapers_1d)

Estimate the power spectrum of the micrograph using the multi-taper method

Parameters:
  • blocks – 3-D NumPy array containing windows extracted from the micrograph in the preprocess function.

  • tapers_1d – NumPy array of data tapers.

Returns:

NumPy array of estimated power spectrum.

gd(signal, df1, df2, angle_ast, r, theta, pixel_size, g_min, g_max, amplitude_contrast, lmbd, cs)

Runs gradient ascent to optimize defocus parameters

Parameters:
  • signal – Estimated power spectrum

  • df1 – Defocus value in the direction perpendicular to df2.

  • df2 – Defocus value in the direction perpendicular to df1.

  • angle_ast – Angle between df1 and the x-axis, Radians.

  • r – Magnitude of spatial frequencies.

  • theta – Phase of spatial frequencies.

  • pixel_size – Pixel size in Å (angstrom).

  • g_min – Inverse of minimun resolution for PSD.

  • g_max – Inverse of maximum resolution for PSD.

  • amplitude_contrast – Amplitude contrast.

  • lmbd – Electron wavelength Å (angstrom).

  • cs – Spherical aberration in mm.

Returns:

Optimal defocus parameters

generate_ctf()

Generates internal representation of the Contrast Transfer Function using parameters from this instance.

micrograph_to_blocks(micrograph, block_size)

Preprocess micrograph into blocks using block_size.

Parameters:
  • micrograph – Micrograph as NumPy array. #NOTE looks like F order

  • blocksize – Size of the square blocks to partition micrograph.

Returns:

NumPy array of blocks extracted from the micrograph.

normalize_blocks(blocks)

Preprocess CTF of micrograph using block_size.

Parameters:

blocks – NumPy array of blocks extracted from the micrograph.

Returns:

NumPy array of normalized blocks.

opt1d(amplitude_spectrum, pixel_size, cs, lmbd, w, N, min_defocus=500, max_defocus=10000)

Find optimal defocus for the radially symmetric case (where no astigmatism is present)

Parameters:
  • amplitude_spectrum – Estimated power specrtum.

  • pixel_size – Pixel size in Å (angstrom).

  • cs – Spherical aberration in mm.

  • lmbd – Electron wavelength Å (angstrom).

  • w – Amplitude contrast.

  • N – Number of rows (or columns) in the estimate power spectrum.

  • min_defocus – Start of defocus loop scan.

  • max_defocus – End of defocus loop scan.

Returns:

2-tuple of NumPy arrays (Estimated average of defocus and low_freq_cutoff)

pca(signal, pixel_size, g_min, g_max)
Parameters:
  • signal – Estimated power spectrum.

  • pixel_size – Pixel size in Å (angstrom).

  • g_min – Inverse of minimun resolution for PSD.

  • g_max – Inverse of maximum resolution for PSD.

Returns:

ratio.

preprocess_micrograph(micrograph, block_size)

Preprocess micrograph into normalized blocks using block_size.

Parameters:
  • micrograph – Micrograph as NumPy array. #NOTE looks like F order

  • blocksize – Size of the square blocks to partition micrograph.

Returns:

NumPy array of normalized blocks extracted from the micrograph.

set_angle(angle)

Sets angle.

Parameters:

angle – Angle (in Radians) between df1 and the x-axis.

set_df1(df)

Sets defocus.

Parameters:

df – Defocus value in the direction perpendicular to df2.

set_df2(df)

Sets defocus.

Parameters:

df – Defocus value in the direction perpendicular to df1.

tapers(N, NW, L)

Compute data tapers (which are discrete prolate spheroidal sequences (dpss))

Uses scipy implementation, see:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.windows.dpss.html

Parameters:
  • N – Size of each taper

  • NW – Half Bandwidth

  • L – Number of tapers

Returns:

NumPy array of data tapers

write_star(name, params_dict, output_dir)

Writes CTF parameters to starfile for a single micrograph.

aspire.ctf.ctf_estimator.estimate_ctf(data_folder, pixel_size=1.0, cs=2.0, amplitude_contrast=0.07, voltage=300, num_tapers=2, psd_size=512, g_min=30, g_max=5, output_dir='results', dtype=<class 'numpy.float32'>, save_ctf_images=False, save_noise_images=False)

Given paramaters estimates CTF from experimental data and returns CTF as a mrc file.

Module contents