Skip to content

Cutout process

cutana.cutout_process

Cutout process script for Cutana - handles individual cutout creation as subprocess.

This script is designed to be run as a subprocess and provides functions for: - FITS file loading and processing - Cutout extraction from FITS tiles - WCS coordinate transformation - Error handling for missing/corrupted files - Integration with image processor

Usage

Can be run as a script or imported for function use. Main entry point: create_cutouts_main()

create_cutouts_batch(source_batch, config, job_tracker, batch_info_out=None)

Create cutouts for a batch of sources with optimized FITS loading and sub-batch processing.

Groups sources by their FITS files at process level and loads each FITS file only once, processing sources in sub-batches to provide progress updates while maintaining FITS cache.

Parameters:

Name Type Description Default
source_batch List[Dict[str, Any]]

List of source dictionaries

required
config DotMap

Configuration DotMap

required
job_tracker JobTracker

JobTracker instance for progress reporting

required
batch_info_out Optional[Dict[str, Any]]

Optional dict populated in place with this batch's structure and per-stage performance breakdown (sources_per_fits_set, performance). Lets the caller surface these via the orchestrator's worker events without parsing stderr logs (issue #354). Ignored when None.

None

Returns:

Type Description
List[Dict[str, Any]]

List of results for each source

Raises:

Type Description
Exception

whatever failed, re-raised after logging. The caller needs a failed batch to be distinguishable from an empty one (#425).

create_cutouts_main()

Main entry point for subprocess execution.

Expects command line arguments: 1. JSON string containing source batch data 2. JSON string containing configuration

stream_cutouts_via_shm_pool(batch_results, process_id, config, batch_info=None)

Stream cutouts to parent via a pre-allocated shared memory pool.

The pool is created by the orchestrator and this worker attaches to it. Cutouts are written into pool slots, then signaled as ready via stdout. The worker waits for an ACK before reusing slots for the next chunk.

Parameters:

Name Type Description Default
batch_results List[Dict[str, Any]]

List of batch result dicts with 'cutouts' and 'metadata'

required
process_id str

Unique process identifier

required
config DotMap

Config with shm_pool_name, shm_control_name, shm_pool_config

required
batch_info Optional[Dict[str, Any]]

Optional FITS-set composition + per-stage performance breakdown, echoed back to the orchestrator on the complete message so it can be exposed via worker events (issue #354).

None