I/O operations
Functions used to read data from various sources and store them in a numpy array.
Read files
Read image, video and numerical data as a numpy array:
Read a zipped archive of files as a dictionary-like object:
Read CSV file:
- bigfish.stack.read_image(path, sanity_check=False)
Read an image with
png
,jpg
,jpeg
,tif
ortiff
extension.- Parameters:
- pathstr
Path of the image to read.
- sanity_checkbool
Check if the array returned fits with bigfish pipeline.
- Returns:
- imagendarray, np.uint or np.int
Image read.
- bigfish.stack.read_dv(path, sanity_check=False)
Read a video file with
dv
extension.- Parameters:
- pathstr
Path of the file to read.
- sanity_checkbool
Check if the array returned fits with bigfish pipeline.
- Returns:
- videondarray
Video read.
- bigfish.stack.read_array(path)
Read a numpy array with
npy
extension.- Parameters:
- pathstr
Path of the array to read.
- Returns:
- arrayndarray
Array read.
- bigfish.stack.read_uncompressed(path, verbose=False)
Read a NpzFile object with
npz
extension.- Parameters:
- pathstr
Path of the file to read.
- verbosebool
Return names of the different objects.
- Returns:
- dataNpzFile object
NpzFile read.
- bigfish.stack.read_cell_extracted(path, verbose=False)
Read a NpzFile object with
npz
extension, previously written withbigfish.stack.save_cell_extracted()
.- Parameters:
- pathstr
Path of the file to read.
- verbosebool
Return names of the different objects.
- Returns:
- cell_resultsDict
Dictionary including information about the cell (image, masks, coordinates arrays). Minimal information are:
cell_id: Unique id of the cell.
bbox: bounding box coordinates with the order (min_y, min_x, max_y, max_x).
cell_coord: boundary coordinates of the cell.
cell_mask: mask of the cell.
- bigfish.stack.read_array_from_csv(path, dtype=None, delimiter=';', encoding='utf-8', skiprows=0)
Read a numpy array saved in a
csv
file.- Parameters:
- pathstr
Path of the
csv
file to read.- dtypetype, optional
Expected dtype to cast the array.
- delimiterstr, default=”;”
Delimiter used to separate columns.
- encodingstr, default=”utf-8”
Encoding to use.
- skiprowsint, default=0
Skip the first skiprows lines of the file. Useful to skip the first rows of a csv with header.
- Returns:
- arrayndarray
Array read.
- bigfish.stack.read_dataframe_from_csv(path, delimiter=';', encoding='utf-8')
Read a numpy array or a pandas object saved in a
csv
file.- Parameters:
- pathstr
Path of the
csv
file to read.- delimiterstr
Delimiter used to separate columns.
- encodingstr
Encoding to use.
- Returns:
- dfpd.DataFrame
Pandas object read.
Write files
Save numpy array:
Save cell-level results in a zipped archive of files:
Save tabular data in a CSV file:
- bigfish.stack.save_image(image, path, extension='tif')
Save an image.
The input image should have between 2 and 5 dimensions, with boolean, (unsigned) integer, or float.
The dimensions should be in the following order: (round, channel, z, y, x).
- Parameters:
- imagenp.ndarray
Image to save.
- pathstr
Path of the saved image.
- extensionstr
Default extension to save the image (among
png
,jpg
,jpeg
,tif
ortiff
).
Notes
If the image has more than 2 dimensions,
tif
andtiff
extensions are required (png
extension does not handle 3-d images other than (M, N, 3) or (M, N, 4) shapes).A 2-d boolean image can be saved in
png
,jpg
orjpeg
(cast in np.uint8).A multidimensional boolean image should be saved with
bigfish.stack.save_array()
or as a boolean images withtif
/tiff
extension.
- bigfish.stack.save_array(array, path)
Save an array in a
npy
extension file.The input array should have between 2 and 5 dimensions, with boolean, (unsigned) integer, or float.
- Parameters:
- arraynp.ndarray
Array to save.
- pathstr
Path of the saved array.
- bigfish.stack.save_cell_extracted(cell_results, path)
Save cell-level results from
bigfish.stack.extract_cell()
in a NpzFile object withnpz
extension.- Parameters:
- cell_resultsDict
Dictionary including information about the cell (image, masks, coordinates arrays). Minimal information are:
cell_id: Unique id of the cell.
bbox: bounding box coordinates with the order (min_y, min_x, max_y, max_x).
cell_coord: boundary coordinates of the cell.
cell_mask: mask of the cell.
- pathstr
Path of the saved array.
- bigfish.stack.save_data_to_csv(data, path, delimiter=';')
Save a numpy array or a pandas object into a
csv
file.The input should be a pandas object (Series or DataFrame) or a numpy array with 2 dimensions and (unsigned) integer or float.
- Parameters:
- datanp.ndarray, pd.Series or pd.DataFrame
Data to save.
- pathstr
Path of the saved
csv
file.- delimiterstr
Delimiter used to separate columns.