Skip to content

Commit 3d3fc1e

Browse files
authored
ADD: Add xradar io to correct examples (#1708)
* ADD: Add xradar io to correct examples * FIX: Fix the extra radar in explanation
1 parent ce9a566 commit 3d3fc1e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

examples/correct/plot_attenuation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
# License: BSD 3 clause
1515

1616
import matplotlib.pyplot as plt
17+
import xradar as xd
1718

1819
import pyart
1920

2021
file = pyart.testing.get_test_data("sgpcsaprsurcmacI7.c0.20110520.095101.nc")
2122

2223
# read in the data
23-
radar = pyart.io.read_cfradial(file)
24+
tree = xd.io.open_cfradial1_datatree(file)
25+
radar = tree.pyart.to_radar()
2426

2527
# remove existing corrections
2628
radar.fields.pop("specific_attenuation")

examples/correct/plot_zdr_check.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@
66
The technique here uses a vertically pointing scan in regions of light rain.
77
In these regions, raindrops should be approximately spherical and therefore their
88
ZDR near zero. Therefore, we want the average ZDR in these regions.
9-
This code applies reflectivity and cross correlation ratio-based thresholds to the ZDR
9+
This code applies reflectivity and cross correlation ratio-based threshold to the ZDR
1010
bias calculation to ensure that we are taking the average ZDR in light rain.
1111
1212
"""
1313

1414
import matplotlib.pyplot as plt
15+
import xradar as xd
1516
from open_radar_data import DATASETS
1617

1718
import pyart
1819

1920
# Read in example data
2021
filename = DATASETS.fetch("sgpxsaprcfrvptI4.a1.20200205.100827.nc")
21-
ds = pyart.io.read(filename)
22+
23+
# Read in the data
24+
tree = xd.io.open_cfradial1_datatree(filename)
25+
radar = tree.pyart.to_radar()
2226

2327
# Set up a typical filter for ZDR bias calculation in birdbath scan
2428
# Light rain and RhoHV near 1 ensures that raindrops are close to spherical
2529
# Therefore ZDR should be zero in these regions
26-
gatefilter = pyart.filters.GateFilter(ds)
30+
gatefilter = pyart.filters.GateFilter(radar)
2731
gatefilter.exclude_below("cross_correlation_ratio_hv", 0.995)
2832
gatefilter.exclude_above("cross_correlation_ratio_hv", 1)
2933
gatefilter.exclude_below("reflectivity", 10)
3034
gatefilter.exclude_above("reflectivity", 30)
3135

3236
results = pyart.correct.calc_zdr_offset(
33-
ds,
37+
radar,
3438
zdr_var="differential_reflectivity",
3539
gatefilter=gatefilter,
3640
height_range=(1000, 3000),

pyart/correct/attenuation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from warnings import warn
1111

1212
import numpy as np
13+
import numpy.ma as ma
1314
from scipy.integrate import cumulative_trapezoid
1415

1516
from ..config import get_field_name, get_fillvalue, get_metadata
@@ -1058,6 +1059,10 @@ def calculate_attenuation(
10581059

10591060
cor_z = get_metadata(corr_refl_field)
10601061
cor_z["data"] = atten + reflectivity_horizontal + z_offset
1062+
1063+
# If the numpy arrays are not masked arrays, convert it before returning
1064+
if isinstance(cor_z["data"], np.ndarray):
1065+
cor_z["data"] = ma.masked_invalid(cor_z["data"])
10611066
cor_z["data"].mask = init_refl_correct.mask
10621067
cor_z["_FillValue"] = get_fillvalue()
10631068

0 commit comments

Comments
 (0)