Skip to content

Commit

Permalink
FIX: Fixed to_xarray() for more than one radar
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhamidali committed Aug 30, 2024
1 parent ebcf031 commit ef72aa0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pyart/core/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ def to_xarray(self):

def _process_radar_name(radar_name):
"""Process radar_name to handle different formats."""
if radar_name.dtype.kind in {"S", "U"} and radar_name.ndim > 1:
return radar_name.flatten()
if radar_name.dtype.kind == "S" and radar_name.ndim > 1:
# Join each row of bytes into a single byte string
return np.array(
[b"".join(row) for row in radar_name],
dtype=f"|S{radar_name.shape[1]}",
)
return radar_name

lon, lat = self.get_point_longitude_latitude()
Expand Down Expand Up @@ -434,7 +438,9 @@ def _process_radar_name(radar_name):
)

# Add radar_name to attributes
ds.attrs["radar_name"] = radar_name if radar_name.size > 0 else "ExampleRadar"
ds.attrs["radar_name"] = (
radar_name.tolist() if radar_name.size > 1 else radar_name.item()
)
ds.attrs["nradar"] = radar_name.size
ds.attrs.update(self.metadata)
for key in ds.attrs:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_grid_to_xarray():

# Check radar-specific attributes
assert ds.attrs["nradar"] == 1
assert ds.attrs["radar_name"][0] == "ExampleRadar"
assert ds.attrs["radar_name"] == "ExampleRadar"


def _check_dicts_similar(dic1, dic2):
Expand Down

0 comments on commit ef72aa0

Please sign in to comment.