Skip to content

Commit

Permalink
FIX: Fix handling of sweep_mode attribiutes (#143)
Browse files Browse the repository at this point in the history
* FIX: Fix handling of sweep_mode attribiutes

* ADD: Update the history.md file
  • Loading branch information
mgrover1 authored Oct 31, 2023
1 parent 815f504 commit 5570e22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions xradar/io/backends/cfradial1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion xradar/io/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5570e22

Please sign in to comment.