From 83848974687dcf758df3b744d2127c75687ed353 Mon Sep 17 00:00:00 2001 From: Max Grover Date: Fri, 5 Apr 2024 10:54:32 -0500 Subject: [PATCH] FIX: Add get_azimuth xradar (#1547) * FIX: Fix handling of instrument params * ADD: Add get_azimuth method to xradar --- pyart/xradar/accessor.py | 26 ++++++++++++++++++++++++++ tests/xradar/test_accessor.py | 10 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/pyart/xradar/accessor.py b/pyart/xradar/accessor.py index 90b7c66c7c..94dd1b0675 100644 --- a/pyart/xradar/accessor.py +++ b/pyart/xradar/accessor.py @@ -712,6 +712,32 @@ def _find_fields(self, ds): } return fields + def get_azimuth(self, sweep, copy=False): + """ + Return an array of azimuth angles for a given sweep. + + Parameters + ---------- + sweep : int + Sweep number to retrieve data for, 0 based. + copy : bool, optional + True to return a copy of the azimuths. False, the default, returns + a view of the azimuths (when possible), changing this data will + change the data in the underlying Radar object. + + Returns + ------- + azimuths : array + Array containing the azimuth angles for a given sweep. + + """ + s = self.get_slice(sweep) + azimuths = self.azimuth["data"][s] + if copy: + return azimuths.copy() + else: + return azimuths + def _point_data_factory(grid, coordinate): """Return a function which returns the locations of all points.""" diff --git a/tests/xradar/test_accessor.py b/tests/xradar/test_accessor.py index 611ef4ad2d..6a0bc60fe4 100644 --- a/tests/xradar/test_accessor.py +++ b/tests/xradar/test_accessor.py @@ -19,6 +19,16 @@ def test_get_field(filename=filename): assert reflectivity.shape == (480, 996) +def test_get_azimuth(filename=filename): + dtree = xd.io.open_cfradial1_datatree( + filename, + optional=False, + ) + radar = pyart.xradar.Xradar(dtree) + azimuths = radar.get_azimuth(0) + assert azimuths.shape == (480,) + + def test_instrument_parameters(filename=filename): dtree = xd.io.open_cfradial1_datatree( filename,