CtbRawFile

class aare.CtbRawFile(fname, chunk_size=1, transform=None)

Bases: CtbRawFile

File reader for the CTB raw file format.

Parameters:
  • fname (pathlib.Path | str) – Path to the file to be read.

  • chunk_size (int) – Number of frames to read at a time. Default is 1.

  • transform (function) – Function to apply to the data after reading it. The function should take a numpy array of type uint8 and return one or several numpy arrays.

property frames_in_file: int

Return the number of frames in the file.

Returns:

Number of frames in file.

Return type:

int

property image_size_in_bytes: int

Return the size of the image in bytes.

Returns:

Size of image in bytes.

Return type:

int

property master

Return the master file.

Returns:

Master file.

Return type:

RawMasterFile

read() tuple

Read the entire file. Seeks to the beginning of the file before reading.

Returns:

header, data

Return type:

tuple

read_frame(frame_index: int | None = None) tuple

Read one frame from the file and then advance the file pointer.

Note

Uses the position of the file pointer tell() to determine which frame to read unless frame_index is specified.

Parameters:

frame_index (int) – If not None, seek to this frame before reading.

Returns:

header, data

Return type:

tuple

Raises:

RuntimeError – If the file is at the end.

read_n(n_frames: int) tuple

Read several frames from the file.

Note

Uses the position of the file pointer tell() to determine where to start reading from.

If the number of frames requested is larger than the number of frames left in the file, the function will read the remaining frames. If no frames are left in the file a RuntimeError is raised.

Parameters:

n_frames (int) – Number of frames to read.

Returns:

header, data

Return type:

tuple

Raises:

RuntimeError – If EOF is reached.

property scan_parameters

Return the scan parameters.

Returns:

Scan parameters.

Return type:

ScanParameters

seek(frame_index: int) None

Seek to a specific frame in the file.

Parameters:

frame_index (int) – Frame position in file to seek to.

tell() int

Return the current frame position in the file.

Returns:

Frame position in file.

Return type:

int