Skip to content

Commit

Permalink
ADD: Add new xradar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrover1 committed Sep 22, 2023
1 parent 06f01e4 commit 062ad9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def add_field(self, field_name, dic, replace_existing=False):
# add the field
self.fields[field_name] = dic
for sweep in range(self.nsweeps):
sweep_ds = self.xradar[f"sweep_{sweep}"].to_dataset()
sweep_ds = (
self.xradar[f"sweep_{sweep}"].to_dataset().drop_duplicates("azimuth")
)
sweep_ds[field_name] = (
("azimuth", "range"),
self.fields[field_name]["data"][self.get_slice(sweep)],
Expand Down Expand Up @@ -260,7 +262,7 @@ def get_gate_x_y_z(self, sweep, edges=False, filter_transitions=False):
self.xradar = self.xradar.xradar.georeference()

data = self.xradar[f"sweep_{sweep}"].xradar.georeference()
return data["x"].values, data["y"].values, data["x"].values
return data["x"].values, data["y"].values, data["z"].values

def _combine_sweeps(self, radar):
# Loop through and extract the different datasets
Expand Down
14 changes: 12 additions & 2 deletions tests/xradar/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def test_get_field(filename=filename):
dtree = xd.io.open_cfradial1_datatree(
filename,
first_dim="time",
optional=False,
)
radar = pyart.xradar.Xradar(dtree)
Expand All @@ -20,11 +19,22 @@ def test_get_field(filename=filename):
def test_get_gate_x_y_z(filename=filename):
dtree = xd.io.open_cfradial1_datatree(
filename,
first_dim="time",
optional=False,
)
radar = pyart.xradar.Xradar(dtree)
x, y, z = radar.get_gate_x_y_z(0)
assert x.shape == (483, 996)
assert y.shape == (483, 996)
assert z.shape == (483, 996)


def test_add_field(filename=filename):
dtree = xd.io.open_cfradial1_datatree(
filename,
optional=False,
)
radar = pyart.xradar.Xradar(dtree)
new_field = radar.fields["DBZ"]
radar.add_field("reflectivity", new_field)
assert "reflectivity" in radar.fields
assert radar["sweep_0"]["reflectivity"].shape == radar["sweep_0"]["DBZ"].shape

0 comments on commit 062ad9b

Please sign in to comment.