Skip to content

Commit

Permalink
ADD: Add xradar io to correct examples (#1708)
Browse files Browse the repository at this point in the history
* ADD: Add xradar io to correct examples

* FIX: Fix the extra radar in explanation
  • Loading branch information
mgrover1 authored Dec 16, 2024
1 parent ce9a566 commit 3d3fc1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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 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),
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

0 comments on commit 3d3fc1e

Please sign in to comment.