{ "cells": [ { "cell_type": "markdown", "id": "ed1256e8", "metadata": {}, "source": [ "This notebook demonstrates and tests the `SpectralEfficiency` effect for the METIS long-slit spectroscopic modes. Lacking real data, the grating effciencies used here (and available in the irdb) are pure fantasy." ] }, { "cell_type": "code", "execution_count": null, "id": "57fc6481", "metadata": {}, "outputs": [], "source": [ "import scopesim as sim\n", "\n", "sim.bug_report()\n", "\n", "# Edit this path if you have a custom install directory, otherwise comment it out.\n", "sim.rc.__config__[\"!SIM.file.local_packages_path\"] = \"../../../../\"" ] }, { "cell_type": "code", "execution_count": null, "id": "7a528531", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from astropy.io import fits\n", "from astropy.io import ascii as ioascii\n", "from astropy import units as u\n", "from matplotlib import pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "id": "91e6eeb1", "metadata": {}, "source": [ "If you haven't got the instrument packages yet, uncomment the following cell." ] }, { "cell_type": "code", "execution_count": null, "id": "62947951", "metadata": {}, "outputs": [], "source": [ "# sim.download_packages([\"METIS\", \"ELT\", \"Armazones\"])" ] }, { "cell_type": "markdown", "id": "3ff36c76", "metadata": {}, "source": [ "## Source -- constant spectrum" ] }, { "cell_type": "code", "execution_count": null, "id": "c0ec2fcd", "metadata": {}, "outputs": [], "source": [ "from synphot import SourceSpectrum, Empirical1D\n", "from scopesim_templates.micado import flatlamp" ] }, { "cell_type": "code", "execution_count": null, "id": "4f632845", "metadata": {}, "outputs": [], "source": [ "lam = np.linspace(2.8, 18, 2048)\n", "flux = 0.1 * np.ones_like(lam)\n", "spec = SourceSpectrum(Empirical1D, points = lam * u.um, lookup_table=flux)" ] }, { "cell_type": "code", "execution_count": null, "id": "ac741ecc", "metadata": {}, "outputs": [], "source": [ "src = flatlamp()\n", "src.spectra[0] = spec" ] }, { "cell_type": "markdown", "id": "07e9705d", "metadata": {}, "source": [ "## L band" ] }, { "cell_type": "code", "execution_count": null, "id": "8bd88ee5", "metadata": {}, "outputs": [], "source": [ "cmd_l = sim.UserCommands(use_instrument='METIS', set_modes=['lss_l'])" ] }, { "cell_type": "code", "execution_count": null, "id": "60a42863", "metadata": {}, "outputs": [], "source": [ "metis_l = sim.OpticalTrain(cmd_l)" ] }, { "cell_type": "code", "execution_count": null, "id": "82c6319f", "metadata": {}, "outputs": [], "source": [ "metis_l['psf'].include = False # PSF is not necessary for slit-filling source\n", "metis_l['skycalc_atmosphere'].include = False # sky lines obscure flat spectrum " ] }, { "cell_type": "markdown", "id": "eab4c272", "metadata": {}, "source": [ "Observe the source with and without the grating efficiency. The ratio between the two results (we look at the image plane, which is noise free) shows directly the efficiency.\n", "As long as no realistic data are available, the efficiency effect is turned off by default and has to be included explicitely." ] }, { "cell_type": "code", "execution_count": null, "id": "903231ec", "metadata": {}, "outputs": [], "source": [ "metis_l['grating_efficiency'].include = True\n", "metis_l.observe(src)\n", "sim_l_with_effic = metis_l.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "25c7d614", "metadata": {}, "outputs": [], "source": [ "metis_l['grating_efficiency'].include = False\n", "metis_l.observe(src, update=True)\n", "sim_l_without_effic = metis_l.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "31e717b5", "metadata": {}, "outputs": [], "source": [ "ratio_l = sim_l_with_effic / sim_l_without_effic\n", "plt.figure(figsize=(15, 5))\n", "plt.subplot(131)\n", "plt.imshow(sim_l_with_effic, origin='lower')\n", "plt.title(\"L band, with grating efficiency\")\n", "plt.subplot(132)\n", "plt.imshow(sim_l_without_effic, origin='lower')\n", "plt.title(\"L band, without grating efficiency\")\n", "plt.subplot(133)\n", "plt.imshow(ratio_l, origin='lower')\n", "plt.title(\"L band, ratio\");" ] }, { "cell_type": "code", "execution_count": null, "id": "99af7463", "metadata": {}, "outputs": [], "source": [ "plt.plot((sim_l_with_effic / sim_l_without_effic)[:, 1000]);" ] }, { "cell_type": "markdown", "id": "5924ad57", "metadata": {}, "source": [ "## M band" ] }, { "cell_type": "code", "execution_count": null, "id": "0baa31a5", "metadata": {}, "outputs": [], "source": [ "cmd_m = sim.UserCommands(use_instrument='METIS', set_modes=['lss_m'])\n", "metis_m = sim.OpticalTrain(cmd_m)" ] }, { "cell_type": "code", "execution_count": null, "id": "2a46fd7e", "metadata": {}, "outputs": [], "source": [ "metis_m['psf'].include = False # PSF is not necessary for slit-filling source\n", "metis_m['skycalc_atmosphere'].include = False # sky lines obscure flat spectrum " ] }, { "cell_type": "code", "execution_count": null, "id": "3f6e9b15", "metadata": {}, "outputs": [], "source": [ "metis_m['grating_efficiency'].include = True\n", "metis_m.observe(src, update=True)\n", "sim_m_with_effic = metis_m.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "c7503615", "metadata": {}, "outputs": [], "source": [ "metis_m['grating_efficiency'].include = False\n", "metis_m.observe(src, update=True)\n", "sim_m_without_effic = metis_m.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "1d538045", "metadata": {}, "outputs": [], "source": [ "ratio_m = sim_m_with_effic / sim_m_without_effic\n", "plt.figure(figsize=(15, 5))\n", "plt.subplot(131)\n", "plt.imshow(sim_m_with_effic, origin='lower')\n", "plt.title(\"M band, with grating efficiency\")\n", "plt.subplot(132)\n", "plt.imshow(sim_m_without_effic, origin='lower')\n", "plt.title(\"M band, with grating efficiency\")\n", "plt.subplot(133)\n", "plt.imshow(ratio_m, origin='lower')\n", "plt.title(\"M band, ratio\");" ] }, { "cell_type": "code", "execution_count": null, "id": "8eff13df", "metadata": {}, "outputs": [], "source": [ "plt.plot(ratio_m[:, 1000]);" ] }, { "cell_type": "markdown", "id": "907e5766", "metadata": {}, "source": [ "## N band" ] }, { "cell_type": "code", "execution_count": null, "id": "60a1aa82", "metadata": {}, "outputs": [], "source": [ "cmd_n = sim.UserCommands(use_instrument='METIS', set_modes=['lss_n'])\n", "metis_n = sim.OpticalTrain(cmd_n)" ] }, { "cell_type": "code", "execution_count": null, "id": "d52d1788", "metadata": {}, "outputs": [], "source": [ "metis_n['psf'].include = False # PSF is not necessary for slit-filling source\n", "metis_n['skycalc_atmosphere'].include = False # sky lines obscure flat spectrum " ] }, { "cell_type": "code", "execution_count": null, "id": "e75cc80d", "metadata": {}, "outputs": [], "source": [ "metis_n['grating_efficiency'].include = True\n", "metis_n.observe(src, update=True)\n", "sim_n_with_effic = metis_n.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "17fddec7", "metadata": {}, "outputs": [], "source": [ "metis_n['grating_efficiency'].include = False\n", "metis_n.observe(src, update=True)\n", "sim_n_without_effic = metis_n.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "id": "1a4f11b6", "metadata": {}, "outputs": [], "source": [ "ratio_n = sim_n_with_effic / sim_n_without_effic\n", "plt.figure(figsize=(15, 5))\n", "plt.subplot(131)\n", "plt.imshow(sim_n_with_effic, origin='lower')\n", "plt.title(\"N band, with grating efficiency\")\n", "plt.subplot(132)\n", "plt.imshow(sim_n_without_effic, origin='lower')\n", "plt.title(\"N band, with grating efficiency\")\n", "plt.subplot(133)\n", "plt.imshow(ratio_n, origin='lower')\n", "plt.title(\"N band, ratio\");" ] }, { "cell_type": "code", "execution_count": null, "id": "f27b7712", "metadata": {}, "outputs": [], "source": [ "plt.plot(ratio_n[:, 1000]);" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }