Skip to content

Commit

Permalink
FIX: Pytest fix for apply_to_sweeps
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhamidali committed Aug 31, 2024
1 parent 88ab142 commit 22f4331
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 0.6.4 (2024-08-31)

ADD: Added `apply_to_sweeps` function for applying custom operations to all sweeps in a `DataTree` radar volume. This function allows users to apply a specified function to each sweep, with options for passing additional arguments and handling errors gracefully. Implemented by [@syedhamidali](https://github.com/syedhamidali), ({pull}`202`).

## 0.6.4 (2024-08-30)

FIX: Notebooks are now conforming to ruff's style checks by [@rcjackson](https://github.com/rcjackson), ({pull}`199`) by [@rcjackson](https://github.com/rcjackson).
Expand Down
25 changes: 25 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,28 @@ def error_function(ds):
raise ValueError("This is an intentional error")

util.apply_to_sweeps(dtree, error_function)


def test_apply_to_sweeps_with_sweep_name():
# Fetch the sample radar file
filename = DATASETS.fetch("sample_sgp_data.nc")
dtree = io.open_cfradial1_datatree(filename)

# Define a function that requires the sweep name
def function_with_sweep_name(ds, sweep):
"""A function that adds a field including the sweep name."""
ds["sweep_name_field"] = sweep # Add the sweep name as a new variable
return ds

# Apply the function to all sweeps, passing the sweep name
dtree = util.apply_to_sweeps(dtree, function_with_sweep_name, pass_sweep_name=True)

# Verify that the sweep_name_field has been added and contains the correct sweep name
sweep_keys = util.get_sweep_keys(dtree)
for key in sweep_keys:
assert (
"sweep_name_field" in dtree[key].data_vars
), f"sweep_name_field not found in {key}"
assert (
dtree[key]["sweep_name_field"].values == key
), f"sweep_name_field value is incorrect in {key}"

0 comments on commit 22f4331

Please sign in to comment.