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

MNT: Update arm_scan_name to be optional. Also dep warning fix. #1578

Merged
merged 3 commits into from
May 15, 2024
Merged
Changes from all commits
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
40 changes: 26 additions & 14 deletions pyart/io/cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def read_cfradial(
exclude_fields=None,
include_fields=None,
delay_field_loading=False,
use_arm_scan_name=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -92,6 +93,10 @@ def read_cfradial(
LazyLoadDict objects not dict objects. Delayed field loading will not
provide any speedup in file where the number of gates vary between
rays (ngates_vary=True) and is not recommended.
use_arm_scan_name : bool
Whether or not to get the sweep_mode information from the ARM scan_name
attribute. Default is False and will use the sweep_mode information as
defined in the cfradial standards.

Returns
-------
Expand Down Expand Up @@ -126,7 +131,7 @@ def read_cfradial(
if "volume_number" in ncvars:
if np.ma.isMaskedArray(ncvars["volume_number"][:]):
metadata["volume_number"] = int(
np.ma.getdata(ncvars["volume_number"][:].flatten())
np.ma.getdata(ncvars["volume_number"][:].flatten())[0]
)
else:
metadata["volume_number"] = int(ncvars["volume_number"][:])
Expand Down Expand Up @@ -191,20 +196,27 @@ def read_cfradial(
else:
ray_angle_res = None

# Uses ARM scan name if present.
if not hasattr(ncobj, "scan_name"):
scan_name = ""
else:
scan_name = ncobj.scan_name
if len(scan_name) > 0:
mode = scan_name
else:
# first sweep mode determines scan_type
try:
mode = netCDF4.chartostring(sweep_mode["data"][0])[()].decode("utf-8")
except AttributeError:
# Python 3, all strings are already unicode.
# Use ARM scan_name if chosen by the user
if use_arm_scan_name:
# Check if attribute actually exists
if not hasattr(ncobj, "scan_name"):
warnings.warn(
UserWarning,
"No scan_name attribute present in dataset, using sweep_mode instead.",
)
mode = netCDF4.chartostring(sweep_mode["data"][0])[()]
# Check if attribute is invalid of length 0
elif len(ncobj.scan_name) < 0 or ncobj.scan_name is None:
warnings.warn(
UserWarning,
"Scan name contains no sweep information, using sweep_mode instead.",
)
mode = netCDF4.chartostring(sweep_mode["data"][0])[()]
else:
mode = ncobj.scan_name
else:
# Use sweep_mode if arm_scan_name isn't used. This is default
mode = netCDF4.chartostring(sweep_mode["data"][0])[()]

mode = mode.strip()

Expand Down
Loading