{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Appendix: Creating an Imager Scene\n", "Using the components of Skysim, this notebook generates the scene which is used in the user guide as an example. Please note that the target fluxes used here are exagerated so that they will appear in the single frame (un-calibrated) data produced by the example imager simulation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# import the types of objects to be placed in the scene\n", "\n", "# spatial\n", "from mirisim.skysim import Background, Point, SersicDisk\n", "\n", "# spectral\n", "from mirisim.skysim import sed\n", "\n", "#import the scene configuration parser\n", "from mirisim.config_parser import SceneConfig\n", "\n", "#other imports related to plotting, etc\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "\n", "scene = []" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setup two 'protoplanetary disks':\n", "\n", "Each disk will have the same inner and outer truncation radii, and the same blackbody function defined. The only difference between them will be their positions" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2020-08-04 14:59:42,644 - INFO - Initializing SersicDisk\n", "2020-08-04 14:59:42,645 - INFO - Initializing SersicDisk\n", "2020-08-04 14:59:42,646 - INFO - Initializing SersicDisk\n", "2020-08-04 14:59:42,646 - INFO - Initializing SersicDisk\n" ] } ], "source": [ "# setup a function to define the disks symmetrically \n", "# (with the position as the only difference)\n", "def setup_PD(cen): \n", " \n", " # setup the spatial part of the disk\n", " PD = SersicDisk(Cen = cen, # where to centre the disk\n", " pa = 90, # position angle of the min/maj. axes\n", " q = 0.7, # axis ratios\n", " n = 1, # sersic index (1 = expontential disk)\n", " re = 18, # scale length of disk\n", " rtrunc_in = 1., # where to truncate the inner rad.\n", " rtrunc_out = 3.25 # where to truncate the outer rad.)\n", " )\n", " \n", " # setup the spectral part of the disk\n", " BB = sed.BBSed(Temp=300., # Reference temperature for the BB\n", " flux=1.4e5, # flux [muJy] at the reference wavelength\n", " wref=10.) # ref wave. for flux scaling\n", " \n", " # attach the SED to the spatial spec. of the disk\n", " PD.set_SED(BB)\n", " \n", " return PD\n", " \n", " \n", "PD_one = setup_PD((-8,8))\n", "PD_two = setup_PD((8,8)) \n", " \n", " \n", "scene.append(PD_one)\n", "scene.append(PD_two)\n", " \n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup point sources:\n", "\n", "Place a number of point sources in the field of view. To show a different kind of SED, these are set with a power law SED with a power law index of 1." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2020-08-04 14:59:42,654 - INFO - Initializing Point\n", "2020-08-04 14:59:42,655 - INFO - Initializing Point\n", "2020-08-04 14:59:42,656 - INFO - Initializing Point\n", "2020-08-04 14:59:42,656 - INFO - Initializing Point\n", "2020-08-04 14:59:42,657 - INFO - Initializing Point\n", "2020-08-04 14:59:42,657 - INFO - Initializing Point\n", "2020-08-04 14:59:42,658 - INFO - Initializing Point\n", "2020-08-04 14:59:42,658 - INFO - Initializing Point\n", "2020-08-04 14:59:42,659 - INFO - Initializing Point\n", "2020-08-04 14:59:42,659 - INFO - Initializing Point\n", "2020-08-04 14:59:42,660 - INFO - Initializing Point\n", "2020-08-04 14:59:42,661 - INFO - Initializing Point\n", "2020-08-04 14:59:42,661 - INFO - Initializing Point\n", "2020-08-04 14:59:42,662 - INFO - Initializing Point\n", "2020-08-04 14:59:42,662 - INFO - Initializing Point\n", "2020-08-04 14:59:42,663 - INFO - Initializing Point\n", "2020-08-04 14:59:42,663 - INFO - Initializing Point\n" ] } ], "source": [ "def create_star(xpos,ypos):\n", " star = Point(Cen = (xpos,ypos))\n", " \n", " PLparams = {'alpha': 1,\n", " 'wref': 10.,\n", " 'flux': 120.}\n", " PowerLaw = sed.PLSed(**PLparams)\n", " star.set_SED(PowerLaw)\n", "\n", " return star\n", "\n", "\n", "# create a semi-circle of point sources in the bottom half of the FOVE\n", "\n", "Nstars = 35\n", "radius = 15\n", "for i in range(int(Nstars*0.5)+1,Nstars):\n", " xp = np.cos(2*np.pi/Nstars*i)*radius\n", " yp = np.sin(2*np.pi/Nstars*i)*radius\n", " star = create_star(xp,yp)\n", " scene.append(star)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Write scene to scene file\n", "\n", "So far, we have created an object list called 'scene'. This needs to be wrapped into a scene configuration, which is done by the 'SceneConfig' module.\n", "\n", "Here we also add the telescope background (set to low) to the scene configuration.\n", "\n", "It is this object (scene_config) that could be passed to a python instance of running MIRISim.\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2020-08-04 14:59:42,668 - INFO - Initializing Background\n" ] } ], "source": [ "# generate the scene using the scene configuration parser\n", "# (adding in a telescope background)\n", "scene_config = SceneConfig.makeScene(loglevel=0,\n", " background = Background(level='low',gradient=0,pa=0),\n", " targets = scene)\n", "\n", "# name of output scene file\n", "output_scene = 'Imager_scene.ini'\n", "\n", "# remove previous version of output INI file (if it exists)\n", "try:\n", " os.remove(output_scene)\n", "except OSError:\n", " pass\n", "\n", "\n", "# create output scene file\n", "\n", "scene_config.write(output_scene)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Optional write to FITS\n", "\n", "If you want to output the created scene to a FITS file, this is how to create a (small) field of view image centered at 10 microns (wrange)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "output_to_fits = False\n", "\n", "if output_to_fits == True:\n", "\n", " FOV = np.array([[-20,20],[-20,20]]) # 6x8\" field of view\n", " spatsampling = 0.1 # 0.1\" spatial sampling (resolution)\n", "\n", " # The wavelength range is specified in microns\n", " wrange = [9.5,10.5] # the output only covers 5 to 15 microns \n", " wsampling = 0.2 # 0.002 micron wavelength resolution\n", "\n", "\n", " scene.writecube(cubefits = 'scene.FITS',\n", " FOV = FOV, spatsampling = spatsampling, \n", " wrange = wrange, wsampling = wsampling,\n", " overwrite=True,time = 0.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.7" } }, "nbformat": 4, "nbformat_minor": 2 }