piscis.core
===========

.. py:module:: piscis.core


Classes
-------

.. autoapisummary::

   piscis.core._Piscis
   piscis.core.Piscis
   piscis.core.PiscisLegacy


Functions
---------

.. autoapisummary::

   piscis.core.adjust_parameters


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

.. py:class:: _Piscis(model_name: str, batch_size: int, input_size: Optional[Tuple[int, int]], device: Optional[Union[str, torch.device]], pooling: str)

   
   Base class for running the Piscis algorithm.



   :Attributes:

       **model_name** : str
           Model name.

       **batch_size** : int
           Batch size for the CNN.

       **adjustment** : str
           Adjustment type applied to images during preprocessing.

       **input_size** : Tuple[int, int]
           Input size for the CNN.

       **dilation_iterations** : int
           Number of iterations used to dilate ground truth labels during training.

       **channels** : int
           Number of channels in the input images.

       **device** : Optional[Union[str, torch.device]]
           Device to run the model on.

       **pooling** : str
           Pooling type applied to labels.

       **model** : SpotsModel
           Model.













   ..
       !! processed by numpydoc !!

   .. py:attribute:: model_name


   .. py:attribute:: batch_size


   .. py:attribute:: device


   .. py:attribute:: pooling


   .. py:attribute:: model


   .. py:method:: _predict(x: Union[numpy.ndarray, dask.array.Array], stack: bool, scale: float, threshold: float, min_distance: int, intermediates: bool) -> Union[Tuple[numpy.ndarray, xarray.DataArray], numpy.ndarray]

      
      Predict spots in an image or stack of images.


      :Parameters:

          **x** : np.ndarray or da.Array
              Image or stack of images.

          **stack** : bool, optional
              Whether `x` is a stack of images.

          **scale** : float, optional
              Scale factor for rescaling `x`.

          **threshold** : float, optional
              Spot detection threshold.

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

          **intermediates** : bool, optional
              Whether to return intermediate feature maps.



      :Returns:

          **coords** : np.ndarray
              Predicted spot coordinates.

          **y** : np.ndarray, optional
              Intermediate feature maps. Only returned if `intermediates` is True.











      ..
          !! processed by numpydoc !!


   .. py:method:: _predict_stack(tiles: deeptile.core.data.Tiled, stack_axis_len: int, scales: numpy.ndarray, threshold: float, min_distance: int, intermediates: bool) -> Union[Tuple[deeptile.Output, numpy.ndarray], deeptile.Output]

      
      Predict spots in a stack of images.


      :Parameters:

          **tiles** : Tiled
              Tiles of images.

          **stack_axis_len** : int
              Length of the stack axis.

          **scales** : np.ndarray
              Scales for rescaling tiles.

          **threshold** : float
              Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to
              identify a spot.

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

          **intermediates** : bool
              Whether to return intermediate feature maps.



      :Returns:

          **coords** : Output
              Predicted spot coordinates.

          **y** : np.ndarray, optional
              Intermediate feature maps. Only returned if `intermediates` is True.











      ..
          !! processed by numpydoc !!


   .. py:method:: _predict_plane(tiles: deeptile.core.data.Tiled, scales: numpy.ndarray, threshold: float, min_distance: int, intermediates: bool) -> Union[Tuple[deeptile.Output, numpy.ndarray], deeptile.Output]

      
      Predict spots in a single plane.


      :Parameters:

          **tiles** : Tiled
              Tiles of images.

          **scales** : np.ndarray
              Scales for rescaling tiles.

          **threshold** : float
              Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to
              identify a spot.

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

          **intermediates** : bool
              Whether to return intermediate feature maps.



      :Returns:

          **coords** : Output
              Predicted spot coordinates.

          **y** : np.ndarray, optional
              Intermediate feature maps. Only returned if `intermediates` is True.











      ..
          !! processed by numpydoc !!


   .. py:method:: _preprocess(x: Union[numpy.ndarray, dask.array.Array], stack: bool) -> Tuple[dask.array.Array, bool]

      
      Preprocess the input.


      :Parameters:

          **x** : np.ndarray or dask.array.Array
              Image or stack of images.

          **stack** : bool
              Whether `x` is a stack of images.



      :Returns:

          **x** : Union[np.ndarray, da.Array]
              Preprocessed image or stack of images.

          **batch_axis** : bool
              Whether `x` has a batch axis.




      :Raises:

          ValueError
              If `x` does not have the correct dimensions.

          ValueError
              If `x` does not have the correct number of channels.







      ..
          !! processed by numpydoc !!


   .. py:method:: _process(tiles: deeptile.core.data.Tiled) -> Tuple[numpy.ndarray, numpy.ndarray]

      
      Process tiles.


      :Parameters:

          **tiles** : Tiled
              Tiles of images.



      :Returns:

          **labels** : np.ndarray
              Predicted labels.

          **deltas** : np.ndarray
              Predicted displacement vectors.











      ..
          !! processed by numpydoc !!


   .. py:method:: _postprocess_stack(labels: numpy.ndarray, deltas: numpy.ndarray, scales: numpy.ndarray, threshold: float, min_distance: int) -> deeptile.Output
      :staticmethod:


      
      Postprocess tiles.


      :Parameters:

          **labels** : np.ndarray
              Predicted labels.

          **deltas** : np.ndarray
              Predicted displacement vectors.

          **scales** : np.ndarray
              Scales for rescaling tiles.

          **threshold** : float
              Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to
              identify a spot.

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



      :Returns:

          **coords** : Output
              Predicted spot coordinates.











      ..
          !! processed by numpydoc !!


   .. py:method:: _apply(x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]

      
      Apply SpotsModel to a batch images.

      x : torch.Tensor
          Batch of images.




      :Returns:

          **labels** : np.ndarray
              Predicted binary labels.

          **deltas** : np.ndarray
              Predicted displacements vectors.











      ..
          !! processed by numpydoc !!


