aspire.denoising package

Submodules

aspire.denoising.adaptive_support module

aspire.denoising.adaptive_support.adaptive_support(img_src, energy_threshold=0.99)

Determine size of the compact support in both real and Fourier Space.

Returns c_limit (support radius in Fourier space), and R_limit (support radius in real space).

Fourier c_limit is scaled in range [0, 0.5]. R_limit is in pixels [0, Image.resolution/2].

Parameters:
  • img_src – Input Source of images.

  • energy_threshold – [0, 1] threshold limit

Returns:

(c_limit, R_limit)

aspire.denoising.class_avg module

class aspire.denoising.class_avg.ClassAvgSource(src, classifier, class_selector, averager)

Bases: ImageSource

Source for denoised 2D images using class average methods.

Constructor of an object for denoising 2D images using class averaging methods.

Parameters:
  • src – Source used for image classification.

  • classifier – Class2D subclass used for image classification. Example, RIRClass2D.

  • class_selector – A ClassSelector subclass.

  • averager – An Averager2D subclass.

property class_distances

Returns table of class image distances as (src.n, n_nbors) Numpy array.

Follows same layout as class_indices but holds floats representing the distance (returned by classifier) to the zeroth image in each class.

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, self.dtype.

property class_indices

Returns table of class image indices as (src.n, n_nbors) Numpy array.

Each row reprsents a class, with the columns ordered by smallest class_distances from the reference image (zeroth columm).

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, integers.

property class_refl

Returns table of class image reflections as (src.n, n_nbors) Numpy array.

Follows same layout as class_indices but holds booleans that are True when the image should be reflected before averaging.

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, boolean.

property n
save(*args, **kwargs)

Save metadata to STAR file.

See ImageSource.save for documentation.

property selection_indices
class aspire.denoising.class_avg.ClassAvgSourcev110(src, n_nbor=50, num_procs=None, classifier=None, class_selector=None, averager=None, averager_src=None)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

Defaults to using Contrast based class selection (on the fly, compressed), avoiding neighbors of previous classes, and a brute force image alignment.

Currently this is the most reasonable default for experimental data.

Instantiates ClassAvgSourcev11 with the following parameters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • num_procs – Number of processors. Use 1 to run serially. Default None attempts to compute a reasonable value based on available cores and memory.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates NeighborVarianceWithRepulsionClassSelector.

  • averagerAverager2D instance. Default None ceates BFSRAverager2D instance. See code for parameter details.

  • averager_src – Optionally explicitly assign source to BFSRAverager2D during initialization. Raises error when combined with an explicit averager argument.

Returns:

ClassAvgSource instance.

class aspire.denoising.class_avg.DebugClassAvgSource(src, n_nbor=10, num_procs=1, classifier=None, class_selector=None, averager=None)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

In this context Debug means defaulting to:
  • Using the defaults for RIRClass2D.

  • Using TopClassSelector to select all classes maintaining the same order as the input source.

  • Using BFRAverager2D with defaults on a single core.

Instantiates with default debug paramaters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 10.

  • num_procs – Number of processors. Default of 1 runs serially. None attempts to compute a reasonable value based on available cores and memory.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates TopClassSelector.

  • averagerAverager2D instance. Default None ceates BFRAverager2D instance. See code for parameter details.

Returns:

ClassAvgSource instance.

aspire.denoising.class_avg.DefaultClassAvgSource(src, n_nbor=50, num_procs=None, classifier=None, class_selector=None, averager=None, averager_src=None, version=None)

Source for denoised 2D images using class average methods.

Accepts version, to dispatch ClassAvgSource with parameters below. Default version is latest available.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • num_procs – Number of processors. Use 1 to run serially. Default None attempts to compute a reasonable value based on available cores and memory.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates NeighborVarianceWithRepulsionClassSelector.

  • averagerAverager2D instance. Default None ceates BFSRAverager2D instance. See code for parameter details.

  • averager_src – Optionally explicitly assign source to BFSRAverager2D during initialization. Raises error when combined with an explicit averager argument.

  • version – Optionally selects a versioned DefaultClassAvgSource. Defaults to latest available.

Returns:

ClassAvgSource instance.

aspire.denoising.denoised_src module

class aspire.denoising.denoised_src.DenoisedSource(src, denoiser)

Bases: ImageSource

ImageSource class serving denoised 2D images.

Initialize a denoised ImageSource object from an ImageSource.

Parameters:
  • src – Original ImageSource object storing noisy images

  • denoiser – A Denoiser object for specifying a method for denoising

aspire.denoising.denoiser module

class aspire.denoising.denoiser.Denoiser(src)

Bases: ABC

Base class for 2D image denoisers.

Initialize an object for denoising 2D images from src.

Parameters:

srcImageSource providing noisy images.

property denoise

Subscriptable property returning 2D images after denoising.

See _ImageAccessor.

aspire.denoising.denoiser_cov2d module

class aspire.denoising.denoiser_cov2d.DenoiserCov2D(src, basis=None, var_noise=None, batch_size=512, covar_opt=None)

Bases: Denoiser

Define a derived class for denoising 2D images using Cov2D method

Initialize an object for denoising 2D images using Cov2D method

Parameters:
  • src – The source object of 2D images with metadata

  • basis – The basis method to expand 2D images

  • var_noise – The estimated variance of noise

  • batch_size – Integer batch size for processing images. Defaults to 512.

  • covar_opt – Optional dictionary of option overides for Cov2D. Provided options will supersede defaults in DenoiserCov2D.default_opt.

build_denoiser()

Build estimated mean and covariance matrix of 2D images.

This method should be computed once, on first images access.

default_opt = {'iter_callback': [], 'max_iter': 250, 'rel_tolerance': 1e-12, 'shrinker': 'frobenius_norm', 'store_iterates': False, 'verbose': 0}
aspire.denoising.denoiser_cov2d.src_wiener_coords(sim, mean_vol, eig_vols, lambdas=None, noise_var=0, batch_size=512)

Calculate coordinates using Wiener filter

Parameters:
  • sim – A simulation object containing the images whose coordinates we want.

  • mean_vol – The mean volume of the source as Volume instance.

  • eig_vols – The eigenvolumes of the source as Volume instance.

  • lambdas – The eigenvalues in a K-by-K diagonal matrix (default eye(K)).

  • noise_var – The variance of the noise in the images (default 0).

  • batch_size – The size of the batches in which to compute the coordinates (default 512).

Returns:

A K-by-src.n array of coordinates corresponding to the Wiener filter coordinates of each image in sim.

The coordinates are obtained by the formula

alpha_s = eig_vols^T H_s ( y_s - P_s mean_vol ) ,

where P_s is the forward image mapping and y_s is the sth image,

H_s = Sigma * P_s^T ( P_s Sigma P_s^T + noise_var I )^(-1) ,

and Sigma is the covariance matrix eig_vols * lambdas * eig_vols^T. Note that when noise_var is zero, this reduces to the projecting y_s onto the span of P_s eig_vols.

# TODO: Find a better place for this functionality other than in utils

Module contents