Utility functions¶
Check input quality¶
-
bigfish.stack.check_array(array, ndim=None, dtype=None, allow_nan=True)¶ Full safety check of an array.
- Parameters
- arraynp.ndarray
Array to check.
- ndimint or List[int]
Number of dimensions expected.
- dtypetype or List[type]
Types expected.
- allow_nanbool
Allow NaN values or not.
- Returns
- _bool
Assert if the array is well formatted.
-
bigfish.stack.check_df(df, features=None, features_without_nan=None)¶ Full safety check of a dataframe.
- Parameters
- dfpd.DataFrame or pd.Series
Dataframe or Series to check.
- featuresList[str]
Names of the expected features.
- features_without_nanList[str]
Names of the features to check for the missing values
- Returns
- _bool
Assert if the dataframe is well formatted.
-
bigfish.stack.check_parameter(**kwargs)¶ Check dtype of the function’s parameters.
- Parameters
- kwargsType or Tuple[Type]
Map of each parameter with its expected dtype.
- Returns
- _bool
Assert if the array is well formatted.
-
bigfish.stack.check_range_value(array, min_=None, max_=None)¶ Check the support of the array.
- Parameters
- arraynp.ndarray
Array to check.
- min_int
Minimum value allowed.
- max_int
Maximum value allowed.
- Returns
- _bool
Assert if the array has the right range of values.
Get constant values¶
-
bigfish.stack.get_margin_value()¶ Return the margin pixel around a cell coordinate used to define its bounding box.
- Returns
- _int
Margin value (in pixels).
-
bigfish.stack.get_eps_float32()¶ Return the epsilon value for a 32 bit float.
- Returns
- _np.float32
Epsilon value.
Load and check stored data¶
-
bigfish.stack.load_and_save_url(remote_url, directory, filename=None)¶ Download remote data and save them
- Parameters
- remote_urlstr
Remote url of the data to download.
- directorystr
Directory to save the download content.
- filenamestr
Filename of the object to save.
- Returns
- pathstr
Path of the downloaded file.
-
bigfish.stack.check_hash(path, expected_hash)¶ Check hash value of a file.
- Parameters
- pathstr
Path of the file to check.
- expected_hashstr
Expected hash value.
- Returns
- _bool
True if hash values match.
-
bigfish.stack.compute_hash(path)¶ Compute sha256 hash of a file.
- Parameters
- pathstr
Path to read the file.
- Returns
- sha256str
Hash value of the file.
-
bigfish.stack.check_input_data(input_directory, input_segmentation=False)¶ Check input images exists and download them if necessary.
- Parameters
- input_directorystr
Path of the image directory.
- input_segmentationbool
Check 2-d example images for segmentation.
Compute moving average¶
-
bigfish.stack.moving_average(array, n)¶ Compute a trailing average.
- Parameters
- arraynp.ndarray
Array used to compute moving average.
- nint
Window width of the moving average.
- Returns
- resultsnp.ndarray
Moving average values.
-
bigfish.stack.centered_moving_average(array, n)¶ Compute a centered moving average.
- Parameters
- arraynp.ndarray
Array used to compute moving average.
- nint
Window width of the moving average.
- Returns
- resultsnp.ndarray
Centered moving average values.
Convert pixels and nanometers¶
-
bigfish.detection.convert_spot_coordinates(spots, voxel_size)¶ Convert spots coordinates from pixel to nanometer.
- Parameters
- spotsnp.ndarray
Coordinates of the detected spots with shape (nb_spots, 3) or (nb_spots, 2).
- voxel_sizeint, float, Tuple(int, float) or List(int, float)
Size of a voxel, in nanometer. One value per spatial dimension (zyx or yx dimensions). If it’s a scalar, the same value is applied to every dimensions.
- Returns
- spots_nanometernp.ndarray
Coordinates of the detected spots with shape (nb_spots, 3) or (nb_spots, 3), in nanometer.
-
bigfish.detection.get_object_radius_pixel(voxel_size_nm, object_radius_nm, ndim)¶ Convert the object radius in pixel.
When the object considered is a spot this value can be interpreted as the standard deviation of the spot PSF, in pixel. For any object modelled with a gaussian signal, this value can be interpreted as the standard deviation of the gaussian.
- Parameters
- voxel_size_nmint, float, Tuple(int, float) or List(int, float)
Size of a voxel, in nanometer. One value per spatial dimension (zyx or yx dimensions). If it’s a scalar, the same value is applied to every dimensions.
- object_radius_nmint, float, Tuple(int, float) or List(int, float)
Radius of the object, in nanometer. One value per spatial dimension (zyx or yx dimensions). If it’s a scalar, the same radius is applied to every dimensions.
- ndimint
Number of spatial dimension to consider.
- Returns
- object_radius_pxTuple[float]
Radius of the object in pixel, one element per dimension (zyx or yx dimensions).
-
bigfish.detection.get_object_radius_nm(voxel_size_nm, object_radius_px, ndim)¶ Convert the object radius in nanometer.
When the object considered is a spot this value can be interpreted as the standard deviation of the spot PSF, in nanometer. For any object modelled with a gaussian signal, this value can be interpreted as the standard deviation of the gaussian.
- Parameters
- voxel_size_nmint, float, Tuple(int, float) or List(int, float)
Size of a voxel, in nanometer. One value per spatial dimension (zyx or yx dimensions). If it’s a scalar, the same value is applied to every dimensions.
- object_radius_pxint, float, Tuple(int, float) or List(int, float)
Radius of the object, in pixel. One value per spatial dimension (zyx or yx dimensions). If it’s a scalar, the same radius is applied to every dimensions.
- ndimint
Number of spatial dimension to consider.
- Returns
- object_radius_nmTuple[float]
Radius of the object in nanometer, one element per dimension (zyx or yx dimensions).
Format and save plots¶
-
bigfish.plot.save_plot(path_output, ext)¶ Save the plot.
- Parameters
- path_outputstr
Path to save the image (without extension).
- extstr or List[str]
Extension used to save the plot. If it is a list of strings, the plot will be saved several times.
-
bigfish.plot.get_minmax_values(tensor)¶ Get the minimum and maximum value of the image according to its dtype.
- Parameters
- tensornp.ndarray
A 2-d, 3-d or 5-d tensor with shape (y, x), (z, y, x) or (r, c, z, y, x) respectively.
- Returns
- vminint
Minimum value display in the plot.
- vmaxint
Maximum value display in the plot.
-
bigfish.plot.create_colormap()¶ Create a shuffled colormap to display segmentation masks.
- Returns
- colormapListedColormap object
Colormap for matplotlib.