Skip to content

Comments

ENH: move station coords to root and add optional_groups parameter#333

Open
aladinor wants to merge 6 commits intoopenradar:mainfrom
aladinor:worktree-issue-331-station-coords
Open

ENH: move station coords to root and add optional_groups parameter#333
aladinor wants to merge 6 commits intoopenradar:mainfrom
aladinor:worktree-issue-331-station-coords

Conversation

@aladinor
Copy link
Member

@aladinor aladinor commented Feb 20, 2026

Summary

Closes #331

  • Promote station coordinates (latitude, longitude, altitude) to coordinates on the root node, aligning with CfRadial 2.0 Section 4.4. Station coords remain on sweeps for backward compatibility since xarray does not yet support scalar coordinate inheritance (pydata/xarray#9077). Once xarray adds this, a follow-up PR can remove sweep-level copies.
  • Add optional_groups parameter (default False) to all 11 open_*_datatree() functions, controlling inclusion of /radar_parameters, /georeferencing_correction, and /radar_calibration metadata subgroups. These are mostly empty or sparsely populated and excluded by default for a leaner DataTree.
  • xr.open_dataset() with site_coords=True (single-sweep access) continues to work unchanged.

Motivation: performance and compliance

Profiling a 6-month KVNX radar DataTree (126 zarr groups, 1868 arrays) on EC2 revealed structural inefficiencies in how xradar builds DataTrees:

Finding Impact This PR
F6: Station coords stored as data_vars, not coordinates Not recognized as coordinates by downstream tooling Promoted to root coords via set_coords()
F7: 14 empty/coords-only metadata subgroups per tree ~70 wasted I/O operations (14 groups × ~5 metadata reads) optional_groups=False by default excludes them

CfRadial 2.0 compliance

All three metadata subgroups are explicitly optional per the CfRadial 2.0 spec:

  • Section 3.1 (p14): "A number of optional groups are available in the root group"
  • Figure 3.3 (p17): Caption: "Optional metadata groups (highlighted in gray)"
  • Sections 7, 7.5: Each subgroup described as optional

Test plan

  • All existing IO tests pass (270/270, 8 pre-existing failures unrelated to this PR)
  • Station coords are root coordinates (dtree.ds.coords["latitude"])
  • Station coords are NOT root data_vars
  • Station coords remain on sweeps for backward compatibility
  • optional_groups=True preserves metadata subgroups
  • Roundtrip cfradial2 tests pass with optional_groups=True
  • Pre-commit hooks pass

…penradar#331)

Move latitude, longitude, and altitude from sweep datasets to root node
as coordinates, leveraging DataTree coordinate inheritance. Add
optional_groups parameter (default False) to all open_*_datatree()
functions to control inclusion of /radar_parameters,
/georeferencing_correction, and /radar_calibration subgroups.
Add changelog entries, update importers guide with common DataTree
behavior section, and note station coordinates on root in data model.
…penradar#331)

cfradial1 has its own _get_required_root_dataset() that was missing
the set_coords() promotion for lat/lon/alt. Roundtrip transform tests
(to_cfradial1 -> to_cfradial2) need optional_groups=True to preserve
radar_parameters through the conversion pipeline.
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.52%. Comparing base (b00e01f) to head (8261926).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #333      +/-   ##
==========================================
- Coverage   93.59%   93.52%   -0.07%     
==========================================
  Files          27       27              
  Lines        5654     5717      +63     
==========================================
+ Hits         5292     5347      +55     
- Misses        362      370       +8     
Flag Coverage Δ
notebooktests 0.00% <0.00%> (ø)
unittests 93.52% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…radar#331)

Revert the station-coord stripping from sweeps since xarray does not
yet support scalar coordinate inheritance (pydata/xarray#9077).
Station coords now remain on sweeps AND are promoted to coordinates
on the root node. This preserves backward compatibility for
georeference code and single-sweep access via xr.open_dataset().
The notebook demonstrates the full CfRadial2 structure including
radar_parameters, so it needs optional_groups=True now that the
default is False.
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@aladinor aladinor requested a review from kmuehlbauer February 20, 2026 18:35
Add tests exercising the optional_groups=True code path for all 9
backends that were missing coverage (gamic, odim, iris, rainbow,
furuno, datamet, hpl, metek, uf). NEXRAD already had one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Move station coordinates (lat/lon/alt) to root node for DataTree inheritance

2 participants