Skip to content

Commit

Permalink
Nexrad split cut removal (#271)
Browse files Browse the repository at this point in the history
* 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 <kmuehlbauer@wradlib.org>

* 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 <kmuehlbauer@wradlib.org>
  • Loading branch information
aladinor and kmuehlbauer authored Feb 19, 2025
1 parent eebe778 commit ac39623
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* ENH: Add message type 1 decoding to nexrad level 2 reader ({issue}`256`) ({pull}`267`) by [@kmuehlbauer](https://github.com/kmuehlbauer).
* ENH: Introduce file locks for nexrad level2 and iris backend ({issue}`207`) ({pull}`268`) by [@kmuehlbauer](https://github.com/kmuehlbauer).


## 0.8.0 (2024-11-04)

This is the first version which uses datatree directly from xarray. Thus, xarray is pinned to version >= 2024.10.0.
Expand Down
1 change: 0 additions & 1 deletion xradar/io/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def _get_required_root_dataset(ls_ds, optional=True):

# merging both the created and the variables within each dataset
root = xr.merge([root, _vars], compat="override")

attrs = root.attrs.keys()
remove_attrs = set(attrs) ^ set(required_global_attrs)
if optional:
Expand Down
29 changes: 13 additions & 16 deletions xradar/io/backends/nexrad_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,8 +1694,6 @@ def open_nexradlevel2_datatree(
"""
from xarray.core.treenode import NodePath

comment = None

if isinstance(sweep, str):
sweep = NodePath(sweep).name
sweeps = [sweep]
Expand All @@ -1712,18 +1710,19 @@ def open_nexradlevel2_datatree(
)
else:
with NEXRADLevel2File(filename_or_obj, loaddata=False) as nex:
nsweeps = nex.msg_5["number_elevation_cuts"]
n_sweeps = len(nex.msg_31_data_header)
# check for zero (old files)
if nsweeps == 0:
nsweeps = n_sweeps
comment = "No message 5 information available"
# Check if duplicated sweeps ("split cut mode")
elif nsweeps > n_sweeps:
nsweeps = n_sweeps
comment = "Split Cut Mode scanning strategy"

sweeps = [f"sweep_{i}" for i in range(nsweeps)]
# Expected number of elevation cuts from the VCP definition
exp_sweeps = nex.msg_5["number_elevation_cuts"]
# Actual number of sweeps recorded in the file
act_sweeps = len(nex.msg_31_data_header)
# Check for AVSET mode: If AVSET was active, the actual number of sweeps (act_sweeps)
# will be fewer than the expected number (exp_sweeps), as higher elevations were skipped.
# More info https://www.test.roc.noaa.gov/radar-techniques/avset.php
# https://www.test.roc.noaa.gov/public-documents/engineering-branch/new-technology/misc/avset/AVSET_AMS_RADAR_CONF_Final.pdf
if exp_sweeps > act_sweeps:
# Adjust nsweeps to the actual number of recorded sweeps
exp_sweeps = act_sweeps

sweeps = [f"sweep_{i}" for i in range(act_sweeps)]

sweep_dict = open_sweeps_as_dict(
filename_or_obj=filename_or_obj,
Expand All @@ -1745,8 +1744,6 @@ def open_nexradlevel2_datatree(
)
ls_ds: list[xr.Dataset] = [sweep_dict[sweep] for sweep in sweep_dict.keys()]
ls_ds.insert(0, xr.Dataset())
if comment is not None:
ls_ds[0].attrs["comment"] = comment
dtree: dict = {
"/": _assign_root(ls_ds),
"/radar_parameters": _get_subgroup(ls_ds, radar_parameters_subgroup),
Expand Down

0 comments on commit ac39623

Please sign in to comment.