lunar_toolkit.csm

Read, write and resample USGS CSM linescan cameras (ISD and model state) to match ISIS reduce / crop.

CsmCamera(data, kind, header=None) dataclass

A CSM camera file: an ALE / isd_generate ISD or a USGS CSM model state.

Attributes:
  • data (dict) –

    The parsed JSON (ISD keys such as image_lines or state keys such as m_nLines).

  • kind ({'isd', 'state'}) –
  • header (str or None) –

    For a state, the model-name line that precedes the JSON in getModelState() output and ASP .adjusted_state.json files (None when the file is bare JSON).

size property

(samples, lines) of the image the camera describes.

CubeGeometry(samples, lines, alpha_samples, alpha_lines, sample_scale=1.0, sample_offset=0.0, line_scale=1.0, line_offset=0.0) dataclass

Size of an ISIS cube and its pixel mapping onto the original (alpha) image.

alpha = scale * beta + offset per axis in CSM coordinates (pixel edges at integers), from the cube's AlphaCube group (identity when absent).

parse_camera(text)

Parse a CSM camera from text (ISD JSON, or a model state with or without its name line).

read_camera(path)

Read a CSM camera file (.json ISD, model state or ASP .adjusted_state.json).

format_camera(cam)

Text of cam in its original layout (state name line kept).

transform_camera(cam, sample_scale, sample_offset, line_scale, line_offset, size)

Camera for an image whose pixels map affinely onto cam's image.

CSM image coordinates put the top-left pixel edge at 0 (first pixel centre at 0.5). A point at (x, y) of the new image is (sample_scale * x + sample_offset, line_scale * y + line_offset) of the old one. Across track this scales the detector sample summing and shifts the starting detector sample; along track it scales the integration times (and the line summing, which converts the residual detector-line offset into image lines in groundToImage) and moves the integration start lines so that line y is exposed when old line line_scale * y + line_offset was.

Parameters:
  • cam (CsmCamera) –

    A USGS linescan ISD or state.

  • sample_scale (float) –

    The mapping above (ISIS reduce by f: scales f, offsets 0; ISIS crop from sample s, line l: scales 1, offsets s - 1, l - 1).

  • sample_offset (float) –

    The mapping above (ISIS reduce by f: scales f, offsets 0; ISIS crop from sample s, line l: scales 1, offsets s - 1, l - 1).

  • line_scale (float) –

    The mapping above (ISIS reduce by f: scales f, offsets 0; ISIS crop from sample s, line l: scales 1, offsets s - 1, l - 1).

  • line_offset (float) –

    The mapping above (ISIS reduce by f: scales f, offsets 0; ISIS crop from sample s, line l: scales 1, offsets s - 1, l - 1).

  • size ((samples, lines)) –

    Size of the new image.

Returns:
  • CsmCamera –

    A new camera of the same kind.

reduce_camera(camera, factor, out_json=None, size=None)

CSM camera of an image averaged by factor (ISIS reduce, mode=scale).

reduce output pixel k (0-based) averages input pixels k*f .. k*f + f - 1, so in CSM coordinates (pixel edges at integers) the mapping is a pure scale by f: summing and integration times grow by f, sizes shrink by f.

Parameters:
  • camera (Path or CsmCamera) –

    ISD or state of the full-resolution image.

  • factor (float) –

    sscale = lscale.

  • out_json (Path, default: None ) –

    Where to write the result (same format as the input).

  • size ((samples, lines), default: None ) –

    Size of the reduced image; default ceil(size / factor).

read_isis_label(cube, max_bytes=1 << 22)

The attached PVL label of an ISIS cube (text up to the closing End).

camera_for_cube(cam, cube, source=None)

Re-map cam so it describes cube pixel for pixel.

cam is taken to describe the original (alpha) image when its size matches cube.alpha_* (cameras from isd_generate on the uncropped cube, as in the ASP LRONAC example), else the source cube that cube was derived from (reduce / crop of a cube whose own camera was written for it).

isis_reduce_with_csm(cube, camera, factor, out_dir, algorithm='average', force=False)

ISIS reduce a cube by factor and write the matching CSM camera.

Parameters:
  • cube (Path) –

    Input ISIS cube (may be a crop: its AlphaCube is honoured).

  • camera (Path) –

    CSM ISD or state of the original image or of cube.

  • factor (int) –

    sscale = lscale.

  • out_dir (Path) –

    Receives <cube stem>.red<factor>.cub and <camera stem>.red<factor>.json (same CSM format as camera).

  • algorithm (str, default: 'average' ) –

    reduce algorithm (average as in Bertone et al. 2026, App. A).

  • force (bool, default: False ) –

    Redo existing outputs.

Returns:
  • (reduced_cube, reduced_camera) –