.. py:class:: Piscis(model_name: str = '20251212', batch_size: int = 1, input_size: Optional[Tuple[int, int]] = None, device: Optional[Union[str, torch.device]] = None)

   Bases: :py:obj:`_Piscis`


   
   Class for running the Piscis algorithm.



   :Attributes:

       **model_name** : str
           Model name.

       **batch_size** : int
           Batch size for the CNN.

       **adjustment** : str
           Adjustment type applied to images during preprocessing.

       **input_size** : Tuple[int, int]
           Input size for the CNN.

       **dilation_iterations** : int
           Number of iterations used to dilate ground truth labels during training.

       **channels** : int
           Number of channels in the input images.

       **device** : Optional[Union[str, torch.device]]
           Device to run the model on.

       **pooling** : str
           Pooling type applied to labels.

       **model** : SpotsModel
           Model.













   ..
       !! processed by numpydoc !!

   .. py:method:: predict(x: Union[numpy.ndarray, dask.array.Array], stack: bool = False, scale: float = 1.0, threshold: float = 0.5, min_distance: int = 1, intermediates: bool = False) -> Union[Tuple[numpy.ndarray, xarray.DataArray], numpy.ndarray]

      
      Predict spots in an image or stack of images.


      :Parameters:

          **x** : np.ndarray or da.Array
              Image or stack of images.

          **stack** : bool, optional
              Whether `x` is a stack of images. Default is False.

          **scale** : float, optional
              Scale factor for rescaling `x`. Default is 1.

          **threshold** : float, optional
              Spot detection threshold. Default is 0.5.

          **min_distance** : int, optional
              Minimum distance between spots. Default is 1.

          **intermediates** : bool, optional
              Whether to return intermediate feature maps. Default is False.



      :Returns:

          **coords** : np.ndarray
              Predicted spot coordinates.

          **y** : np.ndarray, optional
              Intermediate feature maps. Only returned if `intermediates` is True.











      ..
          !! processed by numpydoc !!


.. py:class:: PiscisLegacy(model_name: str = '20230905', batch_size: int = 1, input_size: Optional[Tuple[int, int]] = None, device: Optional[Union[str, torch.device]] = None)

   Bases: :py:obj:`_Piscis`


   
   Class for running the PyTorch port of the legacy Piscis algorithm originally implemented in JAX.



   :Attributes:

       **model_name** : str
           Model name.

       **batch_size** : int
           Batch size for the CNN.

       **adjustment** : str
           Adjustment type applied to images during preprocessing.

       **input_size** : Tuple[int, int]
           Input size for the CNN.

       **dilation_iterations** : int
           Number of iterations used to dilate ground truth labels during training.

       **channels** : int
           Number of channels in the input images.

       **device** : Optional[Union[str, torch.device]]
           Device to run the model on.

       **pooling** : str
           Pooling type applied to labels.

       **model** : SpotsModel
           Model.













   ..
       !! processed by numpydoc !!

   .. py:method:: predict(x: Union[numpy.ndarray, dask.array.Array], stack: bool = False, scale: float = 1.0, threshold: float = 1.0, min_distance: int = 1, intermediates: bool = False) -> Union[Tuple[numpy.ndarray, xarray.DataArray], numpy.ndarray]

      
      Predict spots in an image or stack of images.


      :Parameters:

          **x** : np.ndarray or da.Array
              Image or stack of images.

          **stack** : bool, optional
              Whether `x` is a stack of images. Default is False.

          **scale** : float, optional
              Scale factor for rescaling `x`. Default is 1.

          **threshold** : float, optional
              Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to
              identify a spot. Default is 1.0.

          **min_distance** : int, optional
              Minimum distance between spots. Default is 1.

          **intermediates** : bool, optional
              Whether to return intermediate feature maps. Default is False.



      :Returns:

          **coords** : np.ndarray
              Predicted spot coordinates.

          **y** : np.ndarray, optional
              Intermediate feature maps. Only returned if `intermediates` is True.











      ..
          !! processed by numpydoc !!


.. py:function:: adjust_parameters(y: xarray.DataArray, threshold: float = 0.5, min_distance: int = 1) -> numpy.ndarray

   
   Adjust tunable parameters for a given set of intermediate feature maps.


   :Parameters:

       **y** : xr.DataArray
           Intermediate feature maps.

       **threshold: float**
           Spot detection threshold. Default is 0.5.

       **min_distance** : int, optional
           Minimum distance between spots. Default is 1.



   :Returns:

       **coords** : np.ndarray
           Predicted spot coordinates.











   ..
       !! processed by numpydoc !!

