piscis.utils#

Attributes#

Functions#

compute_spot_coordinates(→ numpy.ndarray)

Compute spot coordinates from labels and deltas.

deformable_max_pool() → torch.Tensor)

Max pool labels using deltas.

deformable_softmax_pool(, temperature)

Softmax pool labels or another tensor using deltas.

deformable_sum_pool() → torch.Tensor)

Sum pool labels using deltas.

peak_local_softmax(, temperature)

Smooth variant of peak_local_max with softmax pooling to find peaks in labels.

pad_and_stack(→ numpy.ndarray)

Pad and stack images.

pad(→ Sequence[numpy.ndarray])

Pad images to the same size.

remove_duplicate_coords(→ numpy.ndarray)

Remove duplicate coordinates within a distance threshold.

_match_coords(→ List[int])

Match coordinates within a distance threshold and assign them to the same set.

snap_coords(→ numpy.ndarray)

Snap each coordinate to the local maxima of an image in a window around the coordinate.

fit_coords(→ numpy.ndarray)

Fit a Gaussian to the image in a window around each coordinate and return the center of the Gaussian.

_gaussian(→ numpy.ndarray)

2D Gaussian function.

Module Contents#

piscis.utils.compute_spot_coordinates(labels: numpy.ndarray, deltas: numpy.ndarray, threshold: float, min_distance: int) numpy.ndarray#

Compute spot coordinates from labels and deltas.

Parameters:
labelsnp.ndarray

Labels.

deltasnp.ndarray

Displacement vectors.

thresholdfloat

Detection threshold between 0 and 1.

min_distanceint

Minimum distance between spots.

Returns:
coordsnp.ndarray

Coordinates of detected spots.

piscis.utils.deformable_max_pool(labels: torch.Tensor, deltas: torch.Tensor, kernel_size: Sequence[int] = (3, 3)) torch.Tensor#

Max pool labels using deltas.

Parameters:
labelstorch.Tensor

Labels.

deltastorch.Tensor

Displacement vectors.

kernel_sizeSequence[int], optional

Kernel size or window size of the max pooling operation. Default is (3, 3).

Returns:
pooled_labelstorch.Tensor

Pooled labels.

piscis.utils.vmap_deformable_max_pool#
piscis.utils.deformable_softmax_pool(labels: torch.Tensor, deltas: torch.Tensor, x: torch.Tensor = None, kernel_size: Sequence[int] = (3, 3), temperature: float = 0.05) torch.Tensor#

Softmax pool labels or another tensor using deltas.

Parameters:
labelstorch.Tensor

Labels.

deltastorch.Tensor

Displacement vectors.

xtorch.Tensor, optional

Tensor to be pooled. Default is None.

kernel_sizeSequence[int], optional

Kernel size or window size of the softmax pooling operation. Default is (3, 3).

temperaturefloat

Temperature parameter for softmax. Default is 0.05.

Returns:
pooled_labelstorch.Tensor

Pooled labels.

piscis.utils.vmap_deformable_softmax_pool#
piscis.utils.deformable_sum_pool(labels: torch.Tensor, deltas: torch.Tensor, kernel_size: Sequence[int] = (3, 3)) torch.Tensor#

Sum pool labels using deltas.

Parameters:
labelstorch.Tensor

Labels.

deltastorch.Tensor

Displacement vectors.

kernel_sizeSequence[int], optional

Kernel size or window size of the sum pooling operation. Default is (3, 3).

Returns:
pooled_labelstorch.Tensor

Pooled labels.

piscis.utils.vmap_deformable_sum_pool#
piscis.utils.peak_local_softmax(labels: torch.Tensor, kernel_size: Sequence[int] = (3, 3), temperature: float = 0.05) torch.Tensor#

Smooth variant of peak_local_max with softmax pooling to find peaks in labels.

Parameters:
labelstorch.Tensor

Labels.

kernel_sizeSequence[int], optional

Kernel size or window size of the softmax pooling operation. Default is (3, 3).

