{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Appendix: Creating a Scene in python\n",
"\n",
"A pre-defined sky scene can be injested into MIRISim, although the flexibility exists for the user to create their own custom scene. This notebook shows the steps required to create a viable (albeit simple) scene for use within mirisim. The equivalent code placed in a .ini file is given in parallel with the python definitions.\n",
"\n",
"This example creates a scene with two objects: a star, and an extended galaxy. Both have imported spectral energy distributions (SEDs) and a few additional spectral lines overlaid."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"## skysim is the module within MIRISim that creates scenes.\n",
"\n",
"from mirisim.skysim import Background, sed, kinetics,Galaxy, Point, Skycube\n",
"from mirisim.skysim import wrap_pysynphot as wS\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### setup the scene\n",
"\n",
"There is a short preamble required for a .ini file to be executable. There is no python equivalent, so it is mentioned here briefly before delving into the python aspects of creating a scene\n",
"\n",
" [sky]\n",
" name = scene1\n",
" loglevel = 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a Galaxy\n",
"\n",
"The first target to be created in this simple sky scene is a galaxy. The steps to creating a complete galaxy include:\n",
"\n",
"1. setting up the spatial extent of the galaxy\n",
"1. creating an SED to apply to the extended emission\n",
"1. Add the SED to the Galaxy\n",
"1. add a line of sight velocity distribution to the SED\n",
"\n",
"#### Step 1: Setup the spatial extent of the galaxy\n",
"\n",
"The galaxy created within python below has the same properties as this parameter grouping expressed in a .ini file::\n",
"\n",
" [Galaxy]\n",
" Type = Galaxy # Type of target\n",
" Cen = -2. 2. # RA,DEC (offset, specified in arcseconds)\n",
" n = 1. # Sersic index of the Galaxy\n",
" re = 0.1 # Effective radius (arcsec)\n",
" q = 0.5 # Axial ratio\n",
" pa = 15. # position angle (deg)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-08-04 14:54:20,864 - INFO - Initializing Galaxy\n",
"2020-08-04 14:54:20,864 - INFO - Initializing Galaxy\n",
"2020-08-04 14:54:20,865 - INFO - Initializing Galaxy\n"
]
}
],
"source": [
"galaxy = Galaxy(Cen=(-2.,2.),n=1.,re=0.1,q=0.5,pa=15.)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Step 2: Create a spectral energy distribution for the Galaxy\n",
"\n",
"Here we show an example of importing a pysynphot SED. The parameters required as input to a pysynphot SED can be found on the pysynphot website. note that the `sedname` must be consistent with one provided in the pysynphot directories, the location of which was set when mirisim was installed. To find it:\n",
"\n",
" echo $PYSYN_CDBS\n",
" \n",
"\n",
"The .ini file equivalent of creating this pysynphot SED in python is as follows. Note that when placed in a .ini file, this set of properties can be indented for clarity.\n",
"\n",
" [[sed]]\n",
" Type = pysynphot # specify SED from pySynPhot librarires\n",
" family = bkmodels # SED Family from which to draw.\n",
" sedname = bk_b0005 # Template within calatlogue to be used\n",
" wref = 10. # Reference wavelength for scaling (in micron)\n",
" flux = 1E+3 # Reference flux for scaling (in microJy)\n",
" \n",
" \n",
"The 'bkmodels' are the Buser-Kurucz stellar atmosphere models, more details of which can be found at [this link](http://www.stsci.edu/hst/observatory/crds/bkmodels.html). This model were chosen for this example because the SED extends to 20 micron. Most of the SEDs in the pysynphot repository do not reach MIRI wavelengths.\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# specify which of the pysynphot models to use (in a dictionary)\n",
"PYSPsedDict = {'family':'bkmodels','sedname':'bk_b0004','flux':1E+3,'wref':10.}\n",
"# read that dictionary into the pysynphot interpreter\n",
"sedE = wS.PYSPSed(**PYSPsedDict)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Step 3: Add the SED to the galaxy object\n",
"\n",
"The SED component can now be added to the properties of the galaxy created in Step 1. This step has no equivalent in the .ini file, as this is done automatically by placing the SEDs underneath the instance of `[Galaxy]`"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# link the SED to the galaxy object\n",
"galaxy.set_SED(sedE)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Step 4: add a velocity map to the Galaxy\n",
"\n",
"The template galaxy created here is expected to be rotating, which will shift the SED as a function of position within the galaxy. This is accounted for by applying a velocity map to the galaxy object. The .ini file equivalent of the python code below is:\n",
"\n",
" [[velomap]]\n",
" Type = FlatDisk # Type of Velocity map to initialise\n",
" Cen = -2. 2. # Specify the centre of the disk \n",
" vrot = 200. # Rotational Velocity (km/s)\n",
" pa = 15. # Position angle of the velocity map (deg)\n",
" q = 0.5 # Axial ratio of major and minor axes\n",
" c = 0. # measure of diskiness/boxiness \n",
" \n",
"Here, we've created a flattened galatic disk. Note that many of the parameters set here are identical to those set when initialising the galaxy at the beginning.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-08-04 14:54:20,934 - INFO - Initializing FlatDisk\n"
]
}
],
"source": [
"# Create a dictionary of parameters\n",
"VMAPpars = {'vrot':200.,'Cen':(-2.,2.),'pa':15.,'q':0.5,'c':0}\n",
"# create an instance of a flattened disk\n",
"velomap = kinetics.FlatDisk(**VMAPpars)\n",
"\n",
"\n",
"# apply the velocity mapping to the galaxy\n",
"\n",
"galaxy.set_velomap(velomap)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a \"Star\"\n",
"\n",
"Because a star is a point source, the inputs are a little simpler. An SED can (and should) still be specified (for this example a star is a simple blackbody), however there is no point in specifying a velocity distribution since all of the flux is coming from a single point.\n",
"\n",
"The steps involved in creating a star here include:\n",
"\n",
"1. initialising a point source\n",
"1. adding a blackbody spectrum\n",
"\n",
"The equivalent in a .ini file would entail:\n",
"\n",
" [Star]\n",
" Type = Point\n",
" Cen = 0. 0.\n",
" vel = 0.0\n",
"\n",
" [[sed]]\n",
" Type = BB\n",
" Temp = 1e4\n",
" flux = 100.\n",
" wref = 10.\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-08-04 14:54:20,940 - INFO - Initializing Point\n"
]
}
],
"source": [
"## 1. initialise the point source spatial position\n",
"star = Point(Cen=(0.,0.))\n",
"## 2a. create a dictionary with the required parameters for a blackbody\n",
"BBparams = {'Temp':1e4,'wref':10.,'flux':100.}\n",
"## 2b. create the blackbody spectrum\n",
"BlackBody = sed.BBSed(**BBparams)\n",
"## 2c. add that spectrum to the 'star'\n",
"star.set_SED(BlackBody)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a Scene from a star and a Galaxy\n",
"\n",
"The two components of the scene can now simply be added together to form a scene. To this two component scene, we will also (below) add some background radiation. The equivalent .ini file syntax for adding the background is:\n",
"\n",
" [Background]\n",
" level = low\n",
" gradient = 5.\n",
" pa = 45.\n",
" centreFOV = 0 0\n",
"\n",
"After completing the scene, a text description can be output to the screen using the print function\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-08-04 14:54:20,946 - INFO - Initializing Background\n"
]
}
],
"source": [
"# create a background object\n",
"bg = Background(level='low',gradient=5.,pa=45.)\n",
"\n",
"# sum the background,galaxy and star\n",
"scene = bg + galaxy + star\n",
"\n",
"## print the text version to the screen\n",
"#print(scene)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Exporting the scene to a FITS file\n",
"\n",
"With the scene created, there's now the oportunity to write it out to a FITS file. To do this requires additional specifications, including:\n",
"\n",
" * Field of View (FOV)\n",
" * Spatial Sampling (spatsampling)\n",
" * Output Wavelength Range (wrange)\n",
" * Wavelength Sampling (wsampling)\n",
" * Time (time)\n",
"\n",
"Note that the last parameter, time, needs to be specified for time dependent backgrounds only (which are not yet implemented).\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# The field of view and its sampling are specified in arcsecondsy\n",
"FOV = np.array([[-3,3],[-4,4]]) # 6x8\" field of view\n",
"spatsampling = 0.1 # 0.1\" spatial sampling (resolution)\n",
"\n",
"# The wavelength range is specified in microns\n",
"wrange = [5.,15.] # the output only covers 5 to 15 microns \n",
"wsampling = 0.002 # 0.002 micron wavelength resolution\n",
"\n",
"# Because time dependent backgrounds are not yet implemented, \n",
"# 'time' does not need to be set\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With the additional parameters pertaining to the properties of the output FITS file set, the scene created above can be output to a FITS file\n",
"\n",
"**NOTE:** The option overwrite = False ensures that any FITS file in the current directory with the suggested output file name exists, it will not be overwritten. To change this, set overwrite = True "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"scene.writecube(cubefits = 'scene.FITS',\n",
" FOV = FOV, spatsampling = spatsampling, \n",
" wrange = wrange, wsampling = wsampling,\n",
" overwrite = True, time = 0.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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": 1
}