Repository navigation
feat(ogc): divide a closed time interval under parallel_chunks - #469
Open
thodson-usgs wants to merge 12 commits into
Open
thodson-usgs wants to merge 12 commits into
thodson-usgs wants to merge 12 commits into
Conversation
thodson-usgs
marked this pull request as ready for review
November 17, 2026 16:39
parallel_chunks(n) could divide only a multi-value argument, so one location's long continuous record went as one chunk whose cursor pages ran in sequence. On windows the service had not cached, a year of 15-minute discharge (about 100,000 rows) ran at 6,000 to 7,800 rows/s. The planner now has a time axis for a closed `time` (Water Data) or `datetime` (NGWMN) interval. Its atoms are UTC days; after the multi-value axes take their splits, the interval is divided into equal runs of days by the largest whole factor of n that is left. Outside a parallel_chunks block the axis is not built, so requests are unchanged. Consecutive chunks share their boundary midnight. Water Data includes both ends of an interval and NGWMN excludes the start (probed: a window starting at an observation's instant omits it), so ending each chunk 1 us before the next start dropped NGWMN's boundary observations (3 of 8,475 rows over 25 years). With a shared boundary the result is complete under either rule, and combining drops the repeated feature id. Live, against the unsplit call on the same window: Water Data continuous 96,491 = 96,491 rows (year) and 2,161 = 2,161 (window ending at noon); daily 12,784 = 12,784 with no repeated day; NGWMN 8,475 = 8,475. Cold timing, 3 sites each: parallel_chunks(12) 29,000 to 41,000 rows/s against 6,000 to 7,800 unsplit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The time axis joined ChunkPlan.axes before _plan and _refine, so both passes, _Axis._text and render each tested is_interval to skip or special-case it. It now joins after _refine, built directly as its final runs: one start/end interval per chunk, which the existing render and chunk_bytes send unchanged. _extract_axes, both passes and _Axis are back to their main form. Building only the runs' boundaries, not one string per UTC day, cuts planning a 125-year interval at parallel_chunks(32) from about 30 ms to 1.7 ms, and a "0001-01-01/9999-12-31" sentinel range from 2.3 s and 586 MB peak to 1.6 ms. Boundaries are written by dates._format_one and read by _to_datetime and _is_blank instead of string slicing. Tests: the date-only case uses WATERDATA_DIALECT rather than a copy of its date-only set; two redundant tests are dropped and the byte-split case joins the factor table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- An interval one day long or shorter is not divided. The rule counted the UTC days an interval touches, so a two-hour window across midnight (23:00Z/01:00Z) was sent as two requests. - The canonical_url fallback, used when the whole request cannot be built, runs before the time axis is added, so md.url keeps the caller's interval rather than one run's. - NEWS and the parallel_chunks docstring: the axis is built whenever the effective setting is above 1, including a configure() baseline or a configuration file, not only inside a with-block. The "n is capped by how many values there are" sentences now count UTC days of a time interval too. - README: the new lines say "chunk", the core term, not "sub-request". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The time axis divided every collection's interval into n equal runs, so under parallel_chunks(12) a year of daily values went out as 12 requests of about 30 rows, and a century of peaks as 12 requests of about 8. The dialect now maps each collection whose interval divides to its shortest time chunk: 30 days for continuous values and 10 years for daily values, about 3,000 records of a time series either way. Other collections, and NGWMN, are not divided. The run count is the cap's leftover factor, up to how many shortest chunks the interval's duration holds, which also replaces the separate one-day check. Measured cold on Water Data v1 (each run on its own never-queried site, medians of 4): - one year of continuous discharge: 30-day chunks 1.00 s (12 requests), 14-day 0.96 s (26), 7-day 1.16 s (52), unsplit 4.07 s. - 35 years of daily discharge: unsplit 1.77 s, 9-year chunks 0.89 s, 5-year 0.77 s, 3-year 0.69 s; the new 3-chunk plan 1.10 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Keep OgcDialect hashable: time_chunk_days is a dict, so it is left out of the hash. - The parallel_chunks docstring names OgcDialect.time_chunk_days as the source of the chunk lengths; the records-per-chunk reasoning stays beside the Water Data setting. - The planner comment says datetime, like time, is split only for a collection the dialect lists; NGWMN lists none. - CONTEXT.md's Dialect entry names the shortest time chunk. - Tests: a _day_plan helper replaces ten time_chunk_days=1 arguments, a _run_days helper replaces two copies of the run-length calculation, and the request-count test uses _items_requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The planner held the time axis: it parsed the interval, cut it at UTC midnights, and named the `time` and `datetime` arguments. It now divides any `RangeAxis`, an object with an `arg_key` and `divide(most)`, which it gets from a `read_range(args)` reader called only when `max_chunks` is above 1. The planner reads only the pieces. - `ogc/dates.py` holds the interval axis (`_IntervalAxis`, `_interval_axis`), moved without a change in logic. - The dialect names the argument: `time_param`, default `datetime`, the OGC API Features name. Water Data sets `time`. - The engine binds the reader from the dialect with `functools.partial`. `multi_value_chunked` and `ChunkPlan` take `read_range` in place of `time_chunk_days`. Plans are unchanged. A grid of 18,480 requests (Water Data and NGWMN dialects, list and filter axes, closed, open, and offset intervals, caps 1 to 32) gives identical chunks and canonical URLs before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The planner divides axes without knowing what they measure; a range axis owns what its range measures and where it may be cut. A fitness function now fails if `ogc/planning.py` imports a date module, pandas, or `ogc.dates`, and its message names the fix. CONTEXT.md defines *axis* as a core term (list, filter, and range axes), and the *Dialect* entry names the argument holding the time interval. The *Source* entry used "axis" for the configuration scope; it now says "names something else" so the core term keeps one meaning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `ChunkPlan` plans the multi-value axes with main's code unchanged (now `_plan_axes`), then `_divide_range` divides the range. `_plan` loses its range-only branch, and the reader is called only when the cap leaves room for two pieces. - `RangeAxis.divide` returns two to `most` pieces; a reader returns an axis only for a range that divides in two, so neither side checks for fewer. - The engine binds no reader for a collection its dialect does not list, so `_interval_axis` takes an `int` `chunk_days`. - `_IntervalAxis` stores its bounds as datetimes and computes the first midnight and day count in `divide`. - `.importlinter` forbids `ogc.planning -> ogc.dates`; the fitness function keeps the standard-library and pandas imports it cannot see. - Planner tests drop rows that repeated the dialect's 3,650-day value. Plans are unchanged on the 18,480-request grid, and a live A/B of nine Water Data requests and one NGWMN request matches the previous run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thodson-usgs
force-pushed
the
feat/time-axis-chunks
branch
from
November 23, 2026 14:05
8cc5470 to
4816a67
Compare
NEWS.md: kept both entries; main's 11/21 ratings fix goes on top of this PR's 11/17 entry (newest first). No code conflicts.
Planner: `_plan_axes` reads `self.args` as `_divide_range` does, instead of taking the same dict as a parameter. The canonical-URL fallback in `_divide_range` uses the `suppress(httpx.InvalidURL)` form of the one in `_plan_axes`. Its docstring gives the byte-budget reason `RangeAxis` gives. `_interval_axis` drops a `None` guard that `_format_api_dates` already covers. Docs: the `parallel_chunks` docstring is shared OGC code, so it no longer repeats the Water Data day counts, the private `OgcDialect.time_chunk_days` pointer, or the NGWMN exclusion. The settings table in `configuration.rst` uses the package-wide wording. README and NEWS say 3,650 days, which is what the dialect sets. The CONTEXT.md Axis entry and the architecture test docstring no longer restate the `.importlinter` contract. Test: `ChunkPlan` divides a range that is not a time interval, which checks that the planner reads only a range axis's pieces. It also covers the canonical URL of a plan whose only axis is the range. No behavior change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`_IntervalAxis.divide` counted its cuts from the midnight before the interval's start, and `_interval_axis` counted runs from the raw duration. A start or end off a UTC midnight therefore made the first or last run shorter than the collection's shortest time chunk: under `parallel_chunks(12)`, `time="2023-01-01T00:00:00-05:00/2023-12-31T00:00:00-05:00"` gave a first continuous chunk of 29 days 19 hours. Both now count the whole UTC days between the first midnight at or after the start and the last midnight at or before the end, and the first and last runs take the partial days. Intervals that start and end at midnight divide as before (302,760 cases compared against the previous code, none different). Also: the `_format_api_dates` parameter docstring said a naive value is read in the local time zone; it is UTC, as its Notes say. The NEWS entry moves to the top, dated today; update the date if it lands later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parallel_chunks(n)now divides the closedtimeinterval of Water Data continuous and daily values, not only a multi-value argument. One location's long record used to be a single chunk whose cursor pages ran in sequence.get_ogc_data multi_value_chunked(..., time_chunk_days=dialect.time_chunk_days.get(collection)) ChunkPlan(args, build_request, url_limit, max_chunks=n, time_chunk_days=d) _extract_axes(args) # unchanged + _time_interval(args, d) if n > 1 # closed interval holding >= 2 chunks of d days _plan(...) # unchanged _refine(n) # unchanged + _add_time_axis(interval, n) + count = min(duration // d, n // total) # the whole factor of n the other axes leave + append an axis of `count` equal runs of whole days, one interval per chunkThe shortest time chunk is set per collection in the Water Data dialect, so each chunk holds about 3,000 records of a time series:
continuousdailyThe time axis joins the plan after both passes, so the byte pass and the count pass do not change. Only the run boundaries are built; nothing is built per day.
_combine_chunk_framesdrops the repeated featureid. Water Data includes both ends of an interval; NGWMN excludes the start. A shared boundary gives a complete result under either rule, so NGWMN can be added to its dialect later without changing the planner."P7D"), an open interval, or an interval shorter than two chunks.parallel_chunkssetting of 1 the axis is not built, so requests are unchanged. A setting above 1 builds it, whether it comes from a block, aconfigure()baseline, or a configuration file.Evidence
All timings are live against Water Data v1 with a PAT. Every run used its own never-queried site, so the service's data-window cache was cold.
Continuous: one year of 15-minute discharge, by chunk length (about 34,000 rows; medians of 4 sites):
Chunks shorter than 30 days cost more requests for no gain, so 30 days is the shortest continuous chunk. An earlier run of the 12-chunk plan on 3 sites (35k to 105k rows) reached 29,128 to 41,359 rows/s, against 5,997 to 7,829 for the default and 6,885 to 23,800 for water-ogcapi 0.2.0 with
split_datetime="month".Daily: 35 years of daily discharge, by chunk length (about 12,800 rows; medians of 4 sites):
nof 12 or more)A year of daily values is under two 10-year chunks, so it is sent as one request, as before.
Same rows as the unsplit call, live, on the same window:
The daily and NGWMN rows were measured before this PR set a shortest chunk per collection; they check the run boundaries, which have not changed.
Why the boundaries are shared.
datetimeas(start, end]. For example,2006-04-01T00:00:00Z/2006-04-02T00:00:00Zreturns only the 04-02 observation.Tests.
waterdata_chunking_test.py, plus 5 adapter tests inwaterdata_test.py. The adapter tests assert the senttimevalues throughget_continuous, that repeated features appear once, and how many requests continuous, daily and field-measurement calls send underparallel_chunks(12).planning.pyfully covered. Also clean: ruff, mypy 2.4.1, xenon, complexipy, import-linter, and pre-commit.Merge Danger
Door: two-way
One private axis added at the end of planning in
ogc/planning.py, one dialect field, plus docs. Reverting the commits restores the old plans.Blast Radius: opt-in
parallel_chunkssetting is above 1 change (a block, aconfigure()baseline, or a configuration file). A call whose multi-value arguments could already reachnchunks sends the same requests as before.nnow divides its interval too, so it spends more quota. For example,get_continuous()for two locations withtime="2023-01-01/2023-12-31"underparallel_chunks(12)sent 2 requests and now sends 12. NEWS flags this.idde-duplication at boundary instants, the same mechanism that list and filter chunks already rely on.Not in this PR:
NGWMN_DIALECT.time_chunk_dayswould enable them.parallel_chunks, but that spends about 12 requests per series instead of 1 to 3, againstparallel_chunks' documented "never the default" rule.time="2023-01-01/2023-12-31"stops at2023-12-31T00:00Z, so sub-daily queries omit the last day. This is unchanged here.🤖 Generated with Claude Code