jetraw_tools.compression_tool.CompressionTool

class jetraw_tools.compression_tool.CompressionTool[source]

Bases: object

A tool for compressing and decompressing images using the JetRaw algorithm.

Handles batch processing of images with metadata preservation options.

Parameters:
  • calibration_file (str, optional) – Path to the JetRaw calibration file

  • identifier (str, optional) – Camera identifier for the compression settings

  • ncores (int, optional) – Number of CPU cores to use (0 for auto-detection)

  • omit_processed (bool, optional) – Skip files that have already been processed

  • verbose (bool, optional) – Enable detailed logging output

Raises:

FileNotFoundError – If the specified calibration file doesn’t exist

No-index:

__init__(calibration_file=None, identifier='', ncores=0, omit_processed=True, verbose=False, metadata_format='ome')[source]
No-index:

Parameters:
  • calibration_file (str | None)

  • identifier (str)

  • omit_processed (bool)

  • verbose (bool)

  • metadata_format (str)

Methods

__init__([calibration_file, identifier, ...])

compress_image(img_map, target_file, metadata)

Compress an image using JetRaw algorithm.

decompress_image(img_map, target_file, metadata)

Decompress a JetRaw image to standard TIFF.

list_files(folder_path, image_extension)

List all files in a folder with a specific extension.

process_folder(folder_path[, mode, ...])

Process a folder of images using parallel processing.

process_image(folder_path, output_folder, ...)

Process a single image for compression or decompression.

remove_files(output_tiff_filename, ...)

Remove original file after successful compression.

compress_image(img_map, target_file, metadata, ome_bool=True, metadata_json=True)[source]

Compress an image using JetRaw algorithm.

Parameters:
  • img_map (ndarray) – NumPy array containing the image data

  • target_file (str) – Output path for the compressed file

  • metadata (dict) – Dictionary containing image metadata

  • ome_bool (bool) – Save metadata in OME format

  • metadata_json (bool) – Additionally save metadata as JSON

Return type:

bool

Returns:

True if compression was successful

decompress_image(img_map, target_file, metadata, ome_bool=True, metadata_json=False)[source]

Decompress a JetRaw image to standard TIFF.

Parameters:
  • img_map (ndarray) – NumPy array containing the image data

  • target_file (str) – Output path for the decompressed file

  • metadata (dict) – Dictionary containing image metadata

  • ome_bool (bool) – Save metadata in OME format

  • metadata_json (bool) – Additionally save metadata as JSON

Return type:

bool

Returns:

True if decompression was successful

list_files(folder_path, image_extension)[source]

List all files in a folder with a specific extension.

Parameters:
  • folder_path (str) – The path to the folder.

  • image_extension (str) – The image file extension.

Return type:

list

Returns:

A list of image files.

process_folder(folder_path, mode='compress', image_extension='.tiff', process_metadata=True, ome_bool=None, metadata_json=True, remove_source=False, target_folder=None)[source]

Process a folder of images using parallel processing.

Parameters:
  • folder_path (str) – The path to the folder.

  • mode (str) – The mode, either “compress” or “decompress”.

  • image_extension (str) – The image file extension.

  • process_metadata (bool) – Whether to process metadata.

  • ome_bool (Optional[bool]) – Whether to write OME metadata. If None (default), derived from the instance’s metadata_format (‘ome’ -> True, ‘imagej’ -> False).

  • metadata_json (bool) – Whether to write metadata as JSON.

  • remove_source (bool) – Whether to remove the source files.

  • target_folder (Optional[str]) – Optional target folder for processed images.

Return type:

bool

process_image(folder_path, output_folder, image_file, mode, image_extension, process_metadata, ome_bool, metadata_json, remove_source, progress_info)[source]

Process a single image for compression or decompression.

Worker function used by the parallel processing pool.

Parameters:
  • folder_path (str) – The path to the folder containing the image.

  • output_folder (str) – The path to the folder where the processed image will be saved.

  • image_file (str) – The name of the image file to process.

  • mode (str) – The mode, either “compress” or “decompress”.

  • image_extension (str) – The image file extension.

  • process_metadata (bool) – Whether to process metadata.

  • ome_bool (bool) – Whether to use OME metadata.

  • metadata_json (bool) – Whether to write metadata as JSON.

  • remove_source (bool) – Whether to remove the source files after processing.

  • progress_info (tuple) – The total number of files to process.

Return type:

int

Returns:

None

remove_files(output_tiff_filename, input_filename)[source]

Remove original file after successful compression.

Only removes if the compressed file exists and is at least 5% of the original size.

Parameters:
  • output_tiff_filename (str) – The output TIFF filename.

  • input_filename (str) – The input filename.

Return type:

None