Density.resample#

Density.resample(new_sampling_rate, method='spline', order=1)[source]#

Resamples Density.data to new_sampling_rate.

Parameters:
new_sampling_ratetuple of floats or float

Sampling rate to resample to for a single or all axes.

method: str, optional

Resampling method to use, defaults to spline. Availabe options are:

spline

Spline interpolation using scipy.ndimage.zoom

fourier

Fourier cropping

orderint, optional

Order of spline used for interpolation, by default 1. Ignored when method is fourier.

Returns:
Density

A resampled copy of the class instance.

Raises:
ValueError

If method is not supported.

Examples

The following makes use of tme.matching_utils.create_mask() to define a Density instance containing a 2D circle with a sampling rate of 2

>>> from tme import Density
>>> from tme.matching_utils import create_mask
>>> mask = create_mask(
>>>     mask_type="ellipse",
>>>     shape=(11,11),
>>>     center=(5,5),
>>>     radius=3
>>> )
>>> dens = Density(mask, sampling_rate=2)
>>> dens
Origin: (0.0, 0.0), sampling_rate: (2, 2), Shape: (11, 11)

Using Density.resample() we can modulate the sampling rate using spline interpolation of desired order

>>> dens.resample(new_sampling_rate= 4, method="spline", order=3)
Origin: (0.0, 0.0), sampling_rate: (4, 4), Shape: (6, 6)

Or Fourier cropping which results in a less smooth output, but more faithfully captures the contained frequency information

>>> dens.resample(new_sampling_rate=4, method="fourier")
Origin: (0.0, 0.0), sampling_rate: (4, 4), Shape: (6, 6)

new_sampling_rate can also be specified per axis

>>> dens.resample(new_sampling_rate=(4,1), method="spline", order=3)
Origin: (0.0, 0.0), sampling_rate: (4, 1), Shape: (6, 22)