Skip to content

Add level-weighted module#5

Merged
derollins merged 6 commits intomainfrom
add_level_weighted
Nov 4, 2025
Merged

Add level-weighted module#5
derollins merged 6 commits intomainfrom
add_level_weighted

Conversation

@derollins
Copy link
Owner

This PR introduces a new module, level_weighted, providing weighted-region AFM image flattening and background leveling routines. The module is a Python port of the Nanolocz-lib MATLAB level_weighted.m used in the NanoLocz workflow and implements region-wise polynomial and median-based background estimation.

https://github.com/George-R-Heath/NanoLocz-Matlab-Library/blob/main/NanoLocz-lib/level_weighted.m

Supported levelling methods include:

  • plane : Region-weighted polynomial plane subtraction
  • line : Region-weighted row/column polynomial levelling
  • med_line : Region-weighted row-wise median line subtraction
  • med_line_y : Region-weighted column-wise median line subtraction
  • smed_line : Region-weighted smoothed median line subtraction

The module supports masked images, handling multiple regions with weighted aggregation, and is compatible with both 2D images and 3D stacks.

- Python port of NanoLocz level_weighted.m for AFM images and stacks
- Supports region-weighted methods: 'plane', 'line', 'med_line', 'med_line_y', 'smed_line'
- Implements polynomial and median-based background subtraction with per-region weighting
- Handles 2D images and 3D stacks
- Includes robust handling of masks, small regions, and degenerate cases
- Preserves MATLAB-like centering and scaling for polynomial fits
- Compatible with NumPy/SciPy ecosystem; ready for integration into NanoLocz workflow

Also add typing to satisfy mypy.
@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 96.22093% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.64%. Comparing base (8e3f019) to head (a410ff8).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/pnanolocz_lib/level_weighted.py 97.79% 7 Missing ⚠️
src/pnanolocz_lib/__init__.py 16.66% 5 Missing ⚠️
src/pnanolocz_lib/level.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
+ Coverage   96.48%   96.64%   +0.16%     
==========================================
  Files           4        5       +1     
  Lines         455      776     +321     
==========================================
+ Hits          439      750     +311     
- Misses         16       26      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@derollins derollins merged commit 603c739 into main Nov 4, 2025
11 of 12 checks passed
@derollins derollins deleted the add_level_weighted branch November 4, 2025 23:04
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.

1 participant