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

ADD: Add xradar io to correct examples #1708

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion examples/correct/plot_attenuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 8 additions & 4 deletions examples/correct/plot_zdr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 thresholradar to the ZDR
zssherman marked this conversation as resolved.
Show resolved Hide resolved
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),
Expand Down
5 changes: 5 additions & 0 deletions pyart/correct/attenuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
Loading