diff --git a/pyart/xradar/accessor.py b/pyart/xradar/accessor.py index 4939563757..54ec8b823e 100644 --- a/pyart/xradar/accessor.py +++ b/pyart/xradar/accessor.py @@ -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) @@ -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): diff --git a/tests/xradar/test_accessor.py b/tests/xradar/test_accessor.py index 730fbf5acc..71865ad7dd 100644 --- a/tests/xradar/test_accessor.py +++ b/tests/xradar/test_accessor.py @@ -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( @@ -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)