Skip to content

Commit 5dc29b8

Browse files
authored
Added axis_channel and num_channel properties to AbstractInstrument. (#8)
1 parent 93f25e2 commit 5dc29b8

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

ctis/instruments/_instruments.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ def coordinates_sensor(self) -> na.AbstractSpectralPositionalVectorArray:
106106
A grid of wavelength and position coordinates on the detector plane.
107107
"""
108108

109+
@property
110+
@abc.abstractmethod
111+
def axis_channel(self) -> str | tuple[str, ...]:
112+
"""
113+
The logical axis or axes of this instrument corresponding to
114+
the different dispersion magnitudes and angles.
115+
"""
116+
109117
@property
110118
@abc.abstractmethod
111119
def axis_wavelength(self) -> str:
@@ -130,6 +138,14 @@ def axis_sensor_xy(self) -> tuple[str, str]:
130138
changing position coordinate.
131139
"""
132140

141+
@property
142+
@abc.abstractmethod
143+
def num_channel(self) -> int:
144+
"""
145+
The total number of dispersion magnitudes/angles observed by this
146+
instrument.
147+
"""
148+
133149

134150
@dataclasses.dataclass
135151
class AbstractLinearInstrument(
@@ -160,6 +176,21 @@ def weights_transpose(
160176
skyplane.
161177
"""
162178

179+
@property
180+
def num_channel(self) -> int:
181+
182+
shape = self.weights[0].shape
183+
184+
axis_channel = self.axis_channel
185+
if isinstance(axis_channel, str):
186+
axis_channel = (axis_channel,)
187+
188+
num_channels = 1
189+
for ax in axis_channel:
190+
num_channels = num_channels * shape[ax]
191+
192+
return num_channels
193+
163194
@property
164195
def _volume_scene(self) -> na.AbstractScalar:
165196
"""
@@ -338,6 +369,12 @@ class IdealInstrument(
338369
A grid of wavelength and position coordinates on the sensor plane.
339370
"""
340371

372+
axis_channel: str | tuple[str, ...] = dataclasses.MISSING
373+
"""
374+
The logical axis or axes of this instrument corresponding to
375+
the different dispersion magnitudes and angles.
376+
"""
377+
341378
axis_wavelength: str = dataclasses.MISSING
342379
"""
343380
The logical axis of :attr:`coordinates_scene` and :attr:`coordinates_sensor`

ctis/instruments/_instruments_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
timedelta_exposure=10 * u.s,
4646
plate_scale=2 * u.arcsec / u.pix,
4747
dispersion=dispersion,
48-
angle=0 * u.deg,
48+
angle=na.linspace(0, 360, axis="channel", num=3, endpoint=False),
4949
wavelength_ref=wavelength_rest,
5050
position_ref=32 * u.pix,
5151
coordinates_scene=coordinates_scene,
5252
coordinates_sensor=coordinates_sensor,
53+
axis_channel="channel",
5354
axis_wavelength="wavelength",
5455
axis_scene_xy=("scene_x", "scene_y"),
5556
axis_sensor_xy=("sensor_x", "sensor_y"),
@@ -95,6 +96,14 @@ def test_backproject(
9596

9697
assert np.allclose(image.sum(), image_check.sum())
9798

99+
def test_num_channel(
100+
self,
101+
a: ctis.instruments.AbstractInstrument,
102+
):
103+
result = a.num_channel
104+
105+
assert isinstance(result, int)
106+
98107

99108
class AbstractTestAbstractLinearInstrument(
100109
AbstractTestAbstractInstrument,

docs/tutorials/ideal-instrument.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
" position_ref=32 * u.pix,\n",
307307
" coordinates_scene=coordinates_scene,\n",
308308
" coordinates_sensor=coordinates_sensor,\n",
309+
" axis_channel=\"channel\",\n",
309310
" axis_wavelength=\"wavelength\",\n",
310311
" axis_scene_xy=(\"scene_x\", \"scene_y\"),\n",
311312
" axis_sensor_xy=(\"sensor_x\", \"sensor_y\"),\n",

0 commit comments

Comments
 (0)