ptyrad.io.generic#
Generic file handling (load/save) for raw, npy, and tif formats
Functions
|
Loads an array from a binary NumPy .npy file. |
|
Loads a raw binary file containing interleaved image data and gaps. |
|
Loads an image array from a TIFF file. |
|
Saves a NumPy array to a binary .npy file. |
|
Saves a NumPy array as a TIFF file. |
- ptyrad.io.generic.load_raw(file_path, shape, dtype=<class 'numpy.float32'>, offset=0, gap=1024)[source]#
Loads a raw binary file containing interleaved image data and gaps.
This implementation uses a custom numpy.dtype with np.fromfile for fast I/O performance, extracting only the valid data regions and skipping the specified byte gaps between frames. Note that custom processed raw data might have a gap of 0.
- Parameters:
file_path (str) – The path to the raw binary file.
shape (tuple of int) – The expected shape of the data in the format (N, height, width), where N is the number of frames.
dtype (data-type, optional) – The NumPy data type of the image pixels. Defaults to np.float32.
offset (int, optional) – The number of bytes to skip at the beginning of the file. Defaults to 0.
gap (int, optional) – The number of gap bytes to skip between each image frame. Defaults to 1024.
- Returns:
An array of the extracted data with the specified shape and dtype.
- Return type:
numpy.ndarray
- Raises:
ValueError – If the actual file size does not match the expected size calculated from the inputs.
- ptyrad.io.generic.load_tif(file_path)[source]#
Loads an image array from a TIFF file.
- Parameters:
file_path (str) – The path to the TIFF file.
- Returns:
The loaded image data.
- Return type:
numpy.ndarray
- Raises:
FileNotFoundError – If the specified file does not exist.
- ptyrad.io.generic.load_npy(file_path)[source]#
Loads an array from a binary NumPy .npy file.
- Parameters:
file_path (str) – The path to the .npy file.
- Returns:
The loaded array data.
- Return type:
numpy.ndarray
- Raises:
FileNotFoundError – If the specified file does not exist.
- ptyrad.io.generic.write_tif(file_path, data)[source]#
Saves a NumPy array as a TIFF file.
The file is saved with ImageJ compatibility enabled to ensure proper handling of hyperstacks and metadata in common microscopy viewers.
- Parameters:
file_path (str) – The destination path for the TIFF file.
data (numpy.ndarray) – The array data to save.