Skip to content

ENH: accessor methods reindex_angle and reindex_range - #544

Merged
kmuehlbauer merged 8 commits into
openradar:mainfrom
syedhamidali:enh/accessor-reindex
Oct 28, 2026
Merged

kmuehlbauer merged 8 commits into
openradar:mainfrom
syedhamidali:enh/accessor-reindex

Conversation

@syedhamidali

@syedhamidali syedhamidali commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

.xradar gets reindex_angle and reindex_range, the same functions as in xradar.util, with the same keyword arguments:

  • on a Dataset (a sweep): ds.xradar.reindex_angle(start_angle=0, stop_angle=360, angle_res=1.0, direction=1) and ds.xradar.reindex_range(start_range=..., stop_range=..., range_res=...),
  • on a DataTree: applied to every sweep with apply_to_sweeps (the root and the other nodes are not changed, the input is not changed).

This makes it possible to put sweeps from several files or times on one grid after they were read, for example before stacking them with xr.concat (#449). The test does that with two sweeps whose angles and ranges differ slightly, and checks that the result has no gaps.

The methods only call the functions and take **kwargs, so the arguments and defaults stay in one place (xradar.util). Tests: Dataset (same result as the functions), DataTree (all sweeps on one grid, stacking, other nodes untouched). Calling reindex_angle from the DataTree reindex_range makes the DataTree test fail.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.02%. Comparing base (7509037) to head (5d4618a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #544   +/-   ##
=======================================
  Coverage   96.01%   96.02%           
=======================================
  Files          30       30           
  Lines        7461     7472   +11     
=======================================
+ Hits         7164     7175   +11     
  Misses        297      297           
Flag Coverage Δ
notebooktests 82.80% <83.33%> (+0.01%) ⬆️
unittests 95.86% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@aladinor aladinor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @syedhamidali, the methods are small and the range part works well. One thing on reindex_angle (inline, with suggestions).

What I ran, at 012763f merged locally with main (a8f2dac): tests/test_accessors.py and tests/test_util.py 155 passed, the angle_reindexing notebook passes, black/ruff clean. On the GAMIC and ODIM sample volumes the root and the non-sweep nodes are unchanged, the moments stay lazy (and chunked with chunks={}), and the result goes through to_cfradial1 and to_cfradial2 with the same values.

reindex_angle does less than reindex_coord. While reading, reindex_coord={"angle": ...} runs remove_duplicate_rays, reindex_angle and ipol_time (_apply_reindex_coord in io/backends/common.py). The accessor only runs reindex_angle, so after reading:

  • xd.open_datatree("DWD-Vol-2_99999_20180601054047_00.h5", engine="gamic").xradar.reindex_angle(start_angle=0, stop_angle=360, angle_res=1.0, direction=1) raises ValueError: cannot reindex or align along dimension 'azimuth' because the (pandas) index has duplicate values (sweep_4 and sweep_7 have one duplicate ray each; it is the notebook file). The notebook section works because it calls remove_duplicate_rays first on the sweep and only reindex_range on the volume.
  • rays which are missing get NaT as time (10 dropped rays on the ODIM sweep_0 give 10 NaT, with ipol_time 0).

Since the issue is about data which is already open, I think the accessor should give the same result as reindex_coord. The suggestions do that with a small helper, plus a test which compares with reindex_coord on the GAMIC volume (it fails at 012763f with the error above) and the notebook cell. With them: 156 passed, notebook passes. The helper needs time in the test sweeps.

Nit: the last block of test_accessor_reindex_datatree runs reindex_range a second time on out; comparing out["sweep_0"] with the two functions is enough.

Comment thread xradar/accessors.py Resolved
Comment thread xradar/accessors.py Resolved
Comment thread xradar/accessors.py Resolved
Comment thread tests/test_accessors.py Resolved
Comment thread tests/test_accessors.py Resolved
Comment thread docs/notebooks/angle_reindexing.md Resolved
@kmuehlbauer
kmuehlbauer enabled auto-merge (squash) October 28, 2026 13:34
@kmuehlbauer
kmuehlbauer merged commit 1916fd8 into openradar:main Oct 28, 2026
11 checks passed
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.

Accessor methods for reindex_angle and reindex_range

3 participants