From 54330ddd2079bcfd9bec749e2123322e5f847aa5 Mon Sep 17 00:00:00 2001 From: Jakob van Santen Date: Tue, 19 Sep 2023 14:29:26 +0200 Subject: [PATCH] add stubs for glam_fit --- src/python/photospline.pyi | 36 +++++++++++++++++++++++++++++------- test/test_fit.py | 4 ++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/python/photospline.pyi b/src/python/photospline.pyi index b4294d8..5d44183 100644 --- a/src/python/photospline.pyi +++ b/src/python/photospline.pyi @@ -4,28 +4,50 @@ import numpy.typing as npt class SplineTable: coefficients: npt.NDArray[np.float32] - extents: tuple[tuple[float,float], ...] + extents: tuple[tuple[float, float], ...] knots: tuple[npt.NDArray[np.float32], ...] ndim: int order: tuple[int, ...] def __init__(self, path: str): ... - @classmethod - def stack(cls, tables: Sequence[SplineTable], coordinates: Sequence[float], stackOrder: int = 2) -> SplineTable: - """ - """ + def stack( + cls, + tables: Sequence[SplineTable], + coordinates: Sequence[float], + stackOrder: int = 2, + ) -> SplineTable: + """ """ ... - def aux_value(self, *args, **kwargs) -> Any: ... def convolve(self, *args, **kwargs) -> Any: ... def deriv(self, *args, **kwargs) -> Any: ... def evaluate(self, *args, **kwargs) -> Any: ... def evaluate_gradient(self, *args, **kwargs) -> Any: ... def evaluate_simple(self, *args, **kwargs) -> Any: ... + def grideval(self, *args, **kwargs) -> Any: ... def permute_dimensions(self, *args, **kwargs) -> Any: ... def search_centers(self, *args, **kwargs) -> Any: ... def write(self, *args, **kwargs) -> Any: ... def __call__(self, *args, **kwargs) -> Any: ... -def bspline(*args, **kwargs) -> Any: ... +class ndsparse: + def __init__(self, rows: int, ndim: int) -> None: ... + @classmethod + def from_data( + cls, values: npt.ArrayLike, weights: None | npt.ArrayLike = None + ) -> tuple[ndsparse, ndsparse]: ... + def insert(self, value: float, indices: Sequence[int]) -> None: ... + +def bspline(knots: npt.ArrayLike, x: float, index: int, order: int) -> float: ... +def glam_fit( + data: ndsparse, + weights: ndsparse, + coordinates: Sequence[Sequence[float]], + knots: Sequence[Sequence[float]], + order: Sequence[int], + smoothing: Sequence[float], + penaltyOrder: Sequence[int], + monodim: None | int = None, + verbose: int = 1, +) -> SplineTable: ... diff --git a/test/test_fit.py b/test/test_fit.py index ec28b88..0bf606f 100755 --- a/test/test_fit.py +++ b/test/test_fit.py @@ -27,8 +27,8 @@ def pad_knots(knots, order=2): order = [2,2,3] smooth = 1 -data, w = photospline.ndsparse.from_data(z, w) -spline = photospline.glam_fit(data, w, centers, knots, order, [smooth]*3, [2]*3, monodim=2, verbose=False) +data, ws = photospline.ndsparse.from_data(z, w) +spline = photospline.glam_fit(data, ws, centers, knots, order, [smooth]*3, [2]*3, monodim=2, verbose=False) y = spline.grideval(centers) residual = ((z-y)**2).sum()