Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: Add gridding ability to xradar radar object #1719

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,22 @@ def __init__(self, xradar, default_sweep="sweep_0", scan_type=None):
self.ngates = len(self.range["data"])
self.nrays = len(self.azimuth["data"])
self.projection = {"proj": "pyart_aeqd", "_include_lon_0_lat_0": True}
self.sweep_number = {
"standard_name": "sweep_number",
"long_name": "Sweep number",
"data": np.unique(self.combined_sweeps.sweep_number),
}
self.sweep_mode = self._determine_sweep_mode()
self.instrument_parameters = self.find_instrument_parameters()
self.init_gate_x_y_z()
self.init_gate_longitude_latitude()
self.init_gate_alt()

# Extra methods needed for compatibility
self.rays_are_indexed = None
self.ray_angle_res = None
self.target_scan_rate = None

def __repr__(self):
return formatting.datatree_repr(self.xradar)

Expand Down Expand Up @@ -392,6 +403,24 @@ def __getitem__(self: DataTree, key):

# Iterators

def _determine_sweep_mode(self):
sweep_mode = {
"units": "unitless",
"standard_name": "sweep_mode",
"long_name": "Sweep mode",
}
if "sweep_mode" in self.xradar["sweep_0"]:
sweep_mode["data"] = np.array(
self.nsweeps * [str(self.xradar["sweep_0"].sweep_mode.values)],
dtype="S",
)
else:
sweep_mode["data"] = np.array(
self.nsweeps * ["azimuth_surveillance"], dtype="S"
)

return sweep_mode

def find_instrument_parameters(self):
# By default, check the radar_parameters first
if "radar_parameters" in list(self.xradar.children):
Expand Down
19 changes: 19 additions & 0 deletions tests/xradar/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
filename = DATASETS.fetch("cfrad.20080604_002217_000_SPOL_v36_SUR.nc")
cfradial2_file = DATASETS.fetch("cfrad2.20080604_002217_000_SPOL_v36_SUR.nc")

COMMON_MAP_TO_GRID_ARGS = {
"grid_shape": (3, 9, 10),
"grid_limits": ((-400.0, 400.0), (-900.0, 900.0), (-900, 900)),
"fields": None,
"gridding_algo": "map_to_grid",
"roi_func": lambda z, y, x: 30,
}


def test_get_field(filename=filename):
dtree = xd.io.open_cfradial1_datatree(
Expand Down Expand Up @@ -209,3 +217,14 @@ def test_cfradial2_data():
# Ensure georeferencing works as expected
x, y, z = radar.get_gate_x_y_z(0)
assert x.shape == (480, 996)


def test_grid_xradar():
dtree = xd.io.open_cfradial1_datatree(
filename,
optional=False,
)
radar = dtree.pyart.to_radar()
grid = pyart.map.grid_from_radars([radar], **COMMON_MAP_TO_GRID_ARGS)
assert (10, 9, 3) == (grid.nx, grid.ny, grid.nz)
assert_allclose(np.min(grid.fields["DBZ"]["data"]), -1.3201784)
Loading