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

DOC: Add docs for using xradar and Py-ART together #1469

Merged
merged 3 commits into from
Sep 29, 2023
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
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 (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
)
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 @@ -199,8 +198,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 @@ -259,9 +259,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 _combine_sweeps(self, radar):
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 @@ -13,7 +13,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 @@ -23,9 +23,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