Skip to content

Commit ac39623

Browse files
Nexrad split cut removal (#271)
* fixing IndexError when opening nexrad Split Cut Mode file * fixing error with pytest * running pre-commit * running pre-commit * Update xradar/io/backends/nexrad_level2.py Co-authored-by: Kai Mühlbauer <[email protected]> * adding split cut mode to comment in the global/root attributes * attemp to fix lint and style checks errors * documenting changes in history.md files * getting ride of split cut mode comment * getting ride of split cut mode comment * fixing conflitcs * removing empty space * adding AVSET docummentation --------- Co-authored-by: Kai Mühlbauer <[email protected]>
1 parent eebe778 commit ac39623

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

docs/history.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* ENH: Add message type 1 decoding to nexrad level 2 reader ({issue}`256`) ({pull}`267`) by [@kmuehlbauer](https://github.com/kmuehlbauer).
1919
* ENH: Introduce file locks for nexrad level2 and iris backend ({issue}`207`) ({pull}`268`) by [@kmuehlbauer](https://github.com/kmuehlbauer).
2020

21+
2122
## 0.8.0 (2024-11-04)
2223

2324
This is the first version which uses datatree directly from xarray. Thus, xarray is pinned to version >= 2024.10.0.

xradar/io/backends/common.py

-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def _get_required_root_dataset(ls_ds, optional=True):
260260

261261
# merging both the created and the variables within each dataset
262262
root = xr.merge([root, _vars], compat="override")
263-
264263
attrs = root.attrs.keys()
265264
remove_attrs = set(attrs) ^ set(required_global_attrs)
266265
if optional:

xradar/io/backends/nexrad_level2.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,6 @@ def open_nexradlevel2_datatree(
16941694
"""
16951695
from xarray.core.treenode import NodePath
16961696

1697-
comment = None
1698-
16991697
if isinstance(sweep, str):
17001698
sweep = NodePath(sweep).name
17011699
sweeps = [sweep]
@@ -1712,18 +1710,19 @@ def open_nexradlevel2_datatree(
17121710
)
17131711
else:
17141712
with NEXRADLevel2File(filename_or_obj, loaddata=False) as nex:
1715-
nsweeps = nex.msg_5["number_elevation_cuts"]
1716-
n_sweeps = len(nex.msg_31_data_header)
1717-
# check for zero (old files)
1718-
if nsweeps == 0:
1719-
nsweeps = n_sweeps
1720-
comment = "No message 5 information available"
1721-
# Check if duplicated sweeps ("split cut mode")
1722-
elif nsweeps > n_sweeps:
1723-
nsweeps = n_sweeps
1724-
comment = "Split Cut Mode scanning strategy"
1725-
1726-
sweeps = [f"sweep_{i}" for i in range(nsweeps)]
1713+
# Expected number of elevation cuts from the VCP definition
1714+
exp_sweeps = nex.msg_5["number_elevation_cuts"]
1715+
# Actual number of sweeps recorded in the file
1716+
act_sweeps = len(nex.msg_31_data_header)
1717+
# Check for AVSET mode: If AVSET was active, the actual number of sweeps (act_sweeps)
1718+
# will be fewer than the expected number (exp_sweeps), as higher elevations were skipped.
1719+
# More info https://www.test.roc.noaa.gov/radar-techniques/avset.php
1720+
# https://www.test.roc.noaa.gov/public-documents/engineering-branch/new-technology/misc/avset/AVSET_AMS_RADAR_CONF_Final.pdf
1721+
if exp_sweeps > act_sweeps:
1722+
# Adjust nsweeps to the actual number of recorded sweeps
1723+
exp_sweeps = act_sweeps
1724+
1725+
sweeps = [f"sweep_{i}" for i in range(act_sweeps)]
17271726

17281727
sweep_dict = open_sweeps_as_dict(
17291728
filename_or_obj=filename_or_obj,
@@ -1745,8 +1744,6 @@ def open_nexradlevel2_datatree(
17451744
)
17461745
ls_ds: list[xr.Dataset] = [sweep_dict[sweep] for sweep in sweep_dict.keys()]
17471746
ls_ds.insert(0, xr.Dataset())
1748-
if comment is not None:
1749-
ls_ds[0].attrs["comment"] = comment
17501747
dtree: dict = {
17511748
"/": _assign_root(ls_ds),
17521749
"/radar_parameters": _get_subgroup(ls_ds, radar_parameters_subgroup),

0 commit comments

Comments
 (0)