Density#

class Density(data, origin=None, sampling_rate=None, metadata={})[source]#

Bases: object

Abstract representation of N-dimensional densities.

Parameters:
dataarray_like

Array of densities.

originarray_like, optional

Origin of the coordinate system, zero by default.

sampling_ratearray_like, optional

Sampling rate along data axis, one by default.

metadatadict, optional

Dictionary with metadata information, empty by default.

Raises:
ValueError

If metadata is not a dictionary.

If sampling rate / origin is not defined for a single or all axes.

Examples

The following achieves the minimal definition of a Density instance

>>> import numpy as np
>>> from tme import Density
>>> data = np.random.rand(50,70,40)
>>> Density(data=data)

Optional parameters origin correspond to the coordinate system reference, sampling_rate to the spatial length per axis element, and metadata to a dictionary with supplementary information. By default, Density.origin is set to zero, Density.sampling_rate to one, and Density.metadata is an empty dictionary. If provided, origin and sampling_rate either need to be a single value

>>> Density(data=data, origin=0, sampling_rate=1)

be specified along each data axis

>>> Density(data=data, origin=(0, 0, 0), sampling_rate=(1.5, 1.1, 1.2))

or be a combination of both

>>> Density(data=data, origin=0, sampling_rate=(1.5, 1.1, 1.2))

Attributes

Density.data

Returns the value of Density.data.

Density.empty

Returns a copy of the class instance with all elements in Density.data set to zero.

Density.metadata

Returns the instance's Density.metadata attribute.

Density.origin

Returns the value of the instance's Density.origin attribute.

Density.sampling_rate

Returns the value of the instance's Density.sampling_rate attribute.

Density.shape

Returns the dimensions of Density.data.

Methods

Density.adjust_box(box[, pad_kwargs])

Adjusts Density.data and Density.origin according to the provided box.

Density.center_of_mass(arr[, cutoff])

Computes the center of mass of a numpy ndarray instance using all available elements.

Density.centered([cutoff])

Shifts the data center of mass to the center of the data array using linear interpolation.

Density.copy()

Create a copy of the class instance.

Density.core_mask()

Calculates a weighted core mask by performing iterative binary erosion on Density.data.

Density.density_boundary(weight[, ...])

Computes the density boundary of the class instance.

Density.fourier_shell_correlation(density1, ...)

Computes the Fourier Shell Correlation (FSC) between two instances of Density.

Density.from_file(filename[, subset, use_memmap])

Reads a file into a Density instance.

Density.from_structure(filename_or_structure)

Reads in an atomic structure and converts it into a Density instance.

Density.match_densities(target, template[, ...])

Aligns two Density instances target and template and returns the aligned template.

Density.match_structure_to_density(target, ...)

Aligns a tme.structure.Structure template to Density target and returns an aligned tme.structure.Structure instance.

Density.minimum_enclosing_box(cutoff[, ...])

Compute the enclosing box that holds all possible rotations of the internal data array.

Density.normal_vectors(coordinates)

Calculates the normal vectors for the given coordinates on the densities of the class instance.

Density.pad(new_shape[, center, padding_value])

Density.pad() extends the internal Density.data array of the current Density instance to new_shape and adapts Density.origin accordingly.

Density.resample(new_sampling_rate[, ...])

Resamples Density.data to new_sampling_rate.

Density.rigid_transform(rotation_matrix[, ...])

Performs a rigid transform of the class instance.

Density.surface_coordinates(density_boundaries)

Calculates the surface coordinates of the class instance using different boundary and surface detection methods.

Density.to_file(filename[, gzip])

Writes class instance to disk.

Density.to_memmap()

Converts Density.data to a numpy.memmap.

Density.to_numpy()

Converts Density.data to an in-memory numpy.ndarray.

Density.to_pointcloud([threshold])

Returns data indices that are larger than the given threshold.

Density.trim_box(cutoff[, margin])

Computes a rectangle with sufficient dimension that encloses all values of the internal data array larger than the specified cutoff, expanded by the specified margin.