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

ADD: Adding new gatefilter method to remove last gates. #1580

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions pyart/filters/gatefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,15 @@ def exclude_invalid(self, field, exclude_masked=True, op="or"):
marked = ~np.isfinite(self._get_fdata(field))
return self._merge(marked, op, exclude_masked)

def exclude_last_gates(self, field, n_gates=10, exclude_masked=True, op="or"):
"""
Excludes a number of gates at the end of each ray. This is useful
for when trying to exclude "ring artifacts" in some datasets.
"""
marked = np.full(self._get_fdata(field).shape, False)
marked[:, -n_gates:] = True
return self._merge(marked, op, exclude_masked)

def exclude_gates(self, mask, exclude_masked=True, op="or"):
"""
Exclude gates where a given mask is equal True.
Expand Down
14 changes: 14 additions & 0 deletions tests/filters/test_gatefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ def test_gatefilter_ops():
assert gfilter.gate_excluded[0, 9] is np.True_


def test_gatefilter_exclude_last_gates():
gfilter = pyart.correct.GateFilter(radar)
gfilter.exclude_last_gates("test_field", n_gates=2)
assert gfilter.gate_excluded[0, 0] is np.False_
assert gfilter.gate_excluded[0, 8] is np.True_
assert gfilter.gate_excluded[0, 9] is np.True_

gfilter = pyart.correct.GateFilter(radar)
gfilter.exclude_last_gates("test_field", n_gates=1)
assert gfilter.gate_excluded[0, 0] is np.False_
assert gfilter.gate_excluded[0, 8] is np.False_
assert gfilter.gate_excluded[0, 9] is np.True_


def test_gatefilter_raises():
gfilter = pyart.correct.GateFilter(radar)
pytest.raises(ValueError, gfilter.exclude_below, "test_field", 0.5, op="fuzz")
Expand Down
Loading