Skip to content
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
21 changes: 18 additions & 3 deletions src/pnanolocz/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
row- or column-wise artefacts commonly observed in AFM topographic data.

All public leveling functions accept an *exclusion mask* (same convention as
``pnanolocz_lib.thresholder``): ``True`` = excluded, ``False`` = valid.
``pnanolocz.thresholder``): ``True`` = excluded, ``False`` = valid.
Excluded pixels are omitted from fitting using MATLAB-style NaN-outside
semantics (i.e., excluded pixels behave like NaN during fitting) but are
preserved in the output array.
Expand Down Expand Up @@ -63,10 +63,10 @@

Examples
--------
>>> from pnanolocz_lib.level import level
>>> from pnanolocz.level import level
>>> leveled_stack = apply_level(stack, polyx=2, polyy=2, method="plane")

>>> from pnanolocz_lib.level import level_plane
>>> from pnanolocz.level import level_plane
>>> flattened = level_plane(img, mask=None, polyx=2, polyy=2)

Authors
Expand Down Expand Up @@ -845,6 +845,10 @@ def apply_level(
operations (e.g. ``where(valid, value, nan)``) during fitting.
- Method-specific MATLAB parity notes (e.g., stage gating such as `polyy > 0`
in ``"line"``) are documented in the corresponding function docstrings.

Version
-------
0.1.0
"""
img = np.asarray(img)
is_stack = img.ndim == 3
Expand Down Expand Up @@ -921,6 +925,9 @@ def apply_level(
return np.asarray(result) if is_stack else np.asarray(result[0])


apply_level.__version__ = "0.1.0" # type: ignore[attr-defined]


def get_background(
img: np.ndarray[Any, np.dtype[np.float64]],
polyx: int,
Expand Down Expand Up @@ -982,6 +989,10 @@ def get_background(
certain parameter values) are inherited here.
- Excluded pixels are preserved in the output arrays; masking primarily affects
which pixels contribute to fitted estimates.

Version
-------
0.1.0
"""
img = np.asarray(img)
is_stack = img.ndim == 3
Expand Down Expand Up @@ -1028,6 +1039,9 @@ def get_background(
return np.asarray(result) if is_stack else np.asarray(result[0])


get_background.__version__ = "0.1.0" # type: ignore[attr-defined]


__all__ = [
"apply_level",
"level_plane",
Expand All @@ -1037,4 +1051,5 @@ def get_background(
"level_smed_line",
"level_mean_plane",
"level_log_y",
"get_background",
]
7 changes: 7 additions & 0 deletions src/pnanolocz/level_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,10 @@ def apply_level_auto(
``_compute_gauss_limits`` when a thresholder step declares ``args=['gauss_*']``.
- The Gaussian-derived histogram bounds are calculated for each frame rather
than globally across the stack, diverging from MATLAB behavior.

Version
-------
0.1.0
"""
img_stack = np.asarray(img_stack)
if img_stack.ndim == 2:
Expand Down Expand Up @@ -1041,4 +1045,7 @@ def apply_level_auto(
return np.asarray(result[0]) if was_2d else np.asarray(result)


apply_level_auto.__version__ = "0.1.0" # type: ignore[attr-defined]


__all__ = ["apply_level_auto", "ROUTINES"]
11 changes: 9 additions & 2 deletions src/pnanolocz/level_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
and non-uniform masking effects.

All public leveling functions accept an *exclusion mask* (same convention as
``pnanolocz_lib.thresholder``): ``True`` = excluded, ``False`` = valid. Excluded
``pnanolocz.thresholder``): ``True`` = excluded, ``False`` = valid. Excluded
pixels are omitted from region formation and fitting using MATLAB-style NaN-outside
semantics (i.e., excluded pixels behave like NaN during fitting) but are
preserved in the output array.
Expand Down Expand Up @@ -55,7 +55,7 @@

Examples
--------
>>> from pnanolocz_lib.level_weighted import apply_level_weighted
>>> from pnanolocz.level_weighted import apply_level_weighted
>>> leveled = apply_level_weighted(img, polyx=2, polyy=1, method='plane', mask=mask)

Authors
Expand Down Expand Up @@ -849,6 +849,10 @@ def apply_level_weighted(
``bwconncomp(mask, 8)``.
- A MATLAB-style minimum region area is enforced via:
``min_area = max(1, floor(0.01 * H * W))``.

Version
-------
0.1.0
"""
arr = np.asarray(img, dtype=np.float64)
is_stack = arr.ndim == 3
Expand Down Expand Up @@ -897,6 +901,9 @@ def apply_level_weighted(
return np.asarray(stacked if is_stack else stacked[0])


apply_level_weighted.__version__ = "0.1.0" # type: ignore[attr-defined]


__all__ = [
"apply_level_weighted",
"level_weighted_plane",
Expand Down
7 changes: 7 additions & 0 deletions src/pnanolocz/thresholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ def apply_thresholder(
>>> # Otsu on a stack, then invert to obtain a validity mask (True = valid)
>>> excl = apply_thresholder(stack, method="otsu")
>>> valid = np.logical_not(excl)

Version
-------
0.1.0
"""
method = method.lower()
if method not in _METHOD_MAP:
Expand Down Expand Up @@ -1069,6 +1073,9 @@ def apply_thresholder(
return result


apply_thresholder.__version__ = "0.1.0" # type: ignore[attr-defined]


__all__ = [
"apply_thresholder",
"selection",
Expand Down