Repository navigation
ENH: accessor methods reindex_angle and reindex_range - #544
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # docs/history.md
aladinor
left a comment
There was a problem hiding this comment.
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)raisesValueError: 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 callsremove_duplicate_raysfirst on the sweep and onlyreindex_rangeon the volume.- rays which are missing get
NaTas time (10 dropped rays on the ODIM sweep_0 give 10NaT, withipol_time0).
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.
…e angle_reindexing notebook
history.md.xradargetsreindex_angleandreindex_range, the same functions as inxradar.util, with the same keyword arguments:ds.xradar.reindex_angle(start_angle=0, stop_angle=360, angle_res=1.0, direction=1)andds.xradar.reindex_range(start_range=..., stop_range=..., range_res=...),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). Callingreindex_anglefrom the DataTreereindex_rangemakes the DataTree test fail.