Skip to content

Add optional Hampel filter support to H12 functions#955

Open
Tanisha127 wants to merge 5 commits intomalariagen:masterfrom
Tanisha127:feature/hampel-filter-h12
Open

Add optional Hampel filter support to H12 functions#955
Tanisha127 wants to merge 5 commits intomalariagen:masterfrom
Tanisha127:feature/hampel-filter-h12

Conversation

@Tanisha127
Copy link
Copy Markdown
Contributor

Closes #351

Summary

Added optional Hampel filter support to h12_gwss() and related plotting
functions. H12 GWSS results commonly include isolated outliers with high H12
values but little support from neighbouring windows. These are unlikely to be
true selection signals. The Hampel filter smooths these isolated outliers,
helping direct attention towards real recent selection signals.

Changes

  • Added hampel_filter() function using median absolute deviation (MAD)
  • Added three optional parameters to h12_gwss() and all related plotting functions:
    • apply_hampel (bool, default False) — enable/disable the filter
    • hampel_window (int, default 5) — window size for the filter
    • hampel_t (float, default 3) — threshold multiplier for outlier detection
  • Updated docstrings for all affected functions
  • Added unit test test_hampel_filter_removes_isolated_outlier
  • Added Hampel filter checks inside check_h12_gwss and check_h12_gwss_multi

Functions Updated

  • h12_gwss()
  • plot_h12_gwss_track()
  • plot_h12_gwss()
  • plot_h12_gwss_multi_overlay_track()
  • plot_h12_gwss_multi_overlay()
  • plot_h12_gwss_multi_panel()

Testing

All 14 h12 tests pass locally.

@Tanisha127
Copy link
Copy Markdown
Contributor Author

Hi @alimanfoo and @jonbrenas

This PR adds optional Hampel filter support to the h12_gwss() function and related plotting functions to help smooth isolated outliers. All 14 H12 tests pass locally, and all CI checks are green.
Please take a look when convenient? Happy to address any feedback.

Thanks!

@Tanisha127
Copy link
Copy Markdown
Contributor Author

Hi @jonbrenas ,
All checks are now passing for this PR. Could you please review it when convenient?
Happy to make any changes if needed.
Thank you!

Copy link
Copy Markdown
Collaborator

@jonbrenas jonbrenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Tanisha127. Can you move the new parameters to the correct location?

@Tanisha127 Tanisha127 force-pushed the feature/hampel-filter-h12 branch from ae8b2b9 to d0d6293 Compare March 8, 2026 10:32
@Tanisha127 Tanisha127 force-pushed the feature/hampel-filter-h12 branch from 16c02b6 to 8a6c4f0 Compare March 8, 2026 10:35
@Tanisha127 Tanisha127 requested a review from jonbrenas March 8, 2026 11:17
@Tanisha127
Copy link
Copy Markdown
Contributor Author

Hi @jonbrenas, I've addressed your feedback — the hampel parameters have been moved to the correct location (before chunks and inline_array) in all affected functions. All 17 tests are passing and all 8 CI checks are green. Please take a look when convenient!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding Hampel filter support to H12 functions

2 participants