diff --git a/docs/history.md b/docs/history.md index 940e70ec..9f56b7ed 100644 --- a/docs/history.md +++ b/docs/history.md @@ -1,5 +1,8 @@ # History +## Development Version +* FIX: Fix handling of sweep_mode attribiutes ({pull}`143`) by [@mgrover1](https://github.com/mgrover1) + ## 0.4.1 (2023-10-26) * FIX: Add history to cfradial1 output, and fix minor error in CfRadial1_Export.ipynb notebook({pull}`132`) by [@syedhamidali](https://github.com/syedhamidali) diff --git a/tests/io/test_io.py b/tests/io/test_io.py index cfa8368d..e27ea792 100644 --- a/tests/io/test_io.py +++ b/tests/io/test_io.py @@ -78,6 +78,7 @@ def test_open_cfradial1_datatree(cfradial1_file): "range", } assert np.round(ds.sweep_fixed_angle.values.item(), 1) == elevations[i] + assert ds.sweep_mode == "azimuth_surveillance" def test_open_cfradial1_dataset(cfradial1_file): diff --git a/xradar/io/backends/cfradial1.py b/xradar/io/backends/cfradial1.py index 8d6f0f26..299fb287 100644 --- a/xradar/io/backends/cfradial1.py +++ b/xradar/io/backends/cfradial1.py @@ -155,8 +155,8 @@ def _get_sweep_groups( swslice = slice(i, i + 1) ds = data.isel(time=tslice, sweep=swslice).squeeze("sweep") - sweep_mode = _maybe_decode(ds.sweep_mode).compute() - dim0 = "elevation" if sweep_mode == "rhi" else "azimuth" + ds["sweep_mode"] = _maybe_decode(ds.sweep_mode).compute() + dim0 = "elevation" if ds["sweep_mode"] == "rhi" else "azimuth" # check and extract for variable number of gates if ray_n_gates is not False: diff --git a/xradar/io/backends/common.py b/xradar/io/backends/common.py index 330c9cbe..d954bce5 100644 --- a/xradar/io/backends/common.py +++ b/xradar/io/backends/common.py @@ -24,7 +24,12 @@ def _maybe_decode(attr): try: - return attr.decode() + # Decode the xr.DataArray differently than a byte string + if type(attr) == xr.core.dataarray.DataArray: + decoded_attr = attr.astype(str).str.rstrip() + else: + decoded_attr = attr.decode() + return decoded_attr except AttributeError: return attr