{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook demonstrates the use of the `FilterWheel` in Scopesim. The METIS configuration contains two instances of this effect, named `filter_wheel` (for science filters) and `nd_filter_wheel` (for neutral-density filters). Each filter wheel contains a number of predefined filters, with different filter sets for the LM- and N-band imagers. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from matplotlib import pyplot as plt\n", "from matplotlib.colors import LogNorm\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import scopesim as sim\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": "markdown", "metadata": {}, "source": [ "If you haven't got the instrument packages yet, uncomment the following cell." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sim.download_packages([\"METIS\", \"ELT\", \"Armazones\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cmd = sim.UserCommands(use_instrument=\"METIS\", set_modes=['img_lm'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The filter to use is defined by setting `!OBS.filter_name`. In `img_lm` mode, it defaults to the Lp filter:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cmd['!OBS.filter_name']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis = sim.OpticalTrain(cmd)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The METIS package defines the list of filters that are available in the real instrument:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].filters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At any moment one of these filters is in the optical path and used for the simulation. Initially, this is the one set by `!OBS.filter_name`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].current_filter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The current filter can be changed to any of the filters in the list:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].change_filter(\"PAH_3.3\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].current_filter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Observing the same source in different filters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "src = sim.source.source_templates.empty_sky()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].change_filter(\"Lp\")\n", "\n", "metis.observe(src)\n", "img_Lp = metis.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].change_filter(\"PAH_3.3\")\n", "\n", "metis.observe(src, update=True)\n", "img_PAH = metis.image_planes[0].data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Background in Lp: {:8.1f} counts/s\".format(np.median(img_Lp)))\n", "print(\"Background in PAH_3.3: {:8.1f} counts/s\".format(np.median(img_PAH)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using the neutral-density filter wheel\n", "\n", "METIS also has neutral-density filters that can be inserted and changed using the `nd_filter_wheel` effect. The transmission of the filter `ND_ODx` is $10^{-x}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['nd_filter_wheel'].filters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['nd_filter_wheel'].current_filter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Observe a bright star (default arguments result in Vega at 0 mag) in the Lp filter. It will be found that the star saturates the detector in the open position, and requires the `ND_OD4` filter not to do so." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "star = sim.source.source_templates.star()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].change_filter('Lp')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['nd_filter_wheel'].change_filter(\"open\")\n", "metis.observe(star, update=True)\n", "hdu_open = metis.readout()[0][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['nd_filter_wheel'].change_filter(\"ND_OD3\")\n", "metis.observe(star, update=True)\n", "hdu_OD3 = metis.readout()[0][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['nd_filter_wheel'].change_filter(\"ND_OD4\")\n", "metis.observe(star, update=True)\n", "hdu_OD4 = metis.readout()[0][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure(figsize=(15, 4))\n", "plt.subplot(131)\n", "plt.imshow(hdu_open.data[700:1350, 700:1350], origin='lower', norm=LogNorm(vmin=1e-3, vmax=2e6))\n", "plt.colorbar()\n", "plt.subplot(132)\n", "plt.imshow(hdu_OD3.data[700:1350, 700:1350], origin='lower', norm=LogNorm(vmin=1e-3, vmax=2e6))\n", "plt.colorbar()\n", "plt.subplot(133)\n", "plt.imshow(hdu_OD4.data[700:1350, 700:1350], origin='lower', norm=LogNorm(vmin=1e-3, vmax=2e6))\n", "plt.colorbar();" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, figsize=(15, 4))\n", "\n", "ax1.plot(hdu_open.data[800:1250, 1024])\n", "ax1.set_title(\"ND filter: open\")\n", "ax2.plot(hdu_OD3.data[800:1250, 1024])\n", "ax2.set_title(\"ND filter: 1e-3\")\n", "ax3.plot(hdu_OD4.data[800:1250, 1024])\n", "ax3.set_title(\"ND filter: 1e-4\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Adding a custom filter to the filter wheel\n", "A custom filter that is not in the default filter set can be added to the wheel using the method `add_filter`. A \"filter\" is an object of class `TERCurve` (or one of its subclasses) and the various methods for instantiating such an object can be used." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "newfilter = sim.effects.ter_curves.TopHatFilterCurve(transmission=0.9, blue_cutoff=3.8, red_cutoff=3.9, \n", " name=\"custom_tophat\")\n", "metis['filter_wheel'].add_filter(newfilter)\n", "metis['filter_wheel'].filters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "metis['filter_wheel'].change_filter(\"custom_tophat\")\n", "metis['filter_wheel'].current_filter.plot();" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 4 }