-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ENH: xarray grid compatibility * ENH: xarray grid output * adding back xarray availablity check * pre-commit run * fix minor error in grid_to_xarary * modified coords in function to_xarray() * modified coords in function to_xarray() + pre-commit * Add plot_max_cappi example and update related modules * Update tests and fix Example * drop a few args * Fix grid.to_xarray() * FIX: Fixed some tests and to_xarray() function * FIX: Fixed to_xarray() for more than one radar --------- Co-authored-by: Zach Sherman <[email protected]>
- Loading branch information
1 parent
a82b49d
commit db03920
Showing
8 changed files
with
826 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
""" | ||
============= | ||
Plot Max-CAPPI | ||
============= | ||
This is an example of how to plot a Max-CAPPI | ||
within a Py-ART grid display object. | ||
""" | ||
|
||
print(__doc__) | ||
|
||
# Author: Hamid Ali Syed ([email protected]) | ||
# License: BSD 3 clause | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
import pyart | ||
from pyart.testing import get_test_data | ||
|
||
######################################### | ||
# ** MAX-CAPPI Display | ||
# | ||
|
||
# Define and Read in the test data | ||
grid_file = get_test_data("20110520100000_nexrad_grid.nc") | ||
grid = pyart.io.read_grid(grid_file) | ||
|
||
|
||
# Create a grid display | ||
gdisplay = pyart.graph.GridMapDisplay(grid) | ||
gdisplay.plot_maxcappi(field="REF", range_rings=True, add_slogan=True) | ||
|
||
|
||
######################################### | ||
# ** Second Example | ||
# | ||
# Let's read in a cfradial file and create a grid. | ||
|
||
|
||
import logging | ||
from datetime import datetime | ||
|
||
import fsspec | ||
import pytz | ||
|
||
|
||
def download_nexrad(timezone, date, site, local_date=False): | ||
"""Download NEXRAD radar data from an S3 bucket.""" | ||
try: | ||
utc_date = ( | ||
pytz.timezone(timezone).localize(date).astimezone(pytz.utc) | ||
if local_date | ||
else date | ||
) | ||
logging.info(f"Time: {utc_date}") | ||
|
||
fs = fsspec.filesystem("s3", anon=True) | ||
nexrad_path = utc_date.strftime( | ||
f"s3://noaa-nexrad-level2/%Y/%m/%d/{site}/{site}%Y%m%d_%H*" | ||
) | ||
files = sorted(fs.glob(nexrad_path)) | ||
|
||
return [file for file in files if not file.endswith("_MDM")] | ||
except Exception as e: | ||
logging.error("Error in processing: %s", e) | ||
return [] | ||
|
||
|
||
# Load NEXRAD data from S3 Bucket | ||
site = "PHWA" | ||
timezone = "UTC" | ||
date = datetime(2024, 8, 25, 8, 29) | ||
|
||
# Correctly passing the site and timezone | ||
file = download_nexrad(timezone, date, site, local_date=False)[0] | ||
|
||
|
||
# Read the data using nexrad_archive reader | ||
radar = pyart.io.read_nexrad_archive("s3://" + file) | ||
|
||
# Create a 3D grid | ||
# Mask out last 10 gates of each ray, this removes the "ring" around the radar. | ||
radar.fields["reflectivity"]["data"][:, -10:] = np.ma.masked | ||
|
||
# Exclude masked gates from the gridding | ||
gatefilter = pyart.filters.GateFilter(radar) | ||
gatefilter.exclude_transition() | ||
gatefilter.exclude_masked("reflectivity") | ||
gatefilter.exclude_outside("reflectivity", 10, 80) | ||
|
||
# Perform Cartesian mapping, limit to the reflectivity field. | ||
max_range = np.ceil(radar.range["data"].max()) | ||
if max_range / 1e3 > 250: | ||
max_range = 250 * 1e3 | ||
|
||
grid = pyart.map.grid_from_radars( | ||
(radar,), | ||
gatefilters=(gatefilter,), | ||
grid_shape=(30, 441, 441), | ||
grid_limits=((0, 10000), (-max_range, max_range), (-max_range, max_range)), | ||
fields=["reflectivity"], | ||
) | ||
|
||
# Create a grid display | ||
gdisplay = pyart.graph.GridMapDisplay(grid) | ||
with plt.style.context("dark_background"): | ||
gdisplay.plot_maxcappi( | ||
field="reflectivity", cmap="pyart_HomeyerRainbow", add_slogan=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.