-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix METIS IFU mode #391
base: main
Are you sure you want to change the base?
Fix METIS IFU mode #391
Changes from all commits
214446b
e6dd25c
a1475b7
d44ed39
cdd1a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"""SpectralTraceList and SpectralTrace for the METIS LM spectrograph.""" | ||
import copy | ||
|
||
import warnings | ||
|
||
import numpy as np | ||
|
@@ -13,9 +13,9 @@ | |
|
||
from ..utils import from_currsys, find_file, quantify, get_logger | ||
from .spectral_trace_list import SpectralTraceList | ||
from .spectral_trace_list_utils import SpectralTrace | ||
from .spectral_trace_list_utils import Transform2D | ||
from .spectral_trace_list_utils import make_image_interpolations | ||
from .spectral_trace_list_utils import (SpectralTrace, Transform2D, | ||
make_image_interpolations, | ||
SpecTraceError) | ||
from .apertures import ApertureMask | ||
from .ter_curves import TERCurve | ||
from ..base_classes import FieldOfViewBase, FOVSetupBase | ||
|
@@ -138,7 +138,11 @@ | |
slicefov.cube = fits.ImageHDU(header=slicewcs.to_header(), | ||
data=slicecube) | ||
# slicefov.cube.writeto(f"slicefov_{sptid}.fits", overwrite=True) | ||
slicefov.hdu = spt.map_spectra_to_focal_plane(slicefov) | ||
try: | ||
slicefov.hdu = spt.map_spectra_to_focal_plane(slicefov) | ||
except SpecTraceError as err: | ||
logger.warning(err) | ||
continue | ||
|
||
sxmin = slicefov.hdu.header["XMIN"] | ||
sxmax = slicefov.hdu.header["XMAX"] | ||
|
@@ -159,11 +163,12 @@ | |
self.meta["angle"] = tempres["Angle"] | ||
|
||
spec_traces = {} | ||
for sli in np.arange(self.meta["nslice"]): | ||
slicename = "Slice " + str(sli + 1) | ||
for sli in range(self.meta["nslice"]): | ||
slicename = f"Slice {sli + 1}" | ||
spec_traces[slicename] = MetisLMSSpectralTrace( | ||
self._file, | ||
spslice=sli, params=self.meta) | ||
spslice=sli, | ||
params=self.meta) | ||
|
||
self.spectral_traces = spec_traces | ||
|
||
|
@@ -223,10 +228,13 @@ | |
for i, spt in enumerate(self.spectral_traces.values()): | ||
spt.wave_min = wave_min | ||
spt.wave_max = wave_max | ||
result = spt.rectify(hdulist, interps=interps, | ||
wave_min=wave_min, wave_max=wave_max, | ||
xi_min=xi_min, xi_max=xi_max, | ||
bin_width=dwave) | ||
try: | ||
result = spt.rectify(hdulist, interps=interps, | ||
wave_min=wave_min, wave_max=wave_max, | ||
xi_min=xi_min, xi_max=xi_max, | ||
bin_width=dwave) | ||
except SpecTraceError as err: | ||
logger.warning(err) | ||
cube[:, i, :] = result.data.T | ||
|
||
# FIXME: use wcs object here | ||
|
@@ -280,7 +288,7 @@ | |
super().__init__(polyhdu, **params) | ||
|
||
self._file = hdulist | ||
self.meta["description"] = "Slice " + str(spslice + 1) | ||
self.meta["description"] = f"Slice {spslice + 1}" | ||
self.meta["trace_id"] = f"Slice {spslice + 1}" | ||
self.meta.update(params) | ||
# Provisional: | ||
|
@@ -307,8 +315,7 @@ | |
y_min = aperture["bottom"] | ||
y_max = aperture["top"] | ||
|
||
filename_det_layout = from_currsys("!DET.layout.file_name", cmds=self.cmds) | ||
layout = ioascii.read(find_file(filename_det_layout)) | ||
layout = ioascii.read(find_file(self.cmds["!DET.layout.filename"])) | ||
det_lims = {} | ||
xhw = layout["pixel_size"] * layout["x_size"] / 2 | ||
yhw = layout["pixel_size"] * layout["y_size"] / 2 | ||
|
@@ -562,13 +569,10 @@ | |
} | ||
|
||
def __init__(self, **kwargs): | ||
# TODO: Refactor these _class_params? | ||
self.meta = copy.copy(self._class_params) | ||
assert "grat_spacing" in self.meta, "grat_spacing is missing from self.meta 1" | ||
super().__init__(**kwargs) | ||
assert "grat_spacing" in self.meta, "grat_spacing is missing from self.meta 2" | ||
self.meta = self._class_params | ||
self.meta.update(kwargs) | ||
Comment on lines
+572
to
+573
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this from scopesim.effects.metis_lms_trace_list import MetisLMSEfficiency
eff1 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits")
print(f"{eff1.meta['eff_max']=}")
eff2 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits", eff_max=42)
print(f"{eff2.meta['eff_max']=}")
print(f"{eff1.meta['eff_max']=}")
eff3 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits")
print(f"{eff3.meta['eff_max']=}") will print
is that intentional? |
||
|
||
filename = find_file(self.meta["filename"]) | ||
filename = find_file(from_currsys(self.meta["filename"], kwargs.get("cmds"))) | ||
wcal = fits.getdata(filename, extname="WCAL") | ||
if "wavelen" in kwargs: | ||
wavelen = from_currsys(kwargs["wavelen"], kwargs.get("cmds")) | ||
|
@@ -580,6 +584,13 @@ | |
|
||
lam, efficiency = self.make_ter_curve(wcal, wavelen) | ||
|
||
# HACK: Somehow we end up with duplicate keywords here. This hack | ||
# should not be necessary at all! Investigate what's really | ||
# going on... | ||
Comment on lines
+587
to
+589
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe because you removed the Just guessing. And since I'm already started with 'single comments', I'll keep doing that :-). |
||
self.meta.pop("wavelength", None) | ||
self.meta.pop("transmission", None) | ||
self.meta.pop("emissivity", None) | ||
|
||
super().__init__(wavelength=lam, | ||
transmission=efficiency, | ||
emissivity=np.zeros_like(lam), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah here you introduced the bug that you then fixed in AstarVienna/irdb#165 . We can merge that one if we also merge this one. Let me review the rest of this PR first though