psf_generator.utils.handle_data#

A collection of functions to handle loading and saving of data and image.

  • image uses common image formats, e.g., .tif

  • npy uses numpy data format .npy for images

  • csv uses .csv for statistical data

Notes#

save_image follows convention (spatial dimensions, channels), i.e. it changes the axes of the input image. For tests, we save images in .npy format to avoid this inconvenience.

Functions#

load_image(filepath)

Load data from filepath.

save_image(filepath, image)

Save image in specified format to specified location.

save_as_npy(filepath, input_data)

Save data as a numpy array in a .npy file.

load_from_npy(→ numpy.ndarray)

Load numpy array from a file.

save_stats_as_csv(filepath, data)

Save statistical data to a csv file for further analysis or plotting.

load_stats_from_csv(filepath)

Load data from a csv file.

Module Contents#

psf_generator.utils.handle_data.load_image(filepath: str)[source]#

Load data from filepath.

Parameters#

filepathstr

Path to the file.

psf_generator.utils.handle_data.save_image(filepath: str, image: torch.Tensor | numpy.ndarray)[source]#

Save image in specified format to specified location.

Parameters#

filepathstr

Path to save the file.

imagetorch.Tensor or np.ndarray

Image to be saved.

Notes#

Scikit-image and tifffile both follow the convention of putting the channel dimension after x and y. The saved tif image thus has dimension (z, x, y, channels) instead of (z, channels, x, y).

psf_generator.utils.handle_data.save_as_npy(filepath: str, input_data: torch.Tensor | numpy.ndarray)[source]#

Save data as a numpy array in a .npy file.

Parameters#

filepathstr

Path to save the file.

input_datatorch.Tensor or np.ndarray

Data to be saved

psf_generator.utils.handle_data.load_from_npy(filepath: str) numpy.ndarray[source]#

Load numpy array from a file.

Parameters#

filepathstr

Path to file.

Returns#

outputnp.ndarray

Loaded array.

psf_generator.utils.handle_data.save_stats_as_csv(filepath: str, data: list)[source]#

Save statistical data to a csv file for further analysis or plotting.

Statistical data such as the runtime values is saved as a list of tuples (index, value).

Parameters#

filepathstr

Path to the file to store the statistics.

datalist

Statistics to be saved.

psf_generator.utils.handle_data.load_stats_from_csv(filepath: str)[source]#

Load data from a csv file.

Parameters#

filepath: str

Path to the csv file.