piscis.utils
============

.. py:module:: piscis.utils


Attributes
----------

.. autoapisummary::

   piscis.utils.vmap_deformable_max_pool
   piscis.utils.vmap_deformable_softmax_pool
   piscis.utils.vmap_deformable_sum_pool
   piscis.utils.vmap_peak_local_softmax


Functions
---------

.. autoapisummary::

   piscis.utils.compute_spot_coordinates
   piscis.utils.deformable_max_pool
   piscis.utils.deformable_softmax_pool
   piscis.utils.deformable_sum_pool
   piscis.utils.peak_local_softmax
   piscis.utils.pad_and_stack
   piscis.utils.pad
   piscis.utils.remove_duplicate_coords
   piscis.utils._match_coords
   piscis.utils.snap_coords
   piscis.utils.fit_coords
   piscis.utils._gaussian


Module Contents
---------------

.. py:function:: compute_spot_coordinates(labels: numpy.ndarray, deltas: numpy.ndarray, threshold: float, min_distance: int) -> numpy.ndarray

   
   Compute spot coordinates from labels and deltas.


   :Parameters:

       **labels** : np.ndarray
           Labels.

       **deltas** : np.ndarray
           Displacement vectors.

       **threshold** : float
           Detection threshold between 0 and 1.

       **min_distance** : int
           Minimum distance between spots.



   :Returns:

       **coords** : np.ndarray
           Coordinates of detected spots.











   ..
       !! processed by numpydoc !!

.. py:function:: deformable_max_pool(labels: torch.Tensor, deltas: torch.Tensor, kernel_size: Sequence[int] = (3, 3)) -> torch.Tensor

   
   Max pool labels using deltas.


   :Parameters:

       **labels** : torch.Tensor
           Labels.

       **deltas** : torch.Tensor
           Displacement vectors.

       **kernel_size** : Sequence[int], optional
           Kernel size or window size of the max pooling operation. Default is (3, 3).



   :Returns:

       **pooled_labels** : torch.Tensor
           Pooled labels.











   ..
       !! processed by numpydoc !!

.. py:data:: vmap_deformable_max_pool

.. py:function:: 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:

       **labels** : torch.Tensor
           Labels.

       **deltas** : torch.Tensor
           Displacement vectors.

       **x** : torch.Tensor, optional
           Tensor to be pooled. Default is None.

       **kernel_size** : Sequence[int], optional
           Kernel size or window size of the softmax pooling operation. Default is (3, 3).

       **temperature** : float
           Temperature parameter for softmax. Default is 0.05.



   :Returns:

       **pooled_labels** : torch.Tensor
           Pooled labels.











   ..
       !! processed by numpydoc !!

.. py:data:: vmap_deformable_softmax_pool

.. py:function:: deformable_sum_pool(labels: torch.Tensor, deltas: torch.Tensor, kernel_size: Sequence[int] = (3, 3)) -> torch.Tensor

   
   Sum pool labels using deltas.


   :Parameters:

       **labels** : torch.Tensor
           Labels.

       **deltas** : torch.Tensor
           Displacement vectors.

       **kernel_size** : Sequence[int], optional
           Kernel size or window size of the sum pooling operation. Default is (3, 3).



   :Returns:

       **pooled_labels** : torch.Tensor
           Pooled labels.











   ..
       !! processed by numpydoc !!

.. py:data:: vmap_deformable_sum_pool

.. py:function:: 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:

       **labels** : torch.Tensor
           Labels.

       **kernel_size** : Sequence[int], optional
           Kernel size or window size of the softmax pooling operation. Default is (3, 3).

       **temperature** : float
           Temperature parameter for softmax. Default is 0.05.



   :Returns:

       **peaked_labels** : torch.Tensor
           Peaked labels.











   ..
       !! processed by numpydoc !!

.. py:data:: vmap_peak_local_softmax

.. py:function:: pad_and_stack(images: Sequence[numpy.ndarray]) -> numpy.ndarray

   
   Pad and stack images.


   :Parameters:

       **images** : Sequence[np.ndarray]
           List of images to pad and stack.



   :Returns:

       **stacked_images** : np.ndarray
           Stacked images.











   ..
       !! processed by numpydoc !!

.. py:function:: pad(images: Sequence[numpy.ndarray]) -> Sequence[numpy.ndarray]

   
   Pad images to the same size.


   :Parameters:

       **images** : Sequence[np.ndarray]
           List of images to pad.



   :Returns:

       **padded_images** : Sequence[np.ndarray]
           List of padded images.











   ..
       !! processed by numpydoc !!

.. py:function:: remove_duplicate_coords(coords: numpy.ndarray, threshold: int = 1) -> numpy.ndarray

   
   Remove duplicate coordinates within a distance threshold.


   :Parameters:

       **coords** : np.ndarray
           Coordinates.

       **threshold** : int, optional
           Distance threshold. Default is 1.



   :Returns:

       **new_coords** : np.ndarray
           Coordinates without duplicates.











   ..
       !! processed by numpydoc !!

.. py:function:: _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:

       **coords** : np.ndarray
           Coordinates.

       **i** : int
           Coordinate index.

       **set_id** : int
           Set id.

       **coord_set_ids** : Dict[int, int]
           Dictionary to keep track of the set id of each coordinate.

       **checked** : List[int]
           List to keep track of coordinates that have been checked.

       **threshold** : int
           Distance threshold.



   :Returns:

       **matches** : List[int]
           List of matched coordinates.











   ..
       !! processed by numpydoc !!

.. py:function:: 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:

       **coords** : np.ndarray
           Coordinates.

       **image** : np.ndarray
           Image.

       **window_size** : int, optional
           Window size. Must be an odd integer. Default is 3.



   :Returns:

       **snapped_coords** : np.ndarray
           Snapped coordinates.




   :Raises:

       ValueError
           If `window_size` is not an odd integer.







   ..
       !! processed by numpydoc !!

.. py:function:: 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:

       **coords** : np.ndarray
           Coordinates.

       **image** : np.ndarray
           Image.

       **window_size** : int, optional
           Window size. Must be an odd integer. Default is 3.

       **max_gaussian_amplitude** : float, optional
           Maximum amplitude of the Gaussian used to fit the normalized image within a window. Default is 2.0.

       **keep_failed_fits** : bool, optional
           Whether to keep the original coordinates when the Gaussian fit fails. Default is False.



   :Returns:

       **fitted_coords** : np.ndarray
           Fitted coordinates.




   :Raises:

       ValueError
           If `window_size` is not an odd integer.







   ..
       !! processed by numpydoc !!

.. py:function:: _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:

       **xy** : Tuple[np.ndarray, np.ndarray]
           x and y values at which to evaluate the Gaussian.

       **amplitude** : float
           Amplitude of the Gaussian.

       **x0** : float
           x-coordinate of the center of the Gaussian.

       **y0** : float
           y-coordinate of the center of the Gaussian.

       **sigma_x** : float
           Standard deviation of the Gaussian in the x-direction.

       **sigma_y** : float
           Standard deviation of the Gaussian in the y-direction.

       **theta** : float
           Rotation angle of the Gaussian.

       **offset** : float
           Offset of the Gaussian in the z-direction.



   :Returns:

       **g** : np.ndarray
           Gaussian at the given x and y values.











   ..
       !! processed by numpydoc !!

