Skip to content

Commit

Permalink
DOC: Add docs for using xradar and Py-ART together (#1469)
Browse files Browse the repository at this point in the history
* DOC: Add docs for xradar and Py-ART

* DOC: Add docs on using xradar with Py-ART

* FIX: Fix small bugs
  • Loading branch information
mgrover1 authored Sep 29, 2023
1 parent 1870652 commit 7bc1922
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
- sphinx-copybutton
- nbsphinx
- pre_commit
- cmweather
- pip
- pip:
- pooch
Expand Down
6 changes: 6 additions & 0 deletions examples/xradar/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _xradar_examples:

Xradar Examples
------------------

Examples of using Xradar with Py-ART to accomplish different tasks.
30 changes: 30 additions & 0 deletions examples/xradar/plot_xradar.py
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
# 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
)
14 changes: 7 additions & 7 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/xradar/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 7bc1922

Please sign in to comment.