radioviz.services.image_loader

Image loading service for RadioViz application.

This module provides asynchronous image loading capabilities supporting multiple file formats including TIFF, XYZ, and standard image formats. It implements background thread workers with progress reporting and cancellation support.

Functions

downscale_image(input_image, factor)

Classes

ImageLoaderService()

Service for managing asynchronous image loading operations.

class radioviz.services.image_loader.ImageLoaderService[source]

Bases: QObject

Service for managing asynchronous image loading operations.

This service provides methods to start image loading operations in background threads, track their progress, and handle completion or failure events. It supports cancellation of ongoing operations and manages the lifecycle of worker threads.

See also

_ImageLoaderWorker for the internal worker implementation

Initialize the image loader service.

Creates internal data structures to track active workers and canceled operations.

_forward_progress(path: Path, progress: int) None[source]

Forward progress signal from worker to service observers.

This internal method ensures that progress updates are only forwarded if the operation hasn’t been canceled.

Parameters:
  • path (Path) – Path to the image file being loaded

  • progress (int) – Loading progress percentage (0-100)

cancel(path: Path) None[source]

Cancel an ongoing image loading operation.

If there is an active worker for the specified path, this method will request cancellation of that operation.

Parameters:

path (Path) – Path to the image file whose loading should be cancelled

clean_up(worker: _ImageLoaderWorker) None[source]

Clean up resources after worker thread finishes.

Removes the worker from tracking structures and schedules it for deletion.

Parameters:

worker (_ImageLoaderWorker) – The worker thread that finished

load(path: Path) None[source]

Start loading an image in a background thread.

This method creates a new worker thread to load the specified image file asynchronously. Progress updates and completion/failure signals are forwarded through the service’s signals.

Parameters:

path (Path) – Path to the image file to load

image_load_failed

Signal emitted when image loading fails.

Parameters:
  • path (Path) – Path to the image file that failed to load

  • exception (Exception) – Exception that occurred during loading

image_loaded

Signal emitted when an image is successfully loaded.

Parameters:
  • path (Path) – Path to the loaded image file

  • array (numpy.ndarray) – Loaded image data as numpy array

  • metadata (dict[str, Any]) – Extracted image metadata

progress

Signal emitted to report loading progress for a specific image.

Parameters:
  • path (Path) – Path to the image file being loaded

  • percentage (int) – Loading progress percentage (0-100)

class radioviz.services.image_loader._ImageLoaderWorker(path: Path)[source]

Bases: QThread

Worker thread for loading images asynchronously.

This class handles the actual image loading process in a separate thread, providing progress updates and emitting signals when loading is complete or fails.

See also

ImageLoaderService for the main service interface

Initialize the image loader worker.

Parameters:

path (Path) – Path to the image file to load

cancel() None[source]

Request cancellation of the image loading operation.

This method requests interruption of the worker thread, which will cause the loading to stop and emit a failure signal with a RuntimeError.

run() None[source]

Execute the image loading operation.

This method runs in a separate thread and performs the actual file reading and image loading. It reports progress and emits appropriate signals based on the outcome of the operation.

failed

Signal emitted when image loading fails.

Parameters:
  • path (Path) – Path to the image file that failed to load

  • exception (Exception) – Exception that occurred during loading

image_loaded

Signal emitted when image loading is successful.

Parameters:
  • path (Path) – Path to the loaded image file

  • array (numpy.ndarray) – Loaded image data as numpy array

  • metadata (dict[str, Any]) – Extracted image metadata

progress

Signal emitted to report loading progress.

Parameters:

percentage (int) – Loading progress percentage (0-100)