Skip to content

Add gallery plotting for many DEM outputs (#11)#120

Merged
bpurinton merged 6 commits into
mainfrom
gallery-plotter
Jun 9, 2026
Merged

Add gallery plotting for many DEM outputs (#11)#120
bpurinton merged 6 commits into
mainfrom
gallery-plotter

Conversation

@bpurinton

@bpurinton bpurinton commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Closes #11. Brings the legacy original_code/gallery.py into the modular package as a robust, reusable class + CLI for visualizing a stack of DEMs.

What's new

asp_plot/gallery.pyGalleryPlotter(Plotter)

  • Lays out many DEMs as a grid of thumbnails sharing one global percentile color stretch and a single colorbar, for QA'ing multi-date / multi-pair ASP output at a glance.
  • Reuses Raster (downsampled reads), ColorBar.find_common_clim, and save_figure; drops the removed pygeotools / imview deps.
  • Renders DEMs with the existing package convention: gray hillshade underlay + semi-transparent viridis DEM (matches stereo.py _plot_dem_with_hillshade), "Elevation (m HAE)" colorbar. Hillshade underlay on by default, toggleable.
  • from_directory(directory, pattern="*-DEM.tif") resolves a directory + glob into the raster list, with recursive ** support for DEMs nested in subdirectories (the common ASP per-pair layout). Also accepts an explicit file list.

gallery CLI (asp_plot/cli/gallery.py) — --directory + --pattern (or explicit FILES), --hillshade/--no-hillshade, --cmap, --downsample, --max_filesize_mb, --title, --output_directory/--output_filename. Registered as a gallery entry point; saves into the working directory by default.

Layout & quality decisions

  • Aspect-matched, absolutely-positioned panels so galleries of 1 to N rasters (incl. non-square) pack tightly with no internal or trailing-cell whitespace.
  • Titles use the full filename, auto-shrunk to fit the panel by measuring rendered text width (a character-count estimate undersized these wide digit/uppercase-heavy names and overflowed into neighbors).
  • Detail preserved, file size bounded: source detail read at ~1200 px/panel and save dpi matched to it for crisp zoom, then dpi capped to a pixel budget so the PNG stays under --max_filesize_mb (default 10) regardless of raster count.

Tests

  • tests/test_gallery.py: grid math, title-fit, shared clim, recursive globbing, end-to-end plotting (with/without hillshade), save-to-disk, and a CLI smoke test — reusing the tiny synthetic DEMs already in tests/test_data/ (no new fixtures).
  • GalleryPlotter / asp_plot.gallery added to tests/test_imports.py. Full suite passes (network-only altimetry tests deselected locally).

Docs & release prep

  • New docs/cli/gallery.md (usage incl. subdirectories, full --help, Python API) + a rendered example figure stored in a new committed docs/figures/ dir (regenerated at ~2 MB to keep the repo lean). Listed in the CLI index.
  • CHANGELOG entry and version bump 1.14.1 → 1.15.0 (minor; new feature). Release auto-publishes on merge to main per the existing workflow.

Not in this PR (possible follow-ups)

  • Wiring the gallery into the main asp_plot PDF report.
  • An example notebook.

Verified end-to-end on a 7-DEM WorldView stack and 1/2/4-raster layouts.

bpurinton added 6 commits June 9, 2026 12:04
Bring the legacy original_code/gallery.py into the modular package as a
reusable GalleryPlotter(Plotter) class plus a gallery CLI command.

- Plots a grid of DEM thumbnails sharing a single global percentile color
  stretch and one shared colorbar.
- Reuses Raster (downsampled reads), ColorBar.find_common_clim, and
  save_figure; drops the pygeotools/imview dependencies.
- Renders DEMs with the existing convention: gray hillshade underlay +
  semi-transparent viridis DEM (matches stereo.py _plot_dem_with_hillshade).
- Auto grid layout (ported aspect-ratio formula) and auto downsampling.
- Adds tests/test_gallery.py (grid math, shared clim, plotting with/without
  hillshade, save-to-disk, CLI smoke test) and import-test coverage.
…size cap

Addresses review feedback on the gallery output:

- Titles: shrink the per-panel font so the full filename fits within the
  panel width (no more oversized, overlapping titles).
- Whitespace: size each panel box to the rasters' median aspect ratio and
  place panels with absolute positioning, so 1..N rasters (incl. non-square)
  pack tightly with no internal or trailing-cell whitespace.
- Resolution/filesize: read more source detail (GALLERY_TARGET_PX 800->1200)
  and match save dpi to the rendered detail for crisp zoom, then cap dpi to a
  pixel budget so the PNG stays under max_filesize_mb (default 10) regardless
  of raster count. New --max_filesize_mb CLI option.

Verified on the 7-DEM WorldView stack (8.3 MB) and 1/2/4-raster layouts.
The character-count font estimate undersized wide, digit/uppercase-heavy
filenames, so titles still overflowed into neighboring panels. Measure the
real text extent with an Agg renderer and scale the font by the width ratio,
guaranteeing the full filename fits the panel width (shrinks when cramped,
fills when roomy). Falls back to the heuristic estimate if measurement fails.
- Add docs/cli/gallery.md documenting the gallery CLI and GalleryPlotter API
- List gallery in the CLI index (four -> five tools, card + toctree)
- CHANGELOG entry for 1.15.0
- Bump version 1.14.1 -> 1.15.0 in pyproject.toml
from_directory now globs with recursive=True so '**' descends into
subdirectories (e.g. '**/*-DEM.tif'), matching the common ASP layout where
each pair lives in its own subdirectory. Previously the shared glob_file
helper was non-recursive, so '**' collapsed to a single level and only
explicit-depth patterns like '*/*-DEM.tif' worked.

- Recursive glob in GalleryPlotter.from_directory (no change to glob_file)
- Updated --pattern help and docs with subdirectory examples
- Added test_from_directory_recursive
Embed a rendered 7-DEM WorldView gallery as a figure on the gallery CLI
doc page. Store committed doc figures in a new docs/figures/ directory
(docs/_static is Sphinx's static-asset dir and only holds the gitignored
report copies). Figure regenerated at --max_filesize_mb 2 (~2 MB) to keep
the repo lean while staying legible.
@bpurinton bpurinton merged commit 8a7abd3 into main Jun 9, 2026
1 check passed
@bpurinton bpurinton deleted the gallery-plotter branch June 9, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add gallery plotting ability for many outputs

1 participant