Skip to content

Derive grid extent and resolution from the store on fetch (#30)#67

Merged
aivanchenk merged 1 commit into
mainfrom
feat/derive-gridspec-from-store
Jul 25, 2026
Merged

Derive grid extent and resolution from the store on fetch (#30)#67
aivanchenk merged 1 commit into
mainfrom
feat/derive-gridspec-from-store

Conversation

@aivanchenk

Copy link
Copy Markdown
Collaborator

Closes #30.

What

Spatial extent, resolution, dimension sizes, and native chunk footprint are no longer hardcoded in src/lib/constants/store.ts. They are now derived from the remote Zarr store's metadata at runtime, so the app adapts to whatever store it opens. The previous constants stay as a fallback (DEFAULT_GRID_SPEC) for first paint and error states, so behavior is unchanged when derivation has not resolved yet or fails.

How

  • src/lib/zarr/gridSpec.ts (new): deriveGridSpec(store, variable) reads the data variable's shape, chunks, and _ARRAY_DIMENSIONS, then opens the lon/lat coordinate arrays to compute start and step (resolution). Returns DEFAULT_GRID_SPEC on any failure.
  • src/types/map.ts: new GridSpec type (grid, dimensions, nativeChunks, spatialResolutionDeg).
  • src/lib/constants/store.ts: DEFAULT_GRID_SPEC exported from the existing constants as the fallback.
  • src/lib/zarr/ZarrChunkReader.ts: memoized getGridSpec() delegating to deriveGridSpec.
  • src/lib/map/geogrid.ts: geometry helpers take a GridSpec param defaulting to the fallback, instead of reading the global constant.
  • src/components/map/EarthMap.tsx: holds gridSpec in state, fetches it once on mount via the shared reader, and threads it into handlePick, MapReadout, and GlobeSelectionOverlay.
  • src/components/map/{GlobeSelectionOverlay,MapReadout}.tsx: accept and use the gridSpec prop.

Verification

  • npx next build: compiled, TypeScript passed.
  • npx vitest run: 47 tests pass across 10 files (2 new in gridSpec.test.ts covering derivation and fallback).
  • Fallback confirmed: a derivation failure keeps DEFAULT_GRID_SPEC, so first paint and offline states behave exactly as before.

Spatial extent, resolution, dimension sizes, and native chunk footprint
are no longer hardcoded. They are read from the remote Zarr store's
metadata at runtime, with the previous constants kept as a fallback for
first paint and error states.

- Add GridSpec type and deriveGridSpec() that reads shape, chunks and
  lon/lat coordinate arrays from the store
- Memoize derivation on ZarrChunkReader via getGridSpec()
- Thread GridSpec through geogrid helpers and map components, defaulting
  to DEFAULT_GRID_SPEC
- Add unit tests covering derivation and the fallback path
@aivanchenk
aivanchenk requested a review from lazarusA July 25, 2026 09:19
@github-actions

Copy link
Copy Markdown

🚀 Vercel preview deployed

Preview URL: https://earth-prints-a9b5nj1ii-anastasiia-s-projects10.vercel.app

@lazarusA lazarusA left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since for now we only have one dataset to test, let's go with this, others will have other conventions, but we cannot do all at once.

@aivanchenk
aivanchenk merged commit 645e7ec into main Jul 25, 2026
2 checks passed
@aivanchenk
aivanchenk deleted the feat/derive-gridspec-from-store branch July 25, 2026 17:46
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.

get global extent and resolution on fetch

2 participants