Density#
- class Density(data, origin=None, sampling_rate=None, metadata={})[source]#
Bases:
objectAbstract 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
Densityinstance>>> import numpy as np >>> from tme import Density >>> data = np.random.rand(50,70,40) >>> Density(data=data)
Optional parameters
origincorrespond to the coordinate system reference,sampling_rateto the spatial length per axis element, andmetadatato a dictionary with supplementary information. By default,Density.originis set to zero,Density.sampling_rateto one, andDensity.metadatais an empty dictionary. If provided,originandsampling_rateeither 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
Returns the value of
Density.data.Returns a copy of the class instance with all elements in
Density.dataset to zero.Returns the instance's
Density.metadataattribute.Returns the value of the instance's
Density.originattribute.Returns the value of the instance's
Density.sampling_rateattribute.Returns the dimensions of
Density.data.Methods
Density.adjust_box(box[, pad_kwargs])Adjusts
Density.dataandDensity.originaccording to the provided box.Density.align_to_axis([data, axis, flip])Density.center_of_mass([arr, cutoff])Computes the center of mass of a numpy ndarray instance.
Density.centered([cutoff, order])Shifts the data center of mass to the center of the data array using linear interpolation.
Create a copy of the class instance.
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
Densityinstance.Density.from_structure(filename_or_structure)Reads in an atomic structure and converts it into a
Densityinstance.Density.match_densities(target, template[, ...])Aligns two
Densityinstances target and template and returns the aligned template.Density.match_structure_to_density(target, ...)Aligns a
tme.structure.Structuretemplate toDensitytarget and returns an alignedtme.structure.Structureinstance.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 internalDensity.dataarray of the currentDensityinstance tonew_shapeand adaptsDensity.originaccordingly.Density.resample(new_sampling_rate[, ...])Resamples
Density.datatonew_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.
Converts
Density.datato anumpy.memmap.Converts
Density.datato an in-memorynumpy.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.