From da97b7dfc255aab6c97355aae33550e36021dbad Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Tue, 22 Apr 2025 23:46:38 -0600 Subject: [PATCH 1/2] Added the `ctis.regridding` module which can resample spatial-spectral cubes. --- ctis/__init__.py | 2 ++ ctis/regridding/__init__.py | 9 ++++++++ ctis/regridding/_weights.py | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 ctis/regridding/__init__.py create mode 100644 ctis/regridding/_weights.py diff --git a/ctis/__init__.py b/ctis/__init__.py index 8107466..53a6aa8 100644 --- a/ctis/__init__.py +++ b/ctis/__init__.py @@ -3,8 +3,10 @@ spectrograph. """ +from . import regridding from . import scenes __all__ = [ + "regridding", "scenes", ] diff --git a/ctis/regridding/__init__.py b/ctis/regridding/__init__.py new file mode 100644 index 0000000..b931a3b --- /dev/null +++ b/ctis/regridding/__init__.py @@ -0,0 +1,9 @@ +""" +Resampling routines tailored to work with CTIS observations. +""" + +from ._weights import weights + +__all__ = [ + "weights", +] diff --git a/ctis/regridding/_weights.py b/ctis/regridding/_weights.py new file mode 100644 index 0000000..60b44a5 --- /dev/null +++ b/ctis/regridding/_weights.py @@ -0,0 +1,44 @@ +from typing import Sequence +import named_arrays as na + +__all__ = [ + + "weights" +] + + +def weights( + wavelength: na.AbstractScalar, + position_input: na.AbstractCartesian2dVectorArray, + position_output: na.AbstractCartesian2dVectorArray, + axis_wavelength: str, + axis_position_input: tuple[str, str], + axis_position_output: tuple[str, str], +) -> tuple[na.AbstractScalar, dict[str, int], dict[str, int]]: + """ + A version of :func:`named_arrays.weights` targeted for use with + the spatial-spectral cubes used in this package. + + Parameters + ---------- + wavelength + position_input + position_output + axis_wavelength + axis_position_input + axis_position_output + """ + + wavelength = wavelength.cell_centers(axis_wavelength) + position_input = position_input.cell_centers(axis_wavelength) + position_output = position_output.cell_centers(axis_wavelength) + + _weights, shape_input, shape_output = na.regridding.weights( + coordinates_input=position_input, + coordinates_output=position_output, + axis_input=axis_position_input, + axis_output=axis_position_output, + method="conservative", + ) + + From 16c18f7ad385645ea09438e34e6c31d6778d7df5 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Wed, 23 Apr 2025 08:09:54 -0600 Subject: [PATCH 2/2] prototypes --- ctis/regridding/_weights.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ctis/regridding/_weights.py b/ctis/regridding/_weights.py index 60b44a5..78c6137 100644 --- a/ctis/regridding/_weights.py +++ b/ctis/regridding/_weights.py @@ -1,8 +1,7 @@ -from typing import Sequence +import numpy as np import named_arrays as na __all__ = [ - "weights" ] @@ -16,8 +15,8 @@ def weights( axis_position_output: tuple[str, str], ) -> tuple[na.AbstractScalar, dict[str, int], dict[str, int]]: """ - A version of :func:`named_arrays.weights` targeted for use with - the spatial-spectral cubes used in this package. + A version of :func:`named_arrays.regridding.weights` tailored for use with + the spatial-spectral cubes in this package. Parameters ---------- @@ -33,7 +32,7 @@ def weights( position_input = position_input.cell_centers(axis_wavelength) position_output = position_output.cell_centers(axis_wavelength) - _weights, shape_input, shape_output = na.regridding.weights( + _weights_2d, shape_input, shape_output = na.regridding.weights( coordinates_input=position_input, coordinates_output=position_output, axis_input=axis_position_input, @@ -42,3 +41,21 @@ def weights( ) +def _weights_3d( + weights_2d: na.ScalarArray, + shape_inputs: dict[str, int], + shape_outputs: dict[str, int], + axis_wavelength: str, +) -> tuple[na.AbstractScalar, dict[str, int], dict[str, int]]: + + pass + + +def weights_3d_numpy( + weights_2d: np.ndarray, + shape_inputs: tuple[int, ...], + shape_outputs: tuple[int, ...], + axis_wavelength: int, +) -> tuple[np.ndarray, tuple[int, ...], tuple[int, ...]]: + + pass