From 4b5ad3abfc0121aa7505ad33b6f12bb79bd7ea98 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Fri, 3 Apr 2026 08:36:47 -0600 Subject: [PATCH] Added `optika.systems.InterpolatedSystem` as an approximation to `SequentialSystem`. --- optika/systems/_interpolated.py | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 optika/systems/_interpolated.py diff --git a/optika/systems/_interpolated.py b/optika/systems/_interpolated.py new file mode 100644 index 0000000..fe7acdf --- /dev/null +++ b/optika/systems/_interpolated.py @@ -0,0 +1,73 @@ +from typing import Callable, Any +import abc +import dataclasses +import named_arrays as na +import optika +from . import AbstractSystem + +__all__ = [ + "AbstractInterpolatedSystem", +] + + +@dataclasses.dataclass(eq=False, repr=False) +class AbstractInterpolatedSystem( + AbstractSystem, +): + """ + Approximate an exact optical system using interpolation. + """ + + @property + @abc.abstractmethod + def distortion(self) -> Callable[ + [na.SpectralPositionalVectorArray], + na.Cartesian2dVectorArray, + ]: + """ + A distortion model which maps positions on the object plane to + positions on the detector. + """ + + def weights( + self, + coordinates: na.SpectralPositionalVectorArray, + axis_wavelength: str, + axis_field: tuple[str, str], + ) -> tuple[na.AbstractScalar, dict[str, int], dict[str, int]]: + """ + Compute the weights which map the overlap of each pixel on the object + plane to each pixel on the detector plane. + + Parameters + ---------- + coordinates + The vertices of each pixel on the object plane. + axis_wavelength + The logical axis + axis_field + The logical axes corresponding to changing field coordinate. + """ + + position = coordinates.position + + position_new = self.distortion(coordinates) + + result = na.regridding.weights( + coordinates_input=position, + coordinates_output=position_new, + axis_input=axis_field, + axis_output=axis_field, + method="conservative", + ) + + return result + + + def image( + self, + scene: na.FunctionArray[na.SpectralPositionalVectorArray, na.AbstractScalar], + **kwargs: Any, + ) -> na.SpectralPositionalVectorArray: + pass +