asp_plot.selections#

Reproducible “figure selections” for asp_plot reports.

When re-processing the same scene with different ASP parameters, the diagnostic figures silently change what they show between runs: a fresh ICESat-2 request returns a slightly different point set, the “best” profile track flips, the best/worst agreement segments move, and the detailed-hillshade clip boxes are re-selected from the (re-processed) intersection-error raster. That makes before/after comparison impossible.

This module persists every non-deterministic selection a run made to a small YAML sidecar next to the report, and reads it back so a later run can replay the same choices. It deliberately imports nothing from report.py / fpdf so it stays safe to use from notebooks.

See issue: uw-cryo/asp_plot#121

Attributes#

Classes#

FigureSelections

Container for the reproducible selections made while building a report.

Functions#

bbox_to_pixel_offset(transform, bbox)

Convert a map-coordinate bbox to a top-left pixel offset (row, col).

pixel_window_to_bbox(transform, row, col, n_rows, n_cols)

Convert a pixel window (top-left row/col + size) to a map-coordinate bbox.

read_selections_yaml(path)

Read a FigureSelections from a YAML file.

reproject_bbox(bbox, src_crs, dst_crs)

Reproject a map-coordinate bbox from one CRS to another.

write_selections_yaml(path, selections)

Write a FigureSelections to a YAML file.

Module Contents#

class asp_plot.selections.FigureSelections#

Container for the reproducible selections made while building a report.

All nested values are plain JSON/YAML-serializable types (dicts, lists, numbers, strings) so the object round-trips cleanly through YAML.

asp_plot_version#

asp_plot version that wrote the file (informational).

Type:

str or None

dem_filename#

DEM the selections were computed against (informational).

Type:

str or None

map_crs#

Map CRS string used by the report (informational).

Type:

str or None

detailed_hillshade#

{"subset_km": float, "intersection_error_percentiles": [..], "dem_crs": "EPSG:XXXX", "clips": [{"label": str, "bbox": [xmin, ymin, xmax, ymax], "pixel_offset": [row, col]}, ...]}. bbox is in dem_crs map coordinates (robust to a re-gridded DEM).

Type:

dict or None

icesat2#

{"request": {..}, "parquet_cache": {key: path}, "profile_track": {"rgt": int, "cycle": int, "spot": int}, "segments": {"best": {..}, "worst": {..}}}. Omitted (None) for planetary DEMs.

Type:

dict or None

classmethod from_dict(data)#

Build a FigureSelections from a parsed YAML/JSON dict.

to_dict()#

Return a plain dict suitable for YAML serialization.

asp_plot_version: str | None = None#
dem_filename: str | None = None#
detailed_hillshade: dict | None = None#
icesat2: dict | None = None#
map_crs: str | None = None#
schema_version: int = 1#
asp_plot.selections.bbox_to_pixel_offset(transform, bbox)#

Convert a map-coordinate bbox to a top-left pixel offset (row, col).

The window size is not returned: on reuse the subset size is recomputed from subset_km and the current DEM’s GSD so the ground footprint stays constant even if the DEM resolution changed. Only the top-left anchor is needed.

Parameters:
  • transform (affine.Affine) – Geotransform of the DEM being clipped on reuse.

  • bbox (sequence of float) – [xmin, ymin, xmax, ymax] in the DEM’s CRS.

Returns:

(row, col) top-left pixel offset (clamped to be non-negative).

Return type:

tuple of int

asp_plot.selections.pixel_window_to_bbox(transform, row, col, n_rows, n_cols)#

Convert a pixel window (top-left row/col + size) to a map-coordinate bbox.

Parameters:
  • transform (affine.Affine) – Raster geotransform (raster.ds.transform).

  • row (int) – Top-left pixel of the window.

  • col (int) – Top-left pixel of the window.

  • n_rows (int) – Window height/width in pixels.

  • n_cols (int) – Window height/width in pixels.

Returns:

[xmin, ymin, xmax, ymax] in the raster’s CRS.

Return type:

list of float

asp_plot.selections.read_selections_yaml(path)#

Read a FigureSelections from a YAML file.

Parameters:

path (str) – Path to a previously written selections file.

Return type:

FigureSelections

asp_plot.selections.reproject_bbox(bbox, src_crs, dst_crs)#

Reproject a map-coordinate bbox from one CRS to another.

Used when replaying detailed-hillshade clips against a DEM in a different CRS than the run that wrote them (e.g. a mapprojected vs. non-mapprojected stereo variant of the same scene, which can land in different projections). Returns the input unchanged when either CRS is missing or they are equal.

Parameters:
  • bbox (sequence of float) – [xmin, ymin, xmax, ymax] in src_crs.

  • src_crs (str or rasterio.crs.CRS or None) – CRS the bbox is currently expressed in.

  • dst_crs (str or rasterio.crs.CRS or None) – Target CRS (the DEM being clipped on reuse).

Returns:

[xmin, ymin, xmax, ymax] in dst_crs.

Return type:

list of float

asp_plot.selections.write_selections_yaml(path, selections)#

Write a FigureSelections to a YAML file.

Parameters:
  • path (str) – Destination path (e.g. <report_stem>_figure_selections.yml).

  • selections (FigureSelections) – Selections to serialize.

asp_plot.selections.HILLSHADE_CLIP_LABELS = ['low', 'medium', 'high']#
asp_plot.selections.SELECTIONS_SCHEMA_VERSION = 1#
asp_plot.selections.logger#