Skip to content

Phase 1: STAC sampler — real COG fetch + map-style datasets - #1

Merged
TechnicToms merged 11 commits into
mainfrom
phase-1
Jul 9, 2026
Merged

Phase 1: STAC sampler — real COG fetch + map-style datasets#1
TechnicToms merged 11 commits into
mainfrom
phase-1

Conversation

@TechnicToms

Copy link
Copy Markdown
Owner

Phase 1: STAC sampler — real COG fetch + map-style datasets

Closes Phase 0 and implements the Phase 1 core: InstrumentDataset.read(bbox) now
fetches real Cloud Optimized GeoTIFFs from the USGS ARD STAC catalog, reprojects
them onto a common geographic grid, applies scale/offset, mosaics overlapping
items, and caches the result — no more synthetic tensors.

New body-agnostic data layer (src/astrofetch/data/)

  • endpoints.py — the single external URL (STAC API root); every COG href is discovered at request time.
  • errors.pyEndpointError, pointing back at data/endpoints.py.
  • grid.pyTargetGrid, the common IAU-2015 geographic raster all layers reproject onto.
  • raster.py — windowed COG reads via WarpedVRT (any source projection → target grid), scale/offset applied, boolean validity mask.
  • stac.py — polite pystac-client search with exponential backoff.
  • cache.py — disposable on-disk window cache, never load-bearing.

Moon datasets

  • Backed by real data. KaguyaTC now reads the kaguya_terrain_camera_usgs_dtms collection (dtm + orthoimage assets).
  • LROCWACKaguyaTCImagery. The USGS catalog has no LRO WAC collection, so the fictional class is replaced by real Kaguya TC stereoscopic radiance imagery. Adding LRO WAC from a non-STAC source is noted for a later phase.
  • Map-style & indexable. Switched from IterableDataset to a map-style Dataset: moondata[i] works and is reproducible, len() unchanged, and DataLoader(shuffle=True), samplers, and random_split now work. Also fixes a latent multi-worker duplication bug.

Docs & project

  • CONTRIBUTING.md + GitHub issue forms (bug / feature / new dataset).
  • README, AGENTS.md, and the docs site updated to the real API; Phase 0 marked done, Phase 1 current; type-check command switched to ty.
  • Project logo in the README header; icon as the docs logo/favicon.
  • Core deps added: rasterio, pystac-client.

Testing

  • 41 unit tests (network fully mocked; raster tests use local GeoTIFFs), all green.
  • 2 live tests (deselected by default) verifying catalog reachability and an end-to-end two-layer DTM+ortho patch fetch.
  • Local gate green: ruff, ruff format --check, ty check, pytest, mkdocs build --strict.

Notes

  • rasterio's WarpedVRT.read emits a NumPy 2.5 DeprecationWarning (upstream, harmless).

Files: 32 changed, +2166 / −145 (11 commits).

Introduce the body-agnostic data layer foundation for the Phase 1 STAC
sampler: EndpointError (pointing back at data/endpoints.py), the single
STAC API root, and TargetGrid — the common geographic raster every layer
is reprojected onto. Add rasterio and pystac-client as core dependencies.
read_window opens a Cloud Optimized GeoTIFF, reprojects the region covering
a TargetGrid onto it via WarpedVRT (any source projection to the geographic
target grid), applies band scale/offset for physical values, and returns a
boolean validity mask for nodata and out-of-coverage pixels.
find_asset_hrefs queries the USGS ARD catalog by collection and bbox through
a memoized pystac-client with exponential backoff on rate-limit and transient
errors, returning one asset href per intersecting item. Failures surface as
EndpointError.
WindowCache stores reprojected (image, mask) arrays under a hash of the layer
id and target grid, writing atomically via a temp file and replace. Entries
are re-fetchable and safe to delete; the cache is never load-bearing.
InstrumentDataset.read now samples a real ground window, searches the USGS ARD
catalog for the covering COGs, reprojects and mosaics them onto a common
geographic grid, and caches the result — replacing the Phase 0 synthetic
tensors. KaguyaTC is backed by the kaguya_terrain_camera_usgs_dtms collection
(dtm + orthoimage assets); LROCWAC (no STAC collection exists) is replaced by
KaguyaTCImagery over the stereoscopic radiance observations. The catalog,
registry, and exports follow.

Note: LRO WAC has no STAC backing in this catalog; a later phase can add it
from a non-STAC (COG/WMS) source.
Update AGENTS.md, README, and the docs site to the real per-instrument API
(KaguyaTC + KaguyaTCImagery), mark Phase 0 done and Phase 1 current, switch the
type-check command to ty, and note the deferred non-STAC LRO WAC source for a
later phase. Replace the live-test placeholder with a real USGS ARD catalog
reachability check and an end-to-end two-layer patch fetch.
Add a contributor guide grounded in the real uv/ruff/ty workflow and the
unit-vs-live test policy, plus GitHub issue forms for bug reports, feature
requests, and new dataset/body proposals (with a config pointing at
Discussions and the guide).
Switch from IterableDataset to a map-style Dataset: each index deterministically
samples one window, so moondata[i] works and is reproducible, len() is unchanged,
and DataLoader shuffling, samplers, and random_split now work. This also fixes a
latent bug where multi-worker DataLoader duplicated patches across workers.
Document that patch_size sets the (C, patch_size, patch_size) output size.
@TechnicToms TechnicToms added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 9, 2026
@TechnicToms
TechnicToms merged commit 2fae509 into main Jul 9, 2026
7 checks passed
@TechnicToms
TechnicToms deleted the phase-1 branch July 9, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant