Repository navigation
refactor(edr): refactor EDR config dicts and provider (BDMS-1602) - #1060
jacob-a-brown wants to merge 42 commits into
Conversation
…DMS-1542-feat-ocotillo-implement-test-for-die-timeseries-summary-water-levels
The PointSeriesEDRProvider will eventually be used for other data types, like air temp from meteorological stations or heat flow measurements in bore holes.
PointSeries is for time series only. This EDR provider should be usable for vertical profiles, too, so chose a generic name
Coverage✅ 82.25% total — gate is 75%. Coverage for the Python files changed in this PR
|
There was a problem hiding this comment.
🟡 Changes recommended
Critical location-query regressions break manual-waterlevels and existing chemistry endpoints, while CoverageJSON types copied into JSON Schema make the published schema invalid.
8 open issues
Use JSON Schema number while retaining CoverageJSON float · New Include configured station properties in the locations query · New Map chemistry station_name to name in the locations provider · New Add lexicon categories for groundwater level reason · New Restore manual-waterlevels parameter descriptions · New Keep the shared well fixture empty for the null-case test · New Filter well readings by thing_id, not reading id · New Use mapping results for SQLAlchemy rows in the test · New
What changed in this PR
Refactors OcotilloAPI’s environmental data retrieval (EDR) provider to support multiple parameters per row and configurable station metadata, while preparing for independent axes beyond time.
Changes:
- Renames the provider to
StationEDRProviderand adds configurable parameter groups, station properties, and axis settings. - Replaces the combined water-level collection configuration with
manual_waterlevels, including measurement qualifiers. - Expands provider, metadata, view-parity, and integration tests; some depend on the planned stacked view migration.
| File | Description |
|---|---|
tests/test_ogc.py |
Moves the water-level publication regression test out of the general suite. |
tests/test_ogc_manual_waterlevels.py |
Adds manual-waterlevel response, publication, and view-contract tests. |
tests/test_ogc_field_metadata.py |
Changes numeric metadata test inputs to float. |
tests/test_ogc_field_descriptions.py |
Updates EDR metadata tests for multiple parameters and configurable axes. |
tests/test_migration_view_parity.py |
Checks deployed public/internal views and configured EDR relations. |
tests/test_edr_provider.py |
Adds parameter selection, null alignment, and configuration propagation tests. |
tests/features/steps/edr_water_data.py |
Updates behavior-test steps for manual water levels. |
tests/features/edr-water-data.feature |
Revises scenarios for manual measurements and qualifiers. |
tests/conftest.py |
Adds formation metadata and a database-free provider fixture. |
core/pygeoapi.py |
Defines and forwards the expanded EDR collection configuration. |
core/ogc-field-descriptions.yml |
Removes the former water-level parameter documentation. |
core/gis-curated-layers.yml |
Updates a comment to use the new collection name. |
core/edr_provider.py |
Implements configurable parameter discovery, filtering, and coverage generation. |
Review effort: Balanced
| # EDR collection parameters are discoverable from the data, so they are not hardcoded | ||
| # here. |
There was a problem hiding this comment.
This is yet another thing that was discovered and addressed while working on the backing view. The schema now builds the descriptions from the parameter itself. There are no verbose explanations, but because we want to "discover" parameters from the data (particularly for water chemistry) we can't have a fixed list. @jirhiker are you okay with this approach? If not we'll have to hardcode all parameters and their descriptions, which means that discovery can't occur from the data itself.
There was a problem hiding this comment.
Let's use this YAML file rather than the lexicon (I answered the same question on #1062). Discovering parameters from the data still works. _parameter_documentation already looks each discovered name up in ogc-field-descriptions.yml, and it only falls back to the raw name when there's no entry. So a fixed list isn't required: documented parameters get proper labels, and undocumented ones still show up under their names.
A lexicon lookup wouldn't help much either. The published names (e.g. groundwater level below ground surface) aren't lexicon terms.
For manual_waterlevels, please add entries for groundwater level below ground surface and groundwater level reason, using the wording from docs/ogc-waterlevels-data-contract.md. For chemistry, add analytes as they get documented, and the fallback covers the rest.
Generated by Claude Code
There was a problem hiding this comment.
The stacking plan makes sense. The failing ogc_manual_waterlevels tests are expected until the view PR lands, and keeping them as the spec is reasonable. Since this PR targets staging, I'd mark it draft or add a do-not-merge label until the view PR has merged into this branch. If it merges early, /collections/waterlevels disappears and the new collection fails on every query.
Separate from the view, the inline comments cover issues that this PR has to fix itself. The main one is the /locations KeyError on core/edr_provider.py L300. The view PR won't fix it, and it'll probably surface as a failure in test_ogc_manual_waterlevel_feature_collection_shape once the view exists.
Generated by Claude Code
| "values": [None] * len(independent_axis_raw_values), | ||
| } | ||
|
|
||
| ranges[name]["values"][i] = r[parameter_column_set["value_column"]] |
There was a problem hiding this comment.
If two rows for a station share the same axis value (for example, two manual measurements recorded at the same datetime), the later row overwrites the earlier one here and the first reading disappears from the coverage without a warning. The old provider did this too, so it isn't a regression, but it now applies to every parameter set. Even a LOGGER.warning on collision would help.
Generated by Claude Code
There was a problem hiding this comment.
I added a LOGGER.warning on collision and am keeping the existing value.
There was a problem hiding this comment.
Do you think that the second value should be kept? Or both of them? If both I'll figure out a way to do that.
There was a problem hiding this comment.
Keeping both isn't an option. A CoverageJSON axis can't repeat a value, so two readings at the same datetime can't both go in one range. Keep one, but there's a bug in how the current check picks it.
The check runs separately for each parameter column and only fires when the existing value is non-null. Take two readings for the same well and datetime:
| row | observation_value | qualifier_value |
|---|---|---|
| A | NULL | Site was unsafe to measure |
| B | 50 | Water level not affected |
observation_value for A is None, so B's 50 replaces it with no warning. qualifier_value for A is non-null, so A's reason stays. The coverage then publishes 50 with "Site was unsafe to measure", a value and reason that came from different readings.
Which row arrives first is also random. _fetch_rows sorts by thing_id, <axis> only, so tied rows come back in whatever order Postgres picks.
Suggested fix:
- Add a tiebreaker to the ORDER BY:
ORDER BY thing_id, {axis}, id. - Decide keep-or-skip once per row, before the
parameter_columnsloop. Keep aseenset of axis indexes. Ifihas already been filled, log once and skip the whole row. A row's value and its qualifier then always stay together, and the lowestidwins every time.
Generated by Claude Code
There was a problem hiding this comment.
Good catch - making this update now
jirhiker
left a comment
There was a problem hiding this comment.
This is a second pass over the test files, which the first pass only skimmed. It leaves out anything already raised by Copilot or the first pass. The one real bug is the BDD Background assert that only runs when the catalog returns 200. The rest are test contradictions and nits.
One more item from the first pass is worth repeating: Copilot's station_name comment on core/pygeoapi.py L343 is as serious as the /locations KeyError. water_chemistry/locations breaks in this PR, and the view PR won't fix it.
Generated by Claude Code
…ond at that value
|
Two items from resolved threads are still open on both this branch and #1062:
Either can go in #1062 if that's easier, since that's merging into this branch. Generated by Claude Code |
|
|
@jirhiker I just pushed an update for the ADR and it's ready for review/comments |
Use underscores for parameter names and define them in ogc-field-descriptions.yml. Enable a fallback to the parameter name if not defined in ogc-field-descriptions.yml.
|
Parameters are now hard-coded and described in core/ogc-field-descriptions.yml. If a parameter does not exist there the EDR provider defaults to the parameter name for the description and title. It then logs that this occurs at a warning level. |
|
I ran into two issues during testing and validation that prevented this from being implemented correctly:
The fixes, as seen in the last 2 commits (drop unloadable EDR collections & enforce only one unit per parameter), address these issues as follows:
Neither of these problems are issues with water level data since they get normalized in the backing view. They are, however, problems with water chemistry data (the broken water chemistry collection was, for example, preventing the manual waterlevels collection from publishing in the OpenAPI documentation). My recommendation for when we create the water chemistry backing view is as follows: normalize it! Make sure that every parameter has one and only one unit. This means that we may need to get together with AMMP colleagues to determine which units we want reported (in some cases), and what to do about Thoughts/opinions? (See screenshot for the dropped parameters and the logged warnings)
|



