piscis.core#
Classes#
Base class for running the Piscis algorithm. |
|
Class for running the Piscis algorithm. |
|
Class for running the PyTorch port of the legacy Piscis algorithm originally implemented in JAX. |
Functions#
|
Adjust tunable parameters for a given set of intermediate feature maps. |
Module Contents#
- class piscis.core._Piscis(model_name: str, batch_size: int, input_size: Tuple[int, int] | None, device: str | torch.device | None, pooling: str)#
Base class for running the Piscis algorithm.
- Attributes:
- model_namestr
Model name.
- batch_sizeint
Batch size for the CNN.
- adjustmentstr
Adjustment type applied to images during preprocessing.
- input_sizeTuple[int, int]
Input size for the CNN.
- dilation_iterationsint
Number of iterations used to dilate ground truth labels during training.
- channelsint
Number of channels in the input images.
- deviceOptional[Union[str, torch.device]]
Device to run the model on.
- poolingstr
Pooling type applied to labels.
- modelSpotsModel
Model.
- model_name#
- batch_size#
- device#
- pooling#
- model#
- _predict(x: numpy.ndarray | dask.array.Array, stack: bool, scale: float, threshold: float, min_distance: int, intermediates: bool) Tuple[numpy.ndarray, xarray.DataArray] | numpy.ndarray#
Predict spots in an image or stack of images.
- Parameters:
- xnp.ndarray or da.Array
Image or stack of images.
- stackbool, optional
Whether x is a stack of images.
- scalefloat, optional
Scale factor for rescaling x.
- thresholdfloat, optional
Spot detection threshold.
- min_distanceint, optional
Minimum distance between spots.
- intermediatesbool, optional
Whether to return intermediate feature maps.
- Returns:
- coordsnp.ndarray
Predicted spot coordinates.
- ynp.ndarray, optional
Intermediate feature maps. Only returned if intermediates is True.
- _predict_stack(tiles: deeptile.core.data.Tiled, stack_axis_len: int, scales: numpy.ndarray, threshold: float, min_distance: int, intermediates: bool) Tuple[deeptile.Output, numpy.ndarray] | deeptile.Output#
Predict spots in a stack of images.
- Parameters:
- tilesTiled
Tiles of images.
- stack_axis_lenint
Length of the stack axis.
- scalesnp.ndarray
Scales for rescaling tiles.
- thresholdfloat
Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to identify a spot.
- min_distanceint
Minimum distance between spots.
- intermediatesbool
Whether to return intermediate feature maps.
- Returns:
- coordsOutput
Predicted spot coordinates.
- ynp.ndarray, optional
Intermediate feature maps. Only returned if intermediates is True.
- _predict_plane(tiles: deeptile.core.data.Tiled, scales: numpy.ndarray, threshold: float, min_distance: int, intermediates: bool) Tuple[deeptile.Output, numpy.ndarray] | deeptile.Output#
Predict spots in a single plane.
- Parameters:
- tilesTiled
Tiles of images.
- scalesnp.ndarray
Scales for rescaling tiles.
- thresholdfloat
Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to identify a spot.
- min_distanceint
Minimum distance between spots.
- intermediatesbool
Whether to return intermediate feature maps.
- Returns:
- coordsOutput
Predicted spot coordinates.
- ynp.ndarray, optional
Intermediate feature maps. Only returned if intermediates is True.
- _preprocess(x: numpy.ndarray | dask.array.Array, stack: bool) Tuple[dask.array.Array, bool]#
Preprocess the input.
- Parameters:
- xnp.ndarray or dask.array.Array
Image or stack of images.
- stackbool
Whether x is a stack of images.
- Returns:
- xUnion[np.ndarray, da.Array]
Preprocessed image or stack of images.
- batch_axisbool
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.
- _process(tiles: deeptile.core.data.Tiled) Tuple[numpy.ndarray, numpy.ndarray]#
Process tiles.
- Parameters:
- tilesTiled
Tiles of images.
- Returns:
- labelsnp.ndarray
Predicted labels.
- deltasnp.ndarray
Predicted displacement vectors.
- static _postprocess_stack(labels: numpy.ndarray, deltas: numpy.ndarray, scales: numpy.ndarray, threshold: float, min_distance: int) deeptile.Output#
Postprocess tiles.
- Parameters:
- labelsnp.ndarray
Predicted labels.
- deltasnp.ndarray
Predicted displacement vectors.
- scalesnp.ndarray
Scales for rescaling tiles.
- thresholdfloat
Spot detection threshold. Can be interpreted as the minimum number of fully confident pixels necessary to identify a spot.
- min_distanceint
Minimum distance between spots.
- Returns:
- coordsOutput
Predicted spot coordinates.
- _apply(x: torch.Tensor) Tuple[torch.Tensor, torch.Tensor]#
Apply SpotsModel to a batch images.
- xtorch.Tensor
Batch of images.
- Returns:
- labelsnp.ndarray
Predicted binary labels.
- deltasnp.ndarray
Predicted displacements vectors.
- class piscis.core.Piscis(model_name: str = '20251212', batch_size: int = 1, input_size: Tuple[int, int] | None = None, device: str | torch.device | None = None)#
Bases:
_PiscisClass for running the Piscis algorithm.
- Attributes:
- model_namestr
Model name.
- batch_sizeint
Batch size for the CNN.
- adjustmentstr
Adjustment type applied to images during preprocessing.
- input_sizeTuple[int, int]
Input size for the CNN.
- dilation_iterationsint
Number of iterations used to dilate ground truth labels during training.
- channelsint
Number of channels in the input images.
- deviceOptional[Union[str, torch.device]]
Device to run the model on.
- poolingstr
Pooling type applied to labels.
- modelSpotsModel
Model.
- predict(x: numpy.ndarray | dask.array.Array, stack: bool = False, scale: float = 1.0, threshold: float = 0.5, min_distance: int = 1, intermediates: bool = False) Tuple[numpy.ndarray, xarray.DataArray] | numpy.ndarray#
Predict spots in an image or stack of images.
- Parameters:
- xnp.ndarray or da.Array
Image or stack of images.
- stackbool, optional
Whether x is a stack of images. Default is False.
- scalefloat, optional
Scale factor for rescaling x. Default is 1.
- thresholdfloat, optional
Spot detection threshold. Default is 0.5.
- min_distanceint, optional
Minimum distance between spots. Default is 1.
- intermediatesbool, optional
Whether to return intermediate feature maps. Default is False.
- Returns:
- coordsnp.ndarray
Predicted spot coordinates.
- ynp.ndarray, optional
Intermediate feature maps. Only returned if intermediates is True.
- class piscis.core.PiscisLegacy(model_name: str = '20230905', batch_size: int = 1, input_size: Tuple[int, int] | None = None, device: str | torch.device | None = None)#
Bases:
_PiscisClass for running the PyTorch port of the legacy Piscis algorithm originally implemented in JAX.
- Attributes:
- model_namestr
Model name.
- batch_sizeint
Batch size for the CNN.
- adjustmentstr
Adjustment type applied to images during preprocessing.
- input_sizeTuple[int, int]
Input size for the CNN.
- dilation_iterationsint
Number of iterations used to dilate ground truth labels during training.
- channelsint
Number of channels in the input images.
- deviceOptional[Union[str, torch.device]]
Device to run the model on.
- poolingstr
Pooling type applied to labels.
- modelSpotsModel
Model.
- predict(x: numpy.ndarray | dask.array.Array, stack: bool = False, scale: float = 1.0, threshold: float = 1.0, min_distance: int = 1, intermediates: bool = False) Tuple[numpy.ndarray, xarray.DataArray] | numpy.ndarray#
Predict spots in an image or stack of images.
- Parameters:
- xnp.ndarray or da.Array
Image or stack of images.
- stackbool, optional
Whether x is a stack of images. Default is False.
- scalefloat, optional
Scale factor for rescaling x. Default is 1.
- thresholdfloat, 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_distanceint, optional
Minimum distance between spots. Default is 1.
- intermediatesbool, optional
Whether to return intermediate feature maps. Default is False.
- Returns:
- coordsnp.ndarray
Predicted spot coordinates.
- ynp.ndarray, optional
Intermediate feature maps. Only returned if intermediates is True.
- piscis.core.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:
- yxr.DataArray
Intermediate feature maps.
- threshold: float
Spot detection threshold. Default is 0.5.
- min_distanceint, optional
Minimum distance between spots. Default is 1.
- Returns:
- coordsnp.ndarray
Predicted spot coordinates.