From 7bc192282e61ec1d0ef5e0480dba5067bd291f0e Mon Sep 17 00:00:00 2001 From: Max Grover Date: Fri, 29 Sep 2023 15:29:46 -0500 Subject: [PATCH] DOC: Add docs for using xradar and Py-ART together (#1469) * DOC: Add docs for xradar and Py-ART * DOC: Add docs on using xradar with Py-ART * FIX: Fix small bugs --- doc/environment.yml | 1 + examples/xradar/README.txt | 6 ++++++ examples/xradar/plot_xradar.py | 30 ++++++++++++++++++++++++++++++ pyart/xradar/accessor.py | 14 +++++++------- tests/xradar/test_accessor.py | 8 ++++---- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 examples/xradar/README.txt create mode 100644 examples/xradar/plot_xradar.py diff --git a/doc/environment.yml b/doc/environment.yml index 009e2ca6be..0c10630d2b 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -33,6 +33,7 @@ dependencies: - sphinx-copybutton - nbsphinx - pre_commit + - cmweather - pip - pip: - pooch diff --git a/examples/xradar/README.txt b/examples/xradar/README.txt new file mode 100644 index 0000000000..0ae5d93f85 --- /dev/null +++ b/examples/xradar/README.txt @@ -0,0 +1,6 @@ +.. _xradar_examples: + +Xradar Examples +------------------ + +Examples of using Xradar with Py-ART to accomplish different tasks. diff --git a/examples/xradar/plot_xradar.py b/examples/xradar/plot_xradar.py new file mode 100644 index 0000000000..d6ccb02800 --- /dev/null +++ b/examples/xradar/plot_xradar.py @@ -0,0 +1,30 @@ +""" +================================== +Plot a PPI Using Xradar and Py-ART +================================== + +An example which uses xradar and Py-ART to create a PPI plot of a Cfradial file. + +""" + +# Author: Max Grover (mgrover@anl.gov) +# License: BSD 3 clause + + +import xradar as xd + +import pyart +from pyart.testing import get_test_data + +# Locate the test data and read in using xradar +filename = get_test_data("swx_20120520_0641.nc") +tree = xd.io.open_cfradial1_datatree(filename) + +# Give the tree Py-ART radar methods +radar = pyart.xradar.Xradar(tree) + +# Plot the Reflectivity Field (corrected_reflectivity_horizontal) +display = pyart.graph.RadarMapDisplay(radar) +display.plot_ppi( + "corrected_reflectivity_horizontal", cmap="ChaseSpectral", vmin=-20, vmax=70 +) diff --git a/pyart/xradar/accessor.py b/pyart/xradar/accessor.py index 2f236b799f..cbe11ef7d2 100644 --- a/pyart/xradar/accessor.py +++ b/pyart/xradar/accessor.py @@ -17,12 +17,11 @@ class Xradar: - def __init__(self, xradar, default_sweep="sweep_0"): + def __init__(self, xradar, default_sweep="sweep_0", scan_type=None): self.xradar = xradar - self.scan_type = "ppi" + self.scan_type = scan_type or "ppi" self.combined_sweeps = self._combine_sweeps(self.xradar) self.fields = self._find_fields(self.combined_sweeps) - self.scan_type = None self.time = dict( data=(self.combined_sweeps.time - self.combined_sweeps.time.min()).astype( "int64" @@ -196,8 +195,9 @@ def get_field(self, sweep, field_name, copy=False): data : array Array containing data for the requested sweep and field. """ - data = self.xradar[f"sweep_{sweep}"][field_name].values - + self.check_field_exists(field_name) + s = self.get_slice(sweep) + data = self.fields[field_name]["data"][s] if copy: return data.copy() else: @@ -256,9 +256,9 @@ def get_gate_x_y_z(self, sweep, edges=False, filter_transitions=False): """ # Check to see if the data needs to be georeferenced if "x" not in self.xradar[f"sweep_{sweep}"].coords: - self.xradar = self.xradar.xradar.georeference() + self.combined_sweeps = self.combined_sweeps.xradar.georeference() - data = self.xradar[f"sweep_{sweep}"].xradar.georeference() + data = self.combined_sweeps.sel(sweep_number=sweep) return data["x"].values, data["y"].values, data["z"].values def init_gate_x_y_z(self): diff --git a/tests/xradar/test_accessor.py b/tests/xradar/test_accessor.py index 5cac06f0ab..113f8be3dd 100644 --- a/tests/xradar/test_accessor.py +++ b/tests/xradar/test_accessor.py @@ -15,7 +15,7 @@ def test_get_field(filename=filename): ) radar = pyart.xradar.Xradar(dtree) reflectivity = radar.get_field(0, "DBZ") - assert reflectivity.shape == (483, 996) + assert reflectivity.shape == (480, 996) def test_get_gate_x_y_z(filename=filename): @@ -25,9 +25,9 @@ def test_get_gate_x_y_z(filename=filename): ) 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) + assert x.shape == (480, 996) + assert y.shape == (480, 996) + assert z.shape == (480, 996) def test_add_field(filename=filename):