From 0e5711197036f091ab9c7afc6ced57ac19500dd2 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sat, 13 Apr 2024 16:01:36 -0600 Subject: [PATCH 1/4] Added `ctis.instruments.Instrument` class. --- ctis/__init__.py | 6 +++ ctis/instruments/__init__.py | 9 ++++ ctis/instruments/_instruments.py | 75 +++++++++++++++++++++++++++ ctis/instruments/_instruments_test.py | 30 +++++++++++ 4 files changed, 120 insertions(+) create mode 100644 ctis/instruments/__init__.py create mode 100644 ctis/instruments/_instruments.py create mode 100644 ctis/instruments/_instruments_test.py diff --git a/ctis/__init__.py b/ctis/__init__.py index 41d44a5..b8c9e63 100644 --- a/ctis/__init__.py +++ b/ctis/__init__.py @@ -2,3 +2,9 @@ A package for inverting imagery captured by a computed tomography imaging spectrograph. """ + +from . import instruments + +__all__ = [ + "instruments", +] diff --git a/ctis/instruments/__init__.py b/ctis/instruments/__init__.py new file mode 100644 index 0000000..6995870 --- /dev/null +++ b/ctis/instruments/__init__.py @@ -0,0 +1,9 @@ +""" +Models of CTIS instruments used during inversions. +""" +from ._instruments import AbstractInstrument, Instrument + +__all__ = [ + "AbstractInstrument", + "Instrument" +] diff --git a/ctis/instruments/_instruments.py b/ctis/instruments/_instruments.py new file mode 100644 index 0000000..6df925d --- /dev/null +++ b/ctis/instruments/_instruments.py @@ -0,0 +1,75 @@ +from typing import Callable +import abc +import dataclasses +import named_arrays as na + +__all__ = [ + "AbstractInstrument", + "Instrument", +] + + +ProjectionCallable = Callable[ + [na.FunctionArray[na.SpectralPositionalVectorArray, na.ScalarArray]], + na.FunctionArray[na.SpectralPositionalVectorArray, na.ScalarArray], +] + + +@dataclasses.dataclass +class AbstractInstrument( + abc.ABC, +): + """ + An interface describing a CTIS instrument. + + This consists of a forward model + (which maps spectral/spatial points on the skyplane to positions on the detector) + and a deprojection model + (which maps positions on the detector to spectral/spatial points on the skyplane). + """ + + @property + @abc.abstractmethod + def project( + self, + ) -> ProjectionCallable: + """ + The forward model of the CTIS instrument. + Maps spectral and spatial coordinates on the field to coordinates + on the detector. + """ + + @property + @abc.abstractmethod + def deproject( + self, + ) -> ProjectionCallable: + """ + The deprojection model of the CTIS instrument. + Maps spectral and spatial coordinates on the detector to coordinates + on the field. + """ + + +@dataclasses.dataclass +class Instrument( + AbstractInstrument, +): + """ + A CTIS instrument where the forward and deprojection models are explicitly + provided. + """ + + project: ProjectionCallable = dataclasses.MISSING + """ + The forward model of the CTIS instrument. + Maps spectral and spatial coordinates on the field to coordinates + on the detector. + """ + + deproject: ProjectionCallable = dataclasses.MISSING + """ + The deprojection model of the CTIS instrument. + Maps spectral and spatial coordinates on the detector to coordinates + on the field. + """ diff --git a/ctis/instruments/_instruments_test.py b/ctis/instruments/_instruments_test.py new file mode 100644 index 0000000..f35717d --- /dev/null +++ b/ctis/instruments/_instruments_test.py @@ -0,0 +1,30 @@ +import pytest +import abc +import ctis + + +class AbstractTestAbstractInstrument( + abc.ABC, +): + def test_project(self, a: ctis.instruments.AbstractInstrument): + result = a.project + assert hasattr(result, "__call__") + + def test_deproject(self, a: ctis.instruments.AbstractInstrument): + result = a.deproject + assert hasattr(result, "__call__") + + +@pytest.mark.parametrize( + argnames="a", + argvalues=[ + ctis.instruments.Instrument( + project=lambda x: x, + deproject=lambda x: x, + ) + ] +) +class TestInstrument( + abc.ABC, +): + pass From 86c694ce71a0b235796bbd4f5343573ec7fc140c Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sat, 13 Apr 2024 16:10:50 -0600 Subject: [PATCH 2/4] Fixed test discovery. --- ctis/instruments/_instruments_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctis/instruments/_instruments_test.py b/ctis/instruments/_instruments_test.py index f35717d..7c6480d 100644 --- a/ctis/instruments/_instruments_test.py +++ b/ctis/instruments/_instruments_test.py @@ -22,9 +22,9 @@ def test_deproject(self, a: ctis.instruments.AbstractInstrument): project=lambda x: x, deproject=lambda x: x, ) - ] + ], ) class TestInstrument( - abc.ABC, + AbstractTestAbstractInstrument, ): pass From 73804d6fd6a7943ddfc7f48a914103686c22c8c6 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sat, 13 Apr 2024 16:18:35 -0600 Subject: [PATCH 3/4] Fixing black errors. --- ctis/instruments/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ctis/instruments/__init__.py b/ctis/instruments/__init__.py index 6995870..cd2312f 100644 --- a/ctis/instruments/__init__.py +++ b/ctis/instruments/__init__.py @@ -1,9 +1,10 @@ """ Models of CTIS instruments used during inversions. """ + from ._instruments import AbstractInstrument, Instrument __all__ = [ "AbstractInstrument", - "Instrument" + "Instrument", ] From 715be40069db1cbd442625bd91acd87b2b43f367 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Wed, 13 Nov 2024 12:18:58 -0700 Subject: [PATCH 4/4] old changes --- ctis/instruments/_instruments.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ctis/instruments/_instruments.py b/ctis/instruments/_instruments.py index 6df925d..7b059ad 100644 --- a/ctis/instruments/_instruments.py +++ b/ctis/instruments/_instruments.py @@ -23,31 +23,41 @@ class AbstractInstrument( An interface describing a CTIS instrument. This consists of a forward model - (which maps spectral/spatial points on the skyplane to positions on the detector) + (which maps the spectral radiance of a physical scene to counts on a detector) and a deprojection model - (which maps positions on the detector to spectral/spatial points on the skyplane). + (which maps detector counts to the spectral radiance of a physical scene). """ - @property @abc.abstractmethod def project( self, - ) -> ProjectionCallable: + scene: na.FunctionArray[na.SpectralPositionalVectorArray, na.AbstractScalar], + ) -> na.FunctionArray[na.SpectralPositionalVectorArray, na.AbstractScalar]: """ The forward model of the CTIS instrument. Maps spectral and spatial coordinates on the field to coordinates on the detector. + + Parameters + ---------- + scene + The spectral radiance of each spatial/spectral point in the scene. """ - @property @abc.abstractmethod def deproject( self, + projections: na.FunctionArray[na.SpectralPositionalVectorArray, na.AbstractScalar], ) -> ProjectionCallable: """ The deprojection model of the CTIS instrument. Maps spectral and spatial coordinates on the detector to coordinates on the field. + + Parameters + ---------- + projections + The counts gathered by each detector in the CTIS instrument. """