From 5cbd0c9d68855c68845ef9f831cdafd33069c0c1 Mon Sep 17 00:00:00 2001 From: Hugo Buddelmeijer Date: Tue, 23 Aug 2022 13:21:13 +0200 Subject: [PATCH 1/9] xfail test that is currently broken on CI See https://github.com/AstarVienna/ScopeSim/issues/160 --- .../tests/test_calibration/test_micado/test_viking_fields.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py b/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py index e038e39..2aa69cd 100644 --- a/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py +++ b/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py @@ -70,6 +70,7 @@ def test_load_viking_field(self): assert len(viking_src.fields) == len(gals) + len(stars) +@pytest.mark.xfail(reason="load_example_optical_train is broken on CI, see https://github.com/AstarVienna/ScopeSim/issues/160") class TestWithScopeSim: def test_runs_through_scopesim_basic_instrument(self): # configure basic_instrument to MICADO specs From 23dd41edb3a2017caa87bf0b03c331aa7a3635ff Mon Sep 17 00:00:00 2001 From: Hugo Buddelmeijer Date: Tue, 23 Aug 2022 13:32:18 +0200 Subject: [PATCH 2/9] Move micado directory to top level This should help with making SourceDescriptionFitsKeywords from ScopeSim work, because the full package paths are now shorter. Not all micado sources are (always) calibration sources, so they should not be in the calibration directory anyway. --- scopesim_templates/__init__.py | 4 ++-- scopesim_templates/calibration/__init__.py | 1 - scopesim_templates/{calibration => }/micado/__init__.py | 0 scopesim_templates/{calibration => }/micado/cluster.py | 0 scopesim_templates/{calibration => }/micado/darkness.py | 0 scopesim_templates/{calibration => }/micado/flatlamp.py | 0 .../{calibration => }/micado/viking_fields/__init__.py | 0 .../{calibration => }/micado/viking_fields/cat_illum.dat | 0 .../micado/viking_fields/cat_science.dat | 0 .../micado/viking_fields/cat_stdstar.dat | 0 .../{calibration => }/micado/viking_fields/faintgal_1.dat | 0 .../{calibration => }/micado/viking_fields/faintgal_2.dat | 0 .../{calibration => }/micado/viking_fields/faintgal_3.dat | 0 .../micado/viking_fields/field_illum.eps | 0 .../micado/viking_fields/field_science.eps | 0 .../micado/viking_fields/field_stdstar.eps | 0 .../{calibration => }/micado/viking_fields/readme.rst | 0 .../micado/viking_fields/viking_fields.py | 8 ++++---- .../tests/{test_calibration => }/test_micado/__init__.py | 0 .../{test_calibration => }/test_micado/test_darkness.py | 2 +- .../{test_calibration => }/test_micado/test_flatlamp.py | 2 +- .../test_micado/test_viking_fields.py | 2 +- 22 files changed, 9 insertions(+), 10 deletions(-) rename scopesim_templates/{calibration => }/micado/__init__.py (100%) rename scopesim_templates/{calibration => }/micado/cluster.py (100%) rename scopesim_templates/{calibration => }/micado/darkness.py (100%) rename scopesim_templates/{calibration => }/micado/flatlamp.py (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/__init__.py (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/cat_illum.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/cat_science.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/cat_stdstar.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/faintgal_1.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/faintgal_2.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/faintgal_3.dat (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/field_illum.eps (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/field_science.eps (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/field_stdstar.eps (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/readme.rst (100%) rename scopesim_templates/{calibration => }/micado/viking_fields/viking_fields.py (97%) rename scopesim_templates/tests/{test_calibration => }/test_micado/__init__.py (100%) rename scopesim_templates/tests/{test_calibration => }/test_micado/test_darkness.py (89%) rename scopesim_templates/tests/{test_calibration => }/test_micado/test_flatlamp.py (88%) rename scopesim_templates/tests/{test_calibration => }/test_micado/test_viking_fields.py (97%) diff --git a/scopesim_templates/__init__.py b/scopesim_templates/__init__.py index 80a66b0..a736fba 100644 --- a/scopesim_templates/__init__.py +++ b/scopesim_templates/__init__.py @@ -14,5 +14,5 @@ from .stellar.clusters import cluster from .extragalactic.galaxies import galaxy, galaxy3d, elliptical from .calibration.calibration import empty_sky -from .calibration.micado import darkness, flatlamp -from .calibration import micado \ No newline at end of file +from .micado import darkness, flatlamp +from . import micado diff --git a/scopesim_templates/calibration/__init__.py b/scopesim_templates/calibration/__init__.py index 7a4b1a1..ab1f04c 100644 --- a/scopesim_templates/calibration/__init__.py +++ b/scopesim_templates/calibration/__init__.py @@ -1,2 +1 @@ from .calibration import * -from . import micado diff --git a/scopesim_templates/calibration/micado/__init__.py b/scopesim_templates/micado/__init__.py similarity index 100% rename from scopesim_templates/calibration/micado/__init__.py rename to scopesim_templates/micado/__init__.py diff --git a/scopesim_templates/calibration/micado/cluster.py b/scopesim_templates/micado/cluster.py similarity index 100% rename from scopesim_templates/calibration/micado/cluster.py rename to scopesim_templates/micado/cluster.py diff --git a/scopesim_templates/calibration/micado/darkness.py b/scopesim_templates/micado/darkness.py similarity index 100% rename from scopesim_templates/calibration/micado/darkness.py rename to scopesim_templates/micado/darkness.py diff --git a/scopesim_templates/calibration/micado/flatlamp.py b/scopesim_templates/micado/flatlamp.py similarity index 100% rename from scopesim_templates/calibration/micado/flatlamp.py rename to scopesim_templates/micado/flatlamp.py diff --git a/scopesim_templates/calibration/micado/viking_fields/__init__.py b/scopesim_templates/micado/viking_fields/__init__.py similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/__init__.py rename to scopesim_templates/micado/viking_fields/__init__.py diff --git a/scopesim_templates/calibration/micado/viking_fields/cat_illum.dat b/scopesim_templates/micado/viking_fields/cat_illum.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/cat_illum.dat rename to scopesim_templates/micado/viking_fields/cat_illum.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/cat_science.dat b/scopesim_templates/micado/viking_fields/cat_science.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/cat_science.dat rename to scopesim_templates/micado/viking_fields/cat_science.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/cat_stdstar.dat b/scopesim_templates/micado/viking_fields/cat_stdstar.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/cat_stdstar.dat rename to scopesim_templates/micado/viking_fields/cat_stdstar.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/faintgal_1.dat b/scopesim_templates/micado/viking_fields/faintgal_1.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/faintgal_1.dat rename to scopesim_templates/micado/viking_fields/faintgal_1.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/faintgal_2.dat b/scopesim_templates/micado/viking_fields/faintgal_2.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/faintgal_2.dat rename to scopesim_templates/micado/viking_fields/faintgal_2.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/faintgal_3.dat b/scopesim_templates/micado/viking_fields/faintgal_3.dat similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/faintgal_3.dat rename to scopesim_templates/micado/viking_fields/faintgal_3.dat diff --git a/scopesim_templates/calibration/micado/viking_fields/field_illum.eps b/scopesim_templates/micado/viking_fields/field_illum.eps similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/field_illum.eps rename to scopesim_templates/micado/viking_fields/field_illum.eps diff --git a/scopesim_templates/calibration/micado/viking_fields/field_science.eps b/scopesim_templates/micado/viking_fields/field_science.eps similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/field_science.eps rename to scopesim_templates/micado/viking_fields/field_science.eps diff --git a/scopesim_templates/calibration/micado/viking_fields/field_stdstar.eps b/scopesim_templates/micado/viking_fields/field_stdstar.eps similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/field_stdstar.eps rename to scopesim_templates/micado/viking_fields/field_stdstar.eps diff --git a/scopesim_templates/calibration/micado/viking_fields/readme.rst b/scopesim_templates/micado/viking_fields/readme.rst similarity index 100% rename from scopesim_templates/calibration/micado/viking_fields/readme.rst rename to scopesim_templates/micado/viking_fields/readme.rst diff --git a/scopesim_templates/calibration/micado/viking_fields/viking_fields.py b/scopesim_templates/micado/viking_fields/viking_fields.py similarity index 97% rename from scopesim_templates/calibration/micado/viking_fields/viking_fields.py rename to scopesim_templates/micado/viking_fields/viking_fields.py index 713fee9..306873f 100644 --- a/scopesim_templates/calibration/micado/viking_fields/viking_fields.py +++ b/scopesim_templates/micado/viking_fields/viking_fields.py @@ -11,10 +11,10 @@ import pyckles -from ....stellar import stars -from ....extragalactic import elliptical -from ....rc import ter_curve_utils as tcu -from ....rc import Source +from ...stellar import stars +from ...extragalactic import elliptical +from ...rc import ter_curve_utils as tcu +from ...rc import Source DATA_DIR = pth.abspath(pth.dirname(__file__)) diff --git a/scopesim_templates/tests/test_calibration/test_micado/__init__.py b/scopesim_templates/tests/test_micado/__init__.py similarity index 100% rename from scopesim_templates/tests/test_calibration/test_micado/__init__.py rename to scopesim_templates/tests/test_micado/__init__.py diff --git a/scopesim_templates/tests/test_calibration/test_micado/test_darkness.py b/scopesim_templates/tests/test_micado/test_darkness.py similarity index 89% rename from scopesim_templates/tests/test_calibration/test_micado/test_darkness.py rename to scopesim_templates/tests/test_micado/test_darkness.py index 6a6dc93..0463cc8 100644 --- a/scopesim_templates/tests/test_calibration/test_micado/test_darkness.py +++ b/scopesim_templates/tests/test_micado/test_darkness.py @@ -1,7 +1,7 @@ """Test for darkness.""" from astropy.table import Table from synphot import SourceSpectrum -from scopesim_templates.calibration.micado import darkness +from scopesim_templates.micado import darkness from scopesim_templates.rc import Source diff --git a/scopesim_templates/tests/test_calibration/test_micado/test_flatlamp.py b/scopesim_templates/tests/test_micado/test_flatlamp.py similarity index 88% rename from scopesim_templates/tests/test_calibration/test_micado/test_flatlamp.py rename to scopesim_templates/tests/test_micado/test_flatlamp.py index 26bfb1e..e1610cd 100644 --- a/scopesim_templates/tests/test_calibration/test_micado/test_flatlamp.py +++ b/scopesim_templates/tests/test_micado/test_flatlamp.py @@ -1,7 +1,7 @@ """Test for flatlamp.""" from astropy.io.fits import ImageHDU from synphot import SourceSpectrum -from scopesim_templates.calibration.micado import flatlamp +from scopesim_templates.micado import flatlamp from scopesim_templates.rc import Source diff --git a/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py b/scopesim_templates/tests/test_micado/test_viking_fields.py similarity index 97% rename from scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py rename to scopesim_templates/tests/test_micado/test_viking_fields.py index 2aa69cd..c9b6190 100644 --- a/scopesim_templates/tests/test_calibration/test_micado/test_viking_fields.py +++ b/scopesim_templates/tests/test_micado/test_viking_fields.py @@ -8,7 +8,7 @@ from scopesim import load_example_optical_train -from scopesim_templates.calibration.micado import viking_fields as vf +from scopesim_templates.micado import viking_fields as vf PLOTS = False From 9de1fdc430d193c5567a50939990d4a6f8f33ff1 Mon Sep 17 00:00:00 2001 From: Hugo Buddelmeijer Date: Wed, 24 Aug 2022 22:57:22 +0200 Subject: [PATCH 3/9] Properly set meta["function_call"] of micado functions. --- scopesim_templates/micado/__init__.py | 33 ++++++++++++++++++----- scopesim_templates/micado/cluster.py | 3 +++ scopesim_templates/utils/general_utils.py | 8 ++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/scopesim_templates/micado/__init__.py b/scopesim_templates/micado/__init__.py index 1641c29..240ce00 100644 --- a/scopesim_templates/micado/__init__.py +++ b/scopesim_templates/micado/__init__.py @@ -1,9 +1,30 @@ -from .darkness import darkness -from .flatlamp import flatlamp -from .cluster import cluster +from .darkness import darkness as _darkness +from .flatlamp import flatlamp as _flatlamp +from .cluster import cluster as _cluster from .viking_fields import viking_fields -# Include empty_sky for backwards compatibility reasons. -# TODO: Remove empty_sky when it is not used in MicadoWISE anymore. -empty_sky = darkness +from ..utils.general_utils import add_function_call_str + + +@add_function_call_str +def darkness(): + _darkness() + + +@add_function_call_str +def empty_sky(): + # Include empty_sky for backwards compatibility reasons. + # TODO: Remove empty_sky when it is not used in MicadoWISE anymore. + return _darkness() + + +@add_function_call_str +def flatlamp(): + return _flatlamp() + + +@add_function_call_str +def cluster(): + return _cluster() + __all__ = [darkness, flatlamp, empty_sky, cluster] diff --git a/scopesim_templates/micado/cluster.py b/scopesim_templates/micado/cluster.py index 3f3deb0..19caec0 100644 --- a/scopesim_templates/micado/cluster.py +++ b/scopesim_templates/micado/cluster.py @@ -1,7 +1,10 @@ """A standard cluster for MICADO.""" +from scopesim_templates.utils.general_utils import function_call_str, add_function_call_str + import scopesim_templates.stellar.clusters +@add_function_call_str def cluster(): """A basic cluster.""" return scopesim_templates.stellar.clusters.cluster(mass=10000, distance=2000, core_radius=.1) diff --git a/scopesim_templates/utils/general_utils.py b/scopesim_templates/utils/general_utils.py index f968f4b..94b636b 100644 --- a/scopesim_templates/utils/general_utils.py +++ b/scopesim_templates/utils/general_utils.py @@ -44,6 +44,14 @@ def function_call_str(func, args): return func_call +def add_function_call_str(func, *args, **kwargs): + def inner_func(): + src = func(*args, **kwargs) + src.meta["function_call"] = function_call_str(func, kwargs) + return src + return inner_func + + def make_img_wcs_header(ra, dec, pixel_scale, image_size): """ Create a WCS header for an image From 1e10cf679c858bd2b2d3f7677a1cf2f0732cad22 Mon Sep 17 00:00:00 2001 From: Hugo Buddelmeijer Date: Thu, 25 Aug 2022 00:12:17 +0200 Subject: [PATCH 4/9] Fix bug in darkness --- scopesim_templates/micado/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scopesim_templates/micado/__init__.py b/scopesim_templates/micado/__init__.py index 240ce00..899882f 100644 --- a/scopesim_templates/micado/__init__.py +++ b/scopesim_templates/micado/__init__.py @@ -7,7 +7,7 @@ @add_function_call_str def darkness(): - _darkness() + return _darkness() @add_function_call_str From cc46536c6392adc17e53e6a1721d1ff64789f9f6 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 1 Sep 2022 14:41:29 +0200 Subject: [PATCH 5/9] added line list function to micado --- .../micado/spectral_calibrations.py | 120 ++++++++++++++++++ .../test_micado/test_spectral_calibrations.py | 50 ++++++++ 2 files changed, 170 insertions(+) create mode 100644 scopesim_templates/micado/spectral_calibrations.py create mode 100644 scopesim_templates/tests/test_micado/test_spectral_calibrations.py diff --git a/scopesim_templates/micado/spectral_calibrations.py b/scopesim_templates/micado/spectral_calibrations.py new file mode 100644 index 0000000..e98a173 --- /dev/null +++ b/scopesim_templates/micado/spectral_calibrations.py @@ -0,0 +1,120 @@ +from os import path as p + +import numpy as np +from scipy import signal +from astropy.io import ascii as ioascii +from astropy.io import fits +from astropy import units as u +from synphot import SourceSpectrum, Empirical1D +from synphot.units import PHOTLAM + +from scopesim import Source +from scopesim.optics import image_plane_utils as ipu +from ..rc import ter_curve_utils as tcu + +DATA_DIR = p.join(p.dirname(__file__), "data") + + +def line_list(unit_flux=1*PHOTLAM, + dwave=0.0001, + smoothing_fwhm=5, + filename="masterlinelist_2.1.txt"): + """ + Make a ScopeSim.Source object for the calibration lamp line list + + [PHOTLAM] = [ph s-1 cm-2 AA-1] + + Parameters + ---------- + unit_flux : astropy.Quantity + Default 1*PHOTLAM. + Flux conversion factor for a relative intensity value of 1. + The unit can be overridden with any equivalent astropy Quantity. + dwave : float + [nm] Bin width + smoothing_fwhm : int, float + Default 5 bins. FWHM of smoothing kernel in units of number of bins + (bin width = dwave) + filename : str + Name of line list file found in ``micado/data`` + + Returns + ------- + line_list_src : scopesim.Source + + Examples + -------- + :: + + from scopesim_templates.micado import spectral_calibrations as mic_spec + from synphot.units import PHOTLAM + from astropy import units as u + + # Use all defaults + src = mic_spec.line_list() + + # Make line list brighter + src = mic_spec.line_list(unit_flux=2000) # [PHOTLAM] by default + src = mic_spec.line_list(unit_flux=5*PHOTLAM) + src = mic_spec.line_list(unit_flux=300*u.Unit("ph s-1 m-2 um-1)) + + # Smooth with a gaussian kernel where FWHM is 3 bins wide + src = mic_spec.line_list(smoothing_fwhm=3) + + """ + if not isinstance(unit_flux, u.Quantity): + unit_flux *= PHOTLAM + + # import line list and pad with zeros + wave, flux = import_line_spectrum(filename) + if smoothing_fwhm is not None and isinstance(smoothing_fwhm, (int, float)): + sigma = smoothing_fwhm / 2.35 + kernel = signal.windows.gaussian(M=int(8 * sigma + 1), std=sigma) + kernel /= kernel.sum() + flux = signal.convolve(flux, kernel, mode="same") + + # make spectrum + spec = SourceSpectrum(Empirical1D, points=wave * u.nm, + lookup_table=flux * unit_flux) + + # make unity image that covers MICADO FOV of +/- 30" arcsec + hw = 30./3600 # input needed in [deg] + hdr = ipu.header_from_list_of_xy([-hw, hw], [-hw, hw], 1./3600) # [deg] + hdr["SPEC_REF"] = 0 + im = np.ones((hdr["NAXIS2"], hdr["NAXIS2"])) + field = fits.ImageHDU(header=hdr, data=im) + + line_list_src = Source(image_hdu=field, spectra=[spec]) + + return line_list_src + + +def import_line_spectrum(filename): + """ + Read in and pad the line list into a spectrum + + Parameters + ---------- + filename : str + Name of line list file found in ``micado/data`` + + Returns + ------- + wave_filled : np.ndarray + wavelength vector in units of whatever is in the input file + flux_filled : np.ndarray + flux vector in units of whatever is in the input file + + """ + line_tbl = ioascii.read(p.join(DATA_DIR, filename)) + dwave = 0.0001 + wave = line_tbl["Wavelength"] + flux = line_tbl["Relative_Intensity"] + i_bin = ((wave - wave[0]) / dwave).astype(int) + wave_filled = np.arange(wave[0], wave[-1] + dwave, dwave) + flux_filled = np.zeros(i_bin[-1] + 1) + # .. todo: warning, this only works if dwave is smaller than the minimum + # distance between lines + flux_filled[i_bin] += flux + + return wave_filled, flux_filled diff --git a/scopesim_templates/tests/test_micado/test_spectral_calibrations.py b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py new file mode 100644 index 0000000..abc8c9e --- /dev/null +++ b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py @@ -0,0 +1,50 @@ +# This test suite takes long because it creates a 10 million entry spectrum 5x over + +import pytest +from pytest import approx + +import numpy as np +from astropy import units as u +from astropy.io import fits +import matplotlib.pyplot as plt + +from synphot import SourceSpectrum +from scopesim_templates.micado import spectral_calibrations as mic_sc + +PLOTS = False + + +class TestLineList: + def test_returns_source_object_with_everything_as_needed(self): + src = mic_sc.line_list() + + wave = np.arange(0.8, 2.5, 1e-7) * u.um + flux = src.spectra[0](wave) + + if not PLOTS: + plt.plot(wave, flux) + plt.show() + + assert isinstance(src.spectra[0], SourceSpectrum) + assert isinstance(src.fields[0], fits.ImageHDU) + + def test_returns_flux_scaled_spectrum(self): + src1 = mic_sc.line_list() + src2 = mic_sc.line_list(unit_flux=5) + + wave = np.arange(0.81, 2.5, 1e-7) * u.um + flux1 = src1.spectra[0](wave).value + flux2 = src2.spectra[0](wave).value + + assert 5 * flux1.sum() == approx(flux2.sum(), rel=1e-4) + + def test_returns_a_smoothed_spectrum(self): + src1 = mic_sc.line_list(smoothing_fwhm=None) + src2 = mic_sc.line_list(smoothing_fwhm=5) + + wave = np.arange(0.81, 2.5, 1e-7) * u.um + flux1 = src1.spectra[0](wave).value + flux2 = src2.spectra[0](wave).value + + assert flux1.max() > flux2.max() + assert flux1.sum() == approx(flux2.sum(), rel=1e-4) From f957afd8766fe5f1f59b2dcdc96004936322a2ac Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 2 Sep 2022 15:13:25 +0200 Subject: [PATCH 6/9] updates to micado line list function --- scopesim_templates/micado/__init__.py | 1 + .../micado/spectral_calibrations.py | 48 ++++++++------- .../test_micado/test_spectral_calibrations.py | 58 +++++++++++++++++-- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/scopesim_templates/micado/__init__.py b/scopesim_templates/micado/__init__.py index 899882f..cddc5d4 100644 --- a/scopesim_templates/micado/__init__.py +++ b/scopesim_templates/micado/__init__.py @@ -4,6 +4,7 @@ from .viking_fields import viking_fields from ..utils.general_utils import add_function_call_str +from . import spectral_calibrations @add_function_call_str def darkness(): diff --git a/scopesim_templates/micado/spectral_calibrations.py b/scopesim_templates/micado/spectral_calibrations.py index e98a173..931e426 100644 --- a/scopesim_templates/micado/spectral_calibrations.py +++ b/scopesim_templates/micado/spectral_calibrations.py @@ -16,9 +16,12 @@ def line_list(unit_flux=1*PHOTLAM, - dwave=0.0001, - smoothing_fwhm=5, - filename="masterlinelist_2.1.txt"): + dwave=0.001, + smoothing_fwhm=0.003, + width=15., + height=1., + filename="masterlinelist_2.1.txt", + ): """ Make a ScopeSim.Source object for the calibration lamp line list @@ -31,10 +34,9 @@ def line_list(unit_flux=1*PHOTLAM, Flux conversion factor for a relative intensity value of 1. The unit can be overridden with any equivalent astropy Quantity. dwave : float - [nm] Bin width + Bin width in units of input file smoothing_fwhm : int, float - Default 5 bins. FWHM of smoothing kernel in units of number of bins - (bin width = dwave) + FWHM of smoothing kernel in units of ``dwave`` (i.e. input file) filename : str Name of line list file found in ``micado/data`` @@ -66,9 +68,10 @@ def line_list(unit_flux=1*PHOTLAM, unit_flux *= PHOTLAM # import line list and pad with zeros - wave, flux = import_line_spectrum(filename) + wave, flux = import_line_spectrum(filename, dwave) + if smoothing_fwhm is not None and isinstance(smoothing_fwhm, (int, float)): - sigma = smoothing_fwhm / 2.35 + sigma = smoothing_fwhm / dwave / 2.35 kernel = signal.windows.gaussian(M=int(8 * sigma + 1), std=sigma) kernel /= kernel.sum() flux = signal.convolve(flux, kernel, mode="same") @@ -78,10 +81,13 @@ def line_list(unit_flux=1*PHOTLAM, lookup_table=flux * unit_flux) # make unity image that covers MICADO FOV of +/- 30" arcsec - hw = 30./3600 # input needed in [deg] - hdr = ipu.header_from_list_of_xy([-hw, hw], [-hw, hw], 1./3600) # [deg] + dw = 0.5 * width / 3600 # input needed in [deg] + dh = 0.5 * height / 3600 # input needed in [deg] + pixel_scale = 0.1 * dw + + hdr = ipu.header_from_list_of_xy([-dw, dw], [-dh, dh], pixel_scale) # [deg] hdr["SPEC_REF"] = 0 - im = np.ones((hdr["NAXIS2"], hdr["NAXIS2"])) + im = np.ones((hdr["NAXIS1"], hdr["NAXIS2"])) field = fits.ImageHDU(header=hdr, data=im) line_list_src = Source(image_hdu=field, spectra=[spec]) @@ -89,7 +95,7 @@ def line_list(unit_flux=1*PHOTLAM, return line_list_src -def import_line_spectrum(filename): +def import_line_spectrum(filename, dwave=0.0001): """ Read in and pad the line list into a spectrum @@ -107,14 +113,16 @@ def import_line_spectrum(filename): """ line_tbl = ioascii.read(p.join(DATA_DIR, filename)) - dwave = 0.0001 - wave = line_tbl["Wavelength"] - flux = line_tbl["Relative_Intensity"] - i_bin = ((wave - wave[0]) / dwave).astype(int) + + wave = line_tbl["Wavelength"].data + wave = np.round(wave / dwave) * dwave # round to level of dwave wave_filled = np.arange(wave[0], wave[-1] + dwave, dwave) - flux_filled = np.zeros(i_bin[-1] + 1) - # .. todo: warning, this only works if dwave is smaller than the minimum - # distance between lines - flux_filled[i_bin] += flux + w0 = wave[0] + + flux = line_tbl["Relative_Intensity"].data + flux_filled = np.zeros_like(wave_filled) + for w, f in zip(wave, flux): + i = int((w - w0) / dwave) + flux_filled[i] += f return wave_filled, flux_filled diff --git a/scopesim_templates/tests/test_micado/test_spectral_calibrations.py b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py index abc8c9e..e39a513 100644 --- a/scopesim_templates/tests/test_micado/test_spectral_calibrations.py +++ b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py @@ -18,10 +18,10 @@ class TestLineList: def test_returns_source_object_with_everything_as_needed(self): src = mic_sc.line_list() - wave = np.arange(0.8, 2.5, 1e-7) * u.um + wave = np.arange(0.8, 2.5, 1e-6) * u.um flux = src.spectra[0](wave) - if not PLOTS: + if PLOTS: plt.plot(wave, flux) plt.show() @@ -40,11 +40,61 @@ def test_returns_flux_scaled_spectrum(self): def test_returns_a_smoothed_spectrum(self): src1 = mic_sc.line_list(smoothing_fwhm=None) - src2 = mic_sc.line_list(smoothing_fwhm=5) + src2 = mic_sc.line_list(smoothing_fwhm=0.005) wave = np.arange(0.81, 2.5, 1e-7) * u.um flux1 = src1.spectra[0](wave).value flux2 = src2.spectra[0](wave).value assert flux1.max() > flux2.max() - assert flux1.sum() == approx(flux2.sum(), rel=1e-4) + assert flux1.sum() == approx(flux2.sum(), rel=2e-2) + + def test_micado_lines(self): + + import numpy as np + from astropy import units as u + from matplotlib import pyplot as plt + from matplotlib.colors import LogNorm + + import scopesim as sim + + sim.rc.__config__["!SIM.file.local_packages_path"] = "F:/Work/irdb" + + cmds = sim.UserCommands(use_instrument="MICADO", + set_modes=["SCAO", "SPEC_3000x20"]) + cmds["!OBS.dit"] = 3600 # [s] Exposure time (more or less) + cmds["!OBS.filter_name_fw1"] = "Spec_HK" # Spec_IJ, Spec_HK + cmds["!OBS.filter_name_fw2"] = "open" + cmds["!SIM.spectral.spectral_bin_width"] = 1e-4 + + micado = sim.OpticalTrain(cmds) + + # Turn off the effects that are not needed (see below for more on this) + micado["skycalc_atmosphere"].include = False + micado["telescope_reflection"].include = False + + # Set to False to test if everything is working, then flip to True + USE_FULL_DETECTOR = False + micado["full_detector_array"].include = USE_FULL_DETECTOR + micado["detector_window"].include = not USE_FULL_DETECTOR + + src_lines = mic_sc.line_list(unit_flux=3e23, dwave=1e-1, smoothing_fwhm=None) + + micado.observe(src_lines) + + plt.figure(figsize=(15, 15)) + plt.imshow(micado.image_planes[0].data, norm=LogNorm()) + plt.colorbar() + plt.show() + + fl = micado.fov_manager._fovs_list + for fov in fl[1:3]: + w = fov.spectra[0].model.points[0] + f = fov.spectra[0].model.lookup_table + plt.plot(w, f) + plt.show() + + plt.figure(figsize=(15, 15)) + plt.imshow(fl[3].cube.data.sum(axis=1), norm=LogNorm()) + plt.show() + From 371bc5033c4dd8d1c58b58317175a9fca418e217 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 7 Sep 2022 13:01:13 +0200 Subject: [PATCH 7/9] added line list file --- .../micado/data/masterlinelist_2.1.txt | 380 ++++++++++++++++++ 1 file changed, 380 insertions(+) create mode 100644 scopesim_templates/micado/data/masterlinelist_2.1.txt diff --git a/scopesim_templates/micado/data/masterlinelist_2.1.txt b/scopesim_templates/micado/data/masterlinelist_2.1.txt new file mode 100644 index 0000000..cd4a21f --- /dev/null +++ b/scopesim_templates/micado/data/masterlinelist_2.1.txt @@ -0,0 +1,380 @@ +# description : Spectral line list for MICADO calibration lamp extracted from NIST +# author : Joshua Jost +# source : NIST spectral database +# date_created : +# date_modified : 2022-08-31 +# wavelength_unit : nm +# +# changes : +# - 2022-08-31 (KL) Added meta data header to file. Replaced commas with decimal points +Lamp Wavelength Relative_Intensity +Argon 800.8359 20000.0 +Argon 801.6990 25000.0 +Krypton 806.1721 100.0 +Argon 810.5921 20000.0 +Krypton 810.6595 4000.0 +Krypton 811.5132 500.0 +Argon 811.7542 35000.0 +Krypton 819.2308 300.0 +Xenon 823.3896 10000.0 +Krypton 826.5514 400.0 +Argon 826.6794 10000.0 +Xenon 828.2392 7000.0 +Krypton 828.3328 200.0 +Krypton 830.0391 500.0 +Argon 841.0521 15000.0 +Xenon 841.1500 2000.0 +Argon 842.6963 20000.0 +Neon 849.7693 69000.0 +Krypton 851.1211 200.0 +Argon 852.3783 15000.0 +Neon 859.3618 41000.0 +Neon 863.7019 35000.0 +Neon 865.6760 64000.0 +Argon 867.0325 4500.0 +Krypton 877.9161 300.0 +Xenon 882.1832 5000.0 +Xenon 886.4753 300.0 +Neon 892.1950 6400.0 +Krypton 893.1145 200.0 +Xenon 895.4709 1000.0 +Xenon 904.7930 400.0 +Argon 912.5471 35000.0 +Argon 915.8562 27.0 +Xenon 916.5167 500.0 +Xenon 917.0040 100.0 +Argon 922.7030 15000.0 +Argon 935.6787 1600.0 +Xenon 937.7330 100.0 +Neon 948.9285 5000.0 +Xenon 949.9680 40.0 +Xenon 950.8390 10.0 +Xenon 951.5987 200.0 +Neon 953.6779 6100.0 +Krypton 954.3510 30.0 +Neon 955.0024 2800.0 +Xenon 958.7770 20.0 +Argon 966.0435 25000.0 +Neon 966.8071 18000.0 +Xenon 968.7980 150.0 +Krypton 969.0490 10.0 +Xenon 970.3650 20.0 +Krypton 970.6880 50.0 +Krypton 971.7510 15.0 +Xenon 972.0830 100.0 +Krypton 974.5780 50.0 +Argon 978.7186 4500.0 +Xenon 980.2384 2000.0 +Krypton 985.8940 500.0 +Xenon 992.5919 3000.0 +Xenon 996.9310 10.0 +Xenon 1002.6470 50.0 +Argon 1005.4820 180.0 +Xenon 1006.3720 10.0 +Xenon 1008.7550 20.0 +Xenon 1011.0110 80.0 +Krypton 1012.3730 30.0 +Xenon 1012.8250 20.0 +Krypton 1015.0460 10.0 +Xenon 1019.1150 10.0 +Xenon 1025.3880 20.0 +Neon 1029.8238 420.0 +Krypton 1029.9750 80.0 +Argon 1033.5550 30.0 +Krypton 1036.3210 100.0 +Krypton 1037.7280 10.0 +Argon 1047.2923 1600.0 +Argon 1048.0905 13.0 +Argon 1050.9380 180.0 +Xenon 1051.8030 10.0 +Xenon 1053.0742 900.0 +Xenon 1055.2650 20.0 +Neon 1056.5303 8000.0 +Krypton 1059.5940 20.0 +Neon 1062.3574 780.0 +Argon 1067.6489 200.0 +Argon 1068.4699 11.0 +Xenon 1070.9710 150.0 +Argon 1073.6810 30.0 +Xenon 1076.1810 100.0 +Neon 1080.1001 6100.0 +Xenon 1084.1310 1000.0 +Neon 1084.7448 9400.0 +Krypton 1087.7880 150.0 +Xenon 1089.8308 870.0 +Neon 1102.3898 78.0 +Neon 1104.7025 64.0 +Neon 1105.2748 200.0 +Argon 1108.1903 11.0 +Xenon 1108.8273 1900.0 +Argon 1110.9500 30.0 +Xenon 1113.0236 375.0 +Xenon 1114.4196 120.0 +Neon 1114.6072 26000.0 +Neon 1116.3270 270.0 +Xenon 1116.5730 10.0 +Neon 1118.0586 49000.0 +Krypton 1119.0170 79.0 +Krypton 1126.0787 130.0 +Krypton 1126.2240 50.0 +Neon 1139.3552 15000.0 +Neon 1141.2258 8800.0 +Xenon 1141.8170 15.0 +Argon 1144.4965 12.0 +Krypton 1146.0614 220.0 +Argon 1149.1254 400.0 +Xenon 1149.4370 15.0 +Neon 1152.5900 33000.0 +Neon 1152.8176 17000.0 +Neon 1153.9503 9100.0 +Neon 1160.4713 2600.0 +Neon 1161.7260 13000.0 +Argon 1167.1904 200.0 +Neon 1169.1202 2800.0 +Argon 1172.2696 12.0 +Xenon 1174.5450 1750.0 +Neon 1177.0014 15000.0 +Neon 1179.2271 13000.0 +Neon 1179.3117 3200.0 +Krypton 1179.5640 140.0 +Xenon 1179.6790 10.0 +Krypton 1182.2614 1800.0 +Neon 1198.8194 7400.0 +Krypton 1200.0385 350.0 +Neon 1206.9636 23000.0 +Krypton 1208.0520 160.0 +Argon 1211.5641 200.0 +Krypton 1212.1110 150.0 +Krypton 1212.6870 50.0 +Argon 1214.3060 50.0 +Krypton 1220.7875 840.0 +Krypton 1232.4450 20.0 +Argon 1234.6770 50.0 +Argon 1240.6221 200.0 +Argon 1244.2724 200.0 +Argon 1245.9530 100.0 +Neon 1246.2799 4300.0 +Argon 1249.1080 200.0 +Neon 1264.3775 500.0 +Neon 1264.6198 710.0 +Neon 1265.4443 330.0 +Neon 1266.1809 470.0 +Neon 1268.7003 300.0 +Neon 1269.2675 6500.0 +Argon 1270.5756 150.0 +Argon 1273.6901 30.0 +Argon 1274.9719 12.0 +Neon 1275.2612 710.0 +Neon 1277.3018 1600.0 +Krypton 1278.6020 100.0 +Argon 1280.6241 200.0 +Krypton 1286.5410 46.0 +Krypton 1288.2260 470.0 +Neon 1291.5546 8400.0 +Argon 1293.6733 50.0 +Argon 1296.0203 500.0 +Krypton 1298.8870 14.0 +Argon 1301.1822 200.0 +Krypton 1318.1015 310.0 +Argon 1321.7600 200.0 +Neon 1322.2858 4500.0 +Argon 1323.1725 200.0 +Argon 1323.4520 100.0 +Argon 1327.6270 500.0 +Argon 1331.6851 1000.0 +Xenon 1333.5500 75.0 +Krypton 1334.1530 18.0 +Argon 1337.0766 1000.0 +Argon 1350.7884 1000.0 +Argon 1357.7329 11.0 +Argon 1360.3052 30.0 +Krypton 1362.6141 130.0 +Argon 1362.6384 400.0 +Krypton 1363.7949 250.0 +Xenon 1366.0210 150.0 +Krypton 1366.2120 37.0 +Argon 1368.2290 200.0 +Argon 1372.2328 1000.0 +Krypton 1374.2612 51.0 +Argon 1382.9495 10.0 +Krypton 1388.6650 27.0 +Argon 1391.1280 10.0 +Xenon 1392.3400 15.0 +Krypton 1392.7850 42.0 +Krypton 1394.2810 10.0 +Argon 1409.7493 200.0 +Xenon 1413.2000 50.0 +Xenon 1414.5960 80.0 +Krypton 1416.0490 15.0 +Krypton 1435.1400 51.0 +Xenon 1436.8830 20.0 +Krypton 1440.6220 12.0 +Krypton 1443.0736 350.0 +Xenon 1473.6410 200.0 +Krypton 1473.8469 100.0 +Krypton 1476.6720 26.0 +Krypton 1476.9520 28.0 +Xenon 1485.4100 20.0 +Krypton 1496.5980 290.0 +Neon 1499.0415 530.0 +Argon 1505.0610 100.0 +Xenon 1510.3800 100.0 +Neon 1514.4236 350.0 +Argon 1517.6840 25.0 +Neon 1519.5083 270.0 +Krypton 1521.3700 10.0 +Neon 1523.4877 5300.0 +Krypton 1524.3787 160.0 +Krypton 1533.0670 12.0 +Argon 1533.3530 10.0 +Krypton 1533.9158 200.0 +Krypton 1537.6242 725.0 +Neon 1541.1803 250.0 +Xenon 1542.2220 110.0 +Krypton 1547.8261 150.0 +Xenon 1549.5200 45.0 +Xenon 1556.1400 150.0 +Krypton 1568.5280 24.0 +Krypton 1582.4412 105.0 +Xenon 1598.3900 250.0 +Argon 1599.3860 30.0 +Xenon 1604.4300 100.0 +Neon 1627.3400 63.0 +Krypton 1631.9715 50.0 +Argon 1652.4370 30.0 +Xenon 1655.9000 125.0 +Krypton 1673.1100 77.0 +Xenon 1673.2727 5000.0 +Xenon 1675.0295 46.0 +Krypton 1678.9718 320.0 +Krypton 1685.8102 170.0 +Xenon 1688.7690 38.0 +Krypton 1689.5067 340.0 +Krypton 1690.1380 400.0 +Krypton 1694.0439 280.0 +Argon 1694.5210 500.0 +Krypton 1710.3450 87.0 +Neon 1716.6622 1800.0 +Xenon 1733.0530 1650.0 +Krypton 1737.2357 110.0 +Krypton 1740.9190 12.0 +Xenon 1748.7746 42.0 +Krypton 1762.1650 35.0 +Krypton 1784.7617 950.0 +Krypton 1800.7146 1200.0 +Neon 1804.0737 1900.0 +Neon 1808.8119 4500.0 +Krypton 1810.4380 72.0 +Krypton 1817.2288 940.0 +Neon 1828.1632 14000.0 +Neon 1828.7606 10000.0 +Neon 1830.8966 6800.0 +Neon 1836.4108 1900.0 +Neon 1838.9846 6400.0 +Neon 1839.4958 8600.0 +Neon 1840.7861 3900.0 +Neon 1842.7432 6300.0 +Neon 1846.3681 1300.0 +Neon 1848.0845 4100.0 +Krypton 1858.5960 270.0 +Neon 1859.6617 6900.0 +Neon 1860.2776 9500.0 +Neon 1868.7339 130.0 +Krypton 1870.1411 380.0 +Krypton 1879.0610 180.0 +Krypton 1879.2860 10.0 +Xenon 1879.3276 860.0 +Krypton 1880.2840 360.0 +Neon 1894.2723 150.0 +Neon 1957.9094 260.0 +Neon 1958.2455 790.0 +Neon 1977.7860 32.0 +Xenon 2019.2711 80.0 +Krypton 2021.5410 61.0 +Xenon 2026.7774 2300.0 +Xenon 2028.7972 10.0 +Neon 2035.5771 630.0 +Neon 2035.9404 43.0 +Argon 2062.1860 50.0 +Argon 2099.1840 30.0 +Neon 2104.7013 2700.0 +Krypton 2117.1300 90.0 +Xenon 2137.8892 26.0 +Neon 2142.0939 30.0 +Neon 2142.7883 46.0 +Xenon 2147.5961 140.0 +Neon 2150.9615 90.0 +Neon 2158.2413 34.0 +Neon 2158.5760 32.0 +Neon 2171.4039 2900.0 +Krypton 2190.8510 1300.0 +Neon 2217.7292 78.0 +Neon 2225.3432 1300.0 +Xenon 2227.5900 60.0 +Xenon 2239.2500 40.0 +Xenon 2241.2900 75.0 +Neon 2243.4265 1300.0 +Neon 2247.2920 540.0 +Krypton 2249.1900 71.0 +Neon 2253.6528 8500.0 +Xenon 2262.4500 90.0 +Neon 2266.7971 1300.0 +Neon 2269.3959 210.0 +Xenon 2297.1100 40.0 +Xenon 2307.9800 45.0 +Neon 2310.6784 2500.0 +Argon 2313.9510 20.0 +Xenon 2319.8000 10.0 +Xenon 2325.9100 35.0 +Neon 2326.6619 3800.0 +Xenon 2328.5900 110.0 +Krypton 2334.6790 120.0 +Neon 2337.9343 5000.0 +Krypton 2350.8900 39.0 +Neon 2357.1764 3400.0 +Neon 2364.2934 17000.0 +Neon 2370.8130 1200.0 +Neon 2371.5599 5900.0 +Xenon 2380.3000 60.0 +Neon 2391.8541 170.0 +Neon 2395.7931 11000.0 +Neon 2396.2964 4600.0 +Argon 2397.3060 20.0 +Neon 2397.8372 220.0 +Neon 2398.4701 6000.0 +Neon 2410.5148 1100.0 +Neon 2415.6486 210.0 +Neon 2416.8025 2000.0 +Neon 2422.5535 140.0 +Neon 2425.6224 2800.0 +Krypton 2426.7180 70.0 +Krypton 2429.8900 110.0 +Neon 2431.6420 38.0 +Neon 2437.1661 7400.0 +Neon 2437.8260 3800.0 +Neon 2439.0011 360.0 +Xenon 2445.0300 70.0 +Neon 2445.4531 1900.0 +Neon 2445.9775 240.0 +Neon 2446.6068 3300.0 +Neon 2447.1606 370.0 +Neon 2453.2498 55.0 +Xenon 2470.9000 60.0 +Krypton 2477.5390 24.0 +Neon 2478.3248 1700.0 +Xenon 2483.2200 20.0 +Neon 2491.0521 780.0 +Neon 2493.5696 2900.0 +Neon 2500.6628 170.0 +Xenon 2515.2800 175.0 +Xenon 2516.6300 60.0 +Neon 2516.8567 1300.0 +Neon 2523.4824 300.0 +Krypton 2524.0750 150.0 +Neon 2528.4125 100.0 +Neon 2540.0128 280.0 +Xenon 2541.9700 45.0 +Neon 2553.1295 4600.0 +Neon 2579.4008 85.0 +Krypton 2585.5940 11.0 + From 683e95937dad0696e976ac8f6351adaf068dedf2 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 12 Oct 2022 14:24:37 +0200 Subject: [PATCH 8/9] Minor --- scopesim_templates/micado/spectral_calibrations.py | 8 ++++---- scopesim_templates/stellar/stars.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scopesim_templates/micado/spectral_calibrations.py b/scopesim_templates/micado/spectral_calibrations.py index 931e426..7bc1f3b 100644 --- a/scopesim_templates/micado/spectral_calibrations.py +++ b/scopesim_templates/micado/spectral_calibrations.py @@ -114,13 +114,13 @@ def import_line_spectrum(filename, dwave=0.0001): """ line_tbl = ioascii.read(p.join(DATA_DIR, filename)) + flux = line_tbl["Relative_Intensity"].data wave = line_tbl["Wavelength"].data wave = np.round(wave / dwave) * dwave # round to level of dwave - wave_filled = np.arange(wave[0], wave[-1] + dwave, dwave) - w0 = wave[0] - - flux = line_tbl["Relative_Intensity"].data + w0, w1 = wave[0], wave[-1] + wave_filled = np.arange(w0 - dwave, w1 + 2 * dwave, dwave) flux_filled = np.zeros_like(wave_filled) + for w, f in zip(wave, flux): i = int((w - w0) / dwave) flux_filled[i] += f diff --git a/scopesim_templates/stellar/stars.py b/scopesim_templates/stellar/stars.py index 6667fea..82f987e 100644 --- a/scopesim_templates/stellar/stars.py +++ b/scopesim_templates/stellar/stars.py @@ -181,7 +181,7 @@ def stars(filter_name, amplitudes, spec_types, x, y, library="pyckles", ra=RA0, >>> import numpy as np >>> import astropy.units as u - >>> from scopesim_templates.basic.stars import stars + >>> from scopesim_templates.stellar import stars >>> >>> n = 100 >>> spec_types = ["A0V", "G2V", "K0III", "M5III", "O8I"] From acfaba6842dc620b32d25845e3cb571415883315 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 12 Oct 2022 14:32:13 +0200 Subject: [PATCH 9/9] minor --- .../test_micado/test_spectral_calibrations.py | 97 +++++++++---------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/scopesim_templates/tests/test_micado/test_spectral_calibrations.py b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py index e39a513..4e6def2 100644 --- a/scopesim_templates/tests/test_micado/test_spectral_calibrations.py +++ b/scopesim_templates/tests/test_micado/test_spectral_calibrations.py @@ -49,52 +49,51 @@ def test_returns_a_smoothed_spectrum(self): assert flux1.max() > flux2.max() assert flux1.sum() == approx(flux2.sum(), rel=2e-2) - def test_micado_lines(self): - - import numpy as np - from astropy import units as u - from matplotlib import pyplot as plt - from matplotlib.colors import LogNorm - - import scopesim as sim - - sim.rc.__config__["!SIM.file.local_packages_path"] = "F:/Work/irdb" - - cmds = sim.UserCommands(use_instrument="MICADO", - set_modes=["SCAO", "SPEC_3000x20"]) - cmds["!OBS.dit"] = 3600 # [s] Exposure time (more or less) - cmds["!OBS.filter_name_fw1"] = "Spec_HK" # Spec_IJ, Spec_HK - cmds["!OBS.filter_name_fw2"] = "open" - cmds["!SIM.spectral.spectral_bin_width"] = 1e-4 - - micado = sim.OpticalTrain(cmds) - - # Turn off the effects that are not needed (see below for more on this) - micado["skycalc_atmosphere"].include = False - micado["telescope_reflection"].include = False - - # Set to False to test if everything is working, then flip to True - USE_FULL_DETECTOR = False - micado["full_detector_array"].include = USE_FULL_DETECTOR - micado["detector_window"].include = not USE_FULL_DETECTOR - - src_lines = mic_sc.line_list(unit_flux=3e23, dwave=1e-1, smoothing_fwhm=None) - - micado.observe(src_lines) - - plt.figure(figsize=(15, 15)) - plt.imshow(micado.image_planes[0].data, norm=LogNorm()) - plt.colorbar() - plt.show() - - fl = micado.fov_manager._fovs_list - for fov in fl[1:3]: - w = fov.spectra[0].model.points[0] - f = fov.spectra[0].model.lookup_table - plt.plot(w, f) - plt.show() - - plt.figure(figsize=(15, 15)) - plt.imshow(fl[3].cube.data.sum(axis=1), norm=LogNorm()) - plt.show() - + # def test_micado_lines(self): + # + # import numpy as np + # from astropy import units as u + # from matplotlib import pyplot as plt + # from matplotlib.colors import LogNorm + # + # import scopesim as sim + # + # sim.rc.__config__["!SIM.file.local_packages_path"] = "F:/Work/irdb" + # + # cmds = sim.UserCommands(use_instrument="MICADO", + # set_modes=["SCAO", "SPEC_3000x20"]) + # cmds["!OBS.dit"] = 3600 # [s] Exposure time (more or less) + # cmds["!OBS.filter_name_fw1"] = "Spec_HK" # Spec_IJ, Spec_HK + # cmds["!OBS.filter_name_fw2"] = "open" + # cmds["!SIM.spectral.spectral_bin_width"] = 1e-4 + # + # micado = sim.OpticalTrain(cmds) + # + # # Turn off the effects that are not needed (see below for more on this) + # micado["skycalc_atmosphere"].include = False + # micado["telescope_reflection"].include = False + # + # # Set to False to test if everything is working, then flip to True + # USE_FULL_DETECTOR = False + # micado["full_detector_array"].include = USE_FULL_DETECTOR + # micado["detector_window"].include = not USE_FULL_DETECTOR + # + # src_lines = mic_sc.line_list(unit_flux=3e23, dwave=1e-1, smoothing_fwhm=None) + # + # micado.observe(src_lines) + # + # plt.figure(figsize=(15, 15)) + # plt.imshow(micado.image_planes[0].data, norm=LogNorm()) + # plt.colorbar() + # plt.show() + # + # fl = micado.fov_manager._fovs_list + # for fov in fl[1:3]: + # w = fov.spectra[0].model.points[0] + # f = fov.spectra[0].model.lookup_table + # plt.plot(w, f) + # plt.show() + # + # plt.figure(figsize=(15, 15)) + # plt.imshow(fl[3].cube.data.sum(axis=1), norm=LogNorm()) + # plt.show()