Skip to content

Guides

Ingest strategies

obs(station, from, to, opts) is the ingest-planner surface. It picks how to pull observations: a one-off date-bounded fetch, a year-aligned warm cache, or (future) a hosted precompute endpoint (not yet available). The default strategy: “auto” picks the right one for your window.

StrategyWhen to useCache behavior
exact_windowOne-off ≤7-day window. Cheapest path for a single call.None — fetches exactly the requested bytes.
warm_cacheYear-aligned. Reusable across calls with overlapping windows.Writes year-padded parquet; subsequent calls in the same year are local-only.
hostedv0.2.x — precomputed-API for fleet-scale ingest. Not yet wired.(Future)
auto (default)Picks exact_window ≤7 days; warm_cache otherwise.Per the picked strategy.
window = (to_date - from_date)
if window ≤ 7 days: strategy = exact_window
else: strategy = warm_cache

The 7-day cut roughly matches AWC’s 168-hour live window — anything inside there can be answered cheaply by a single fetch; anything wider benefits from year-aligned caching.

source=<one> always forces exact_window regardless of window size — single-source queries can’t honor the multi-source merge that warm_cache enables.

from mostlyright.weather import obs
# Auto-router — 7-day window picks exact_window
rows = obs("KNYC", "2025-01-06", "2025-01-12")
# Explicit — pull a year-padded warm cache for repeated backtest queries
rows = obs("KNYC", "2024-01-01", "2024-12-31", strategy="warm_cache")
# Single source — auto-picks exact_window
rows = obs("KNYC", "2025-01-06", "2025-01-12", source="iem")
  • Cheapest for one-off queries. ≤2 MB of HTTP per call for a week of one station.
  • No cache write. Subsequent identical calls re-fetch.
  • Honors source=. Single-source pinning; the fetcher emits only that source’s rows.
  • No year-padding. A 2025-01-06 to 2025-01-12 call pulls exactly that range.
  • Year-aligned. A call for 2025-01-06 to 2025-01-12 pulls Jan-2025 + (if needed) Feb-2025, padded to month boundaries, written to parquet.
  • Multi-source merge. Pulls AWC + IEM + GHCNh; merges per OBSERVATION_SOURCE_PRIORITY.
  • Subsequent calls are local-only for any window inside an already-cached year.
  • Backtest path — this is what research() uses internally.

Reserved for a future hosted precompute API. Calls raise DataAvailabilityError(reason="model_unavailable") today; the signature stays stable so caller code keeps working when v0.2.x ships.

Caller writesStrategy picked
obs("KNYC", from, to) (no source)auto-router (size)
obs("KNYC", from, to, source="iem")exact_window
obs("KNYC", from, to, source="awc")exact_window
obs(..., strategy="warm_cache")forced warm_cache
obs(..., strategy="warm_cache", source=…)ValueError — incompatible

The single-source + multi-source-merge combination is a category error; the router catches it at the call site rather than letting it produce wrong rows.

obs() is for raw observation rows. If you want joined observation + climate + (optional) forecast rows keyed by settlement date, use research(). research() calls obs() internally under the hood.