temperaturefloat

Temperature parameter for softmax. Default is 0.05.

Returns:
peaked_labelstorch.Tensor

Peaked labels.

piscis.utils.vmap_peak_local_softmax#
piscis.utils.pad_and_stack(images: Sequence[numpy.ndarray]) numpy.ndarray#

Pad and stack images.

Parameters:
imagesSequence[np.ndarray]

List of images to pad and stack.

Returns:
stacked_imagesnp.ndarray

Stacked images.

piscis.utils.pad(images: Sequence[numpy.ndarray]) Sequence[numpy.ndarray]#

Pad images to the same size.

Parameters:
imagesSequence[np.ndarray]

List of images to pad.

Returns:
padded_imagesSequence[np.ndarray]

List of padded images.

piscis.utils.remove_duplicate_coords(coords: numpy.ndarray, threshold: int = 1) numpy.ndarray#

Remove duplicate coordinates within a distance threshold.

Parameters:
coordsnp.ndarray

Coordinates.

thresholdint, optional

Distance threshold. Default is 1.

Returns:
new_coordsnp.ndarray

Coordinates without duplicates.

piscis.utils._match_coords(coords: numpy.ndarray, i: int, set_id: int, coord_set_ids: Dict[int, int], checked: List[int], threshold: int) List[int]#

Match coordinates within a distance threshold and assign them to the same set.

Parameters:
coordsnp.ndarray

Coordinates.

iint

Coordinate index.

set_idint

Set id.

coord_set_idsDict[int, int]

Dictionary to keep track of the set id of each coordinate.

checkedList[int]

List to keep track of coordinates that have been checked.

thresholdint

Distance threshold.

Returns:
matchesList[int]

List of matched coordinates.

piscis.utils.snap_coords(coords: numpy.ndarray, image: numpy.ndarray, window_size: int = 3) numpy.ndarray#

Snap each coordinate to the local maxima of an image in a window around the coordinate.

Parameters:
coordsnp.ndarray

Coordinates.

imagenp.ndarray

Image.

window_sizeint, optional

Window size. Must be an odd integer. Default is 3.

Returns:
snapped_coordsnp.ndarray

Snapped coordinates.

Raises:
ValueError

If window_size is not an odd integer.

piscis.utils.fit_coords(coords: numpy.ndarray, image: numpy.ndarray, window_size: int = 3, max_gaussian_amplitude: float = 2.0, keep_failed_fits: bool = False) numpy.ndarray#

Fit a Gaussian to the image in a window around each coordinate and return the center of the Gaussian.

Parameters:
coordsnp.ndarray

Coordinates.

imagenp.ndarray

Image.

window_sizeint, optional

Window size. Must be an odd integer. Default is 3.

max_gaussian_amplitudefloat, optional

Maximum amplitude of the Gaussian used to fit the normalized image within a window. Default is 2.0.

keep_failed_fitsbool, optional

Whether to keep the original coordinates when the Gaussian fit fails. Default is False.

Returns:
fitted_coordsnp.ndarray

Fitted coordinates.

Raises:
ValueError

If window_size is not an odd integer.

piscis.utils._gaussian(xy: Tuple[numpy.ndarray, numpy.ndarray], amplitude: float, x0: float, y0: float, sigma_x: float, sigma_y: float, theta: float, offset: float) numpy.ndarray#

2D Gaussian function.

Parameters:
xyTuple[np.ndarray, np.ndarray]

x and y values at which to evaluate the Gaussian.

amplitudefloat

Amplitude of the Gaussian.

x0float

x-coordinate of the center of the Gaussian.

y0float

y-coordinate of the center of the Gaussian.

sigma_xfloat

Standard deviation of the Gaussian in the x-direction.

sigma_yfloat

Standard deviation of the Gaussian in the y-direction.

thetafloat

Rotation angle of the Gaussian.

offsetfloat

Offset of the Gaussian in the z-direction.

Returns:
gnp.ndarray

Gaussian at the given x and y values.