Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
281a1eb
Hack in 3D image plane
teutoburg May 8, 2025
a673a76
Hack in `DetectorList3D`
teutoburg May 8, 2025
0c0d1c6
Add warning if cube waves and fov wave disjoint
teutoburg May 8, 2025
78661a9
Remove obsolete `FovVolumeList.detector_limits`
teutoburg May 14, 2025
0b2bd8b
Add `DetectorList3D` to effects considered spectroscopic
teutoburg May 14, 2025
ed92094
Copy detector WCS to FOV cube in 3D mode, add WCS early
teutoburg May 14, 2025
e83f546
Generalise `overlay_image()` for 3D case
teutoburg May 14, 2025
5afe2d6
Generalise `add_imagehdu_to_imagehdu()` for 3D case
teutoburg May 14, 2025
c73991f
Enable `DetectorList3D` to shrink FOV in 3D
teutoburg May 14, 2025
a53e3b3
Fix spectral off-by-one error
teutoburg May 14, 2025
780666b
Override `detector_headers()` for 3D case
teutoburg May 15, 2025
3ff4a87
Add zeros_from_header utils function
teutoburg Feb 12, 2025
9cb1b17
Use `zeros_from_header()` for `Detector` to solve 3D case
teutoburg May 15, 2025
a5babe0
Skip sky WCS for 3D case
teutoburg May 15, 2025
167d90b
Also use `zeros_from_header()` in `ImagePlane`
teutoburg May 15, 2025
81f5558
Refactor `DetectorList3D` and parent class
teutoburg May 16, 2025
f98b1bf
Get rid of unused fov_grid method
teutoburg May 16, 2025
52060ee
Hack sky wcs into cube output
teutoburg May 16, 2025
9605c97
Add `FluxBinning3D` effect
teutoburg May 16, 2025
02f1e17
Add test for DetectorList3D
teutoburg May 18, 2025
a7c3119
Add simple ifu mode to basic instrument
teutoburg May 18, 2025
f33fe05
Add more tests
teutoburg May 18, 2025
903d885
More refactoring in `DetectorList`
teutoburg May 19, 2025
af071b3
Silly single item tuple needs a quacking comma -.-
teutoburg May 19, 2025
d362417
Merge branch 'main' into fh/simple-ifu
teutoburg May 19, 2025
f4df92b
Use BUNIT in ImagePlane
teutoburg May 19, 2025
25fd23d
Bumping version from 0.10.0a0 to 0.10.0a1
teutoburg May 19, 2025
0d20a9d
More BUNIT fixes
teutoburg May 19, 2025
7a0ba5d
Reduce kwargs
teutoburg May 21, 2025
7bd7500
Add psf log msg
teutoburg May 20, 2025
b13a82c
Make unit conversion more robust
teutoburg May 21, 2025
ee95138
Clarify pixel scale conversions
teutoburg May 21, 2025
6635d92
Prevent unexpected keyword argument, add logging
teutoburg May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ScopeSim"
version = "0.10.0a0"
version = "0.10.0a1"
description = "Generalised telescope observation simulator"
license = "GPL-3.0-or-later"
authors = ["Kieran Leschinski <[email protected]>"]
Expand Down
16 changes: 12 additions & 4 deletions scopesim/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from ..optics import ImagePlane
from ..optics.image_plane_utils import (add_imagehdu_to_imagehdu,
sky_wcs_from_det_wcs)
from ..utils import get_logger, from_currsys, stringify_dict
from ..utils import get_logger, from_currsys, stringify_dict, zeros_from_header


logger = get_logger(__name__)


class Detector:
def __init__(self, header, cmds=None, **kwargs):
image = np.zeros((header["NAXIS2"], header["NAXIS1"]))
self._hdu = ImageHDU(header=header, data=image)
self._hdu = ImageHDU(header=header, data=zeros_from_header(header))
self.meta = {}
self.meta.update(header)
self.meta.update(kwargs)
Expand All @@ -32,6 +31,14 @@ def extract_from(self, image_plane, spline_order=1, reset=True):
self._hdu = add_imagehdu_to_imagehdu(
image_plane.hdu, self.hdu, spline_order, wcs_suffix="D")

# HACK: to get sky WCS from image plane into detector...
if self._hdu.header["NAXIS"] == 3:
sky_wcs = WCS(image_plane.hdu)
# HACK: hardcode force back to celestial, this isn't great but will
# have to do for now
sky_wcs.wcs.ctype = ["RA---TAN", "DEC--TAN", "WAVE"]
self.header.update(sky_wcs.to_header())

def reset(self):
"""Reset internal HDU data to all-zeros-array."""
# The detector might have been converted to integers by the
Expand All @@ -45,7 +52,8 @@ def hdu(self):

pixel_scale = from_currsys("!INST.pixel_scale", self.cmds)
plate_scale = from_currsys("!INST.plate_scale", self.cmds)
if pixel_scale == 0 or plate_scale == 0:
if (pixel_scale == 0 or plate_scale == 0
or self._hdu.header["NAXIS"] == 3):
logger.warning("Could not create sky WCS.")
else:
sky_wcs, _ = sky_wcs_from_det_wcs(
Expand Down
1 change: 1 addition & 0 deletions scopesim/effects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .detector_list import *
from .electronic import *
from .shutter import *
from .binning_3d import *
from .obs_strategies import *
from .fits_headers import *

Expand Down
57 changes: 57 additions & 0 deletions scopesim/effects/binning_3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""Where else to put this?."""

from typing import ClassVar

from astropy import units as u

from .effects import Effect
from ..optics.fov import FieldOfView
from ..utils import get_logger, from_currsys, unit_includes_per_physical_type


logger = get_logger(__name__)


class FluxBinning3D(Effect):
"""Takes care of cube flux conversion in absence of a SpectralTraceList."""

z_order: ClassVar[tuple[int, ...]] = (690,)

def apply_to(self, fov, **kwargs):
"""See parent docstring."""
if not isinstance(fov, FieldOfView):
return fov

Check warning on line 24 in scopesim/effects/binning_3d.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/binning_3d.py#L24

Added line #L24 was not covered by tests

if fov.hdu is None or fov.hdu.header["NAXIS"] != 3:
logger.error("Cannot apply cube flux binning.")
return fov

Check warning on line 28 in scopesim/effects/binning_3d.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/binning_3d.py#L27-L28

Added lines #L27 - L28 were not covered by tests

bunit = u.Unit(fov.hdu.header["BUNIT"].lower())
pixel_area = fov.pixel_area << u.arcsec**2

# Spatial binning
if unit_includes_per_physical_type(bunit, "solid angle"):
fov.hdu.data *= pixel_area.value
bunit *= pixel_area.unit
else:
logger.warning("Cube is already binned spatially.")

Check warning on line 38 in scopesim/effects/binning_3d.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/binning_3d.py#L38

Added line #L38 was not covered by tests

# Spectral binning
if unit_includes_per_physical_type(bunit, "length"):
fov.hdu.data *= self.dwave.value
bunit *= self.dwave.unit
else:
logger.warning("Cube is already binned spectrally.")

Check warning on line 45 in scopesim/effects/binning_3d.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/binning_3d.py#L45

Added line #L45 was not covered by tests

fov.hdu.header["BUNIT"] = bunit.to_string("fits")

# This is done in SpectralTraceList as well, idk...
fov.cube = fov.hdu
return fov

@property
def dwave(self) -> u.Quantity[u.um]:
# TODO: turn into class attribute once cmds lookup works...
dwave = from_currsys("!SIM.spectral.spectral_bin_width", self.cmds)
return dwave << u.um
Loading