deduplication pass
This commit is contained in:
@@ -2,16 +2,7 @@ from __future__ import annotations
|
||||
import numpy as np
|
||||
from backend.node_registry import register_node
|
||||
from backend.data_types import DataField
|
||||
|
||||
|
||||
def _normalize_mask(mask: np.ndarray | None, shape: tuple[int, int]) -> np.ndarray | None:
|
||||
if mask is None:
|
||||
return None
|
||||
|
||||
mask_array = np.asarray(mask)
|
||||
if mask_array.shape[:2] != shape:
|
||||
raise ValueError(f"Mask shape {mask_array.shape} does not match field shape {shape}.")
|
||||
return mask_array > 127
|
||||
from backend.nodes.helpers import normalize_mask, apply_masking
|
||||
|
||||
|
||||
def _fit_plane(
|
||||
@@ -24,14 +15,7 @@ def _fit_plane(
|
||||
y = np.linspace(0.0, 1.0, yres)
|
||||
xx, yy = np.meshgrid(x, y)
|
||||
|
||||
if mask is None or masking == "ignore":
|
||||
valid = np.ones(data.shape, dtype=bool)
|
||||
elif masking == "include":
|
||||
valid = mask
|
||||
elif masking == "exclude":
|
||||
valid = ~mask
|
||||
else:
|
||||
raise ValueError(f"Unknown masking mode: {masking}")
|
||||
valid = apply_masking(data, mask, masking)
|
||||
|
||||
if np.count_nonzero(valid) < 3:
|
||||
raise ValueError("Plane Level requires at least three usable pixels for fitting.")
|
||||
@@ -78,7 +62,7 @@ class PlaneLevelField:
|
||||
mask: np.ndarray | None = None,
|
||||
) -> tuple:
|
||||
data = field.data.copy()
|
||||
mask_array = _normalize_mask(mask, data.shape)
|
||||
mask_array = normalize_mask(mask, data.shape)
|
||||
pa, pbx, pby, xx, yy = _fit_plane(data, mask_array, masking)
|
||||
|
||||
plane = (pa + pbx * xx + pby * yy)
|
||||
|
||||
Reference in New Issue
Block a user