mostlyright.weather.catalog.cli
mostlyright.weather.catalog.cli
Section titled “mostlyright.weather.catalog.cli”NWS CLI settlement adapter (CATALOG-03).
Wraps mostlyright.weather._climate.parse_cli_record() (and
parse_cli_response) into a class that satisfies the WeatherAdapter
Protocol and emits a canonical schema.settlement.cli.v1 DataFrame.
R3 mitigation (PLAN.md Task 4.3): the adapter carries the
(station, observation_date) dedup logic lifted from
monorepo-v0.14.1/src/mostlyright/pairs.py — strict-> priority
between preliminary < final < correction with first-row-seen wins
at equal priority. Without this, multiple report-type rows for the same
local date would slip downstream and corrupt Kalshi NHIGH/NLOW settlement.
Classes
Section titled “Classes”CLIAdapter() | NWS CLI settlement adapter. |
|---|
class mostlyright.weather.catalog.cli.CLIAdapter
Section titled “class mostlyright.weather.catalog.cli.CLIAdapter”Bases: object
NWS CLI settlement adapter.
SUPPORTED_SOURCES : ClassVar[list[str]] = [‘cli.archive’, ‘cli.live’]
Section titled “SUPPORTED_SOURCES : ClassVar[list[str]] = [‘cli.archive’, ‘cli.live’]”fetch_observations(source, station, from_date, to_date)
Section titled “fetch_observations(source, station, from_date, to_date)”Phase 3 Mode-2 entry point. v0.1: NotImplementedError.
static from_records(records, , source=‘cli.archive’, station_tz=‘UTC’, retrieved_at=None)
Section titled “static from_records(records, , source=‘cli.archive’, station_tz=‘UTC’, retrieved_at=None)”Project parsed CLI records to a canonical settlement DataFrame.
Applies the v0.14.1 (station, observation_date) dedup:
strict-> priority by REPORT_TYPE_PRIORITY with first-row-seen
wins at equal priority. The adapter never silently merges across
stations.
- Parameters:
- records (
list[dict[str,object]]) – List of dicts as returned byparse_cli_record(). - source (
str) – Source ID fordf.attrs["source"]. - station_tz (
str) – IANA timezone name. Required forevent_time(00:00 local on observation_date → UTC). Default"UTC"is a sentinel — production code MUST pass the real zone. - retrieved_at (
datetime|None) – Wall-clock UTC of the pull. Defaults tonow().
- records (
- Return type:
DataFrame - Returns:
DataFrame conforming to
schema.settlement.cli.v1(12 columns) plus overlay columns (source,retrieved_at,knowledge_time,event_time).
mostlyright.weather.catalog.cli.parse_cli_record(record, station_code)
Section titled “mostlyright.weather.catalog.cli.parse_cli_record(record, station_code)”Parse a single IEM CLI record into a climate schema dict.
Returns dict with 9 fields (8 schema + report_type_priority), or None if both high and low are missing or observation_date is invalid.
observation_date: Uses IEM’s valid field directly. IEM CLI data reports by local calendar day (NWS convention). This is THE correct behavior: “March 31 high” means the station’s local March 31.
mostlyright.weather.catalog.cli.parse_cli_response(data, station_code)
Section titled “mostlyright.weather.catalog.cli.parse_cli_response(data, station_code)”Parse all CLI records, filter None (both temps missing).