Why
This PR addresses the following problem / context:
How
Implementation summary: the following was changed / added / removed:
core/pygeoapi.py
parameter_columns: describes the sets of columns for parameter names, units, and values. This enables the provider to have multiple parameters per rowstation_properties: the properties of a station (e.g. site) that go into thepropertiesfor each feature in the feature class (queried at/locations)independent_axis: the name of the independent axis (e.g.torz) and the column of the view where those values residecore/edr_provider.py
/locationsand the CoverageCollection from all other endpoints in the collection (e.g./area,/cube,/locations/{locId})parameter_columnsto get relevant data.ithen its value isNoneat that index. IMPORTANT: for water level data there is only one observed parameter and a qualifier. Each exists in the same row. This means that there will always be the same number of observations and qualifiers, even if one of them isNonein the database. When making the water chemistry EDR the provider will need to be updated to set the associated qualifier to an appropriate message (such as "Parameter not analyzed for at this datetime. Value is set to None." Message TBD. Doing this is out of scope for this work and will be implemented when working on water chemistry EDR.)StationEDRProvidersince this will eventually be used for vertical data. We can, if we want, have the following setup instead:BaseStationEDRProviderthat defines common methods and then aPointSeriesEDRProviderfor time series data andVerticalProfileEDRProviderfor vertical data. Thoughts? See CoverageJSON docs for the different domain types.Author Checklist
Reviewer Checklist
Notes
Any special considerations, known limitations, risks, workarounds, or follow-up work to note?
ogc_manual_waterlevelsview. The original intention was to have all of this work in one PR, but after yesterday's meeting the EDR refactor and the view construction were split up into separate tickets. There are, therefore, some tests that fail. I don't want to get rid of them, though, because I think that they are important and do a good job describing what needs to occur. My intention is to open a stacked PR. In the next PR these tests, and others, will all pass. That means that that PR will need to get merged here first for all tests to pass. Then all of the work can get merged into staging.