diff --git a/examples/correct/plot_attenuation.py b/examples/correct/plot_attenuation.py index 6bdbb3ee74..f9b9eeee44 100644 --- a/examples/correct/plot_attenuation.py +++ b/examples/correct/plot_attenuation.py @@ -14,13 +14,15 @@ # License: BSD 3 clause import matplotlib.pyplot as plt +import xradar as xd import pyart file = pyart.testing.get_test_data("sgpcsaprsurcmacI7.c0.20110520.095101.nc") # read in the data -radar = pyart.io.read_cfradial(file) +tree = xd.io.open_cfradial1_datatree(file) +radar = tree.pyart.to_radar() # remove existing corrections radar.fields.pop("specific_attenuation") diff --git a/examples/correct/plot_zdr_check.py b/examples/correct/plot_zdr_check.py index df98780e0c..c723c1c07c 100644 --- a/examples/correct/plot_zdr_check.py +++ b/examples/correct/plot_zdr_check.py @@ -6,31 +6,35 @@ The technique here uses a vertically pointing scan in regions of light rain. In these regions, raindrops should be approximately spherical and therefore their ZDR near zero. Therefore, we want the average ZDR in these regions. -This code applies reflectivity and cross correlation ratio-based thresholds to the ZDR +This code applies reflectivity and cross correlation ratio-based threshold to the ZDR bias calculation to ensure that we are taking the average ZDR in light rain. """ import matplotlib.pyplot as plt +import xradar as xd from open_radar_data import DATASETS import pyart # Read in example data filename = DATASETS.fetch("sgpxsaprcfrvptI4.a1.20200205.100827.nc") -ds = pyart.io.read(filename) + +# Read in the data +tree = xd.io.open_cfradial1_datatree(filename) +radar = tree.pyart.to_radar() # Set up a typical filter for ZDR bias calculation in birdbath scan # Light rain and RhoHV near 1 ensures that raindrops are close to spherical # Therefore ZDR should be zero in these regions -gatefilter = pyart.filters.GateFilter(ds) +gatefilter = pyart.filters.GateFilter(radar) gatefilter.exclude_below("cross_correlation_ratio_hv", 0.995) gatefilter.exclude_above("cross_correlation_ratio_hv", 1) gatefilter.exclude_below("reflectivity", 10) gatefilter.exclude_above("reflectivity", 30) results = pyart.correct.calc_zdr_offset( - ds, + radar, zdr_var="differential_reflectivity", gatefilter=gatefilter, height_range=(1000, 3000), diff --git a/pyart/correct/attenuation.py b/pyart/correct/attenuation.py index 85dbca3ac5..1281e0860c 100644 --- a/pyart/correct/attenuation.py +++ b/pyart/correct/attenuation.py @@ -10,6 +10,7 @@ from warnings import warn import numpy as np +import numpy.ma as ma from scipy.integrate import cumulative_trapezoid from ..config import get_field_name, get_fillvalue, get_metadata @@ -1058,6 +1059,10 @@ def calculate_attenuation( cor_z = get_metadata(corr_refl_field) cor_z["data"] = atten + reflectivity_horizontal + z_offset + + # If the numpy arrays are not masked arrays, convert it before returning + if isinstance(cor_z["data"], np.ndarray): + cor_z["data"] = ma.masked_invalid(cor_z["data"]) cor_z["data"].mask = init_refl_correct.mask cor_z["_FillValue"] = get_fillvalue()