{ "cells": [ { "cell_type": "markdown", "id": "coral-wright", "metadata": {}, "source": [ "# Source : from FITS images\n", "\n", "We can use a FITS image as the Source object for a ScopeSim Simulation\n", "\n", "**Warning: The simulation output is only as good as the input**\n", " \n", " If the pixel scale of the input (`CDELTn`) is bigger than the pixel scale of the instrument, ScopeSim will simply interpolate the image.\n", " \n", " Please don't expect wonders if the input image WCS information is not appropriate for the instrument you are using.\n", " \n", "ScopeSim Source objects can be generated from fits.ImageHDU object in the following ways: \n", " \n", "1. Just an Image and scaling flux value \n", "2. An Image and the associated synphot Spectrum\n", "3. An Image and arrays for wavelength and flux\n", " \n", "- ``image_hdu=`` + ``flux=``\n", "- ``image_hdu=`` + ``spectra=``\n", "- ``image_hdu=`` + ``lam=`` + ``spectra=``\n" ] }, { "cell_type": "code", "execution_count": null, "id": "armed-tampa", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scipy\n", "import astropy.io.fits as fits\n", "from astropy import units as u\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "import scopesim\n", "\n", "# Make an ImageHDU with some pixel data\n", "hdu = fits.ImageHDU(data=scipy.misc.face(gray=True))\n", "\n", "# Give the header some proper WCS info\n", "hdu.header.update({\"CDELT1\": 1, \"CUNIT1\": \"arcsec\", \"CRPIX1\": 0, \"CRVAL1\": 0,\n", " \"CDELT2\": 1, \"CUNIT2\": \"arcsec\", \"CRPIX2\": 0, \"CRVAL2\": 0,})\n", "\n", "\n", "# plotting function for later\n", "def plot(src):\n", " plt.figure(figsize=(12, 5))\n", " plt.subplot(121)\n", " wave = range(3000, 25000)\n", " plt.plot(wave, image_source.spectra[0](wave))\n", " plt.xlabel(\"Wavelength [Angstrom]\")\n", " plt.ylabel(\"Flux [ph/s/cm2/Angstrom]\")\n", " plt.subplot(122)\n", " plt.imshow(image_source.fields[0].data)" ] }, { "cell_type": "markdown", "id": "abstract-medication", "metadata": {}, "source": [ "## 1. Just an Image and scaling flux value \n", "\n", "``image_hdu=`` + ``flux=``\n", "\n", "It is assumed that the flux definied here is **integrated** flux and is the total flux contained in the image.\n", "\n", "**Note: In future version, header keywords like `BUNIT` etc will also be accepted. This functionality is not yet implemented though (April 2022).**" ] }, { "cell_type": "code", "execution_count": null, "id": "viral-holly", "metadata": {}, "outputs": [], "source": [ "image_source = scopesim.Source(image_hdu=hdu, flux=10*u.ABmag)\n", "\n", "plot(image_source)" ] }, { "cell_type": "markdown", "id": "agreed-stock", "metadata": {}, "source": [ "## 2. An Image and the associated synphot Spectrum\n", "\n", "``image_hdu=`` + ``spectra=``\n", "\n", "In this case, the image pixel values are seen as multipiers for the spectrum at a given coordinate.\n", "\n", "**Note: It is the users responsibility to make sure the total flux of the \"cube\" (image * spectrum) is scaled appropriately.**" ] }, { "cell_type": "code", "execution_count": null, "id": "moral-messaging", "metadata": {}, "outputs": [], "source": [ "# Alternatively, see the SpeXtra and Pyckles libraries for more spectra\n", "vega_spec = scopesim.source.source_templates.vega_spectrum(mag=20)\n", "\n", "image_source = scopesim.Source(image_hdu=hdu, spectra=[vega_spec])\n", "\n", "plot(image_source)" ] }, { "cell_type": "markdown", "id": "convinced-biography", "metadata": {}, "source": [ "## 3. An Image and arrays for wavelength and flux\n", "\n", "``image_hdu=`` + ``lam=`` + ``spectra=``" ] }, { "cell_type": "code", "execution_count": null, "id": "center-latex", "metadata": {}, "outputs": [], "source": [ "n = 100\n", "wavelengths = np.geomspace(0.3, 2.5, n) * u.um\n", "flux = np.ones(n)\n", "\n", "image_source = scopesim.Source(image_hdu=hdu, lam=wavelengths, spectra=np.array([flux]))\n", "\n", "plot(image_source)" ] } ], "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.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }