Skip to content

Instantly share code, notes, and snippets.

@jzuhone
Created July 9, 2014 23:13
Show Gist options
  • Save jzuhone/970931864f3acf2c5760 to your computer and use it in GitHub Desktop.
Save jzuhone/970931864f3acf2c5760 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"celltoolbar": "Slideshow",
"name": "",
"signature": "sha256:271f9935861182bb77d0e21146a1fd7d6a9abcc1ca24a0191963bba659a75940"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from yt.funcs import mylog\n",
"import logging\n",
"mylog.setLevel(logging.ERROR)\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Simulating X-ray Observations with Python\n",
"\n",
"### John ZuHone (NASA/GSFC, U. Maryland)\n",
"\n",
"with \n",
"\n",
"Veronica Biffi (SISSA), Eric Hallman (U. Colorado), \n",
"Scott Randall (Harvard-CfA), Adam Foster (Harvard-CfA), \n",
"Christian Schmid (Dr. Karl Remeis-Sternwarte & ECAP)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## X-ray Astronomy Probes the High-Energy Universe"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* High-temperature plasmas (galaxy clusters, solar corona)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Relativistic cosmic rays (inverse-Compton scattering of the CMB, active galactic nuclei)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"telescopes.png\" align=\"center\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"xrays.png\" align=\"center\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Small-Number Statistics!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"counts.png\" align=\"center\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Image credit Dan Wik, NASA/GSFC"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Simulations vs. Observations"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Simulations are 3D (well, the best ones are); observations are 2D projections"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Simulations consist of physical quantities like density, temperature, velocity, composition; observations are collections of photons which are emitted from physical processes that depend on those quantities"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Simulations generally only model what you put into them (we hope); observations include contaminating backgrounds and instrumental effects"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Bridging the Gap with PHOX"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Biffi et al 2012, ApJ; http://www.mpa-garching.mpg.de/~kdolag/Phox/"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Most previous attempts at generating synthetic X-ray observations generated flux images projected along a line of sight, then used this image as a map to generate photon samples"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* This works well, but if you want to simulate observations along many different lines of sight for many different instruments, it's expensive"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* ``PHOX`` takes a different approach; generate a large sample of photons in 3D first (the most expensive step) ONCE (essentially discretize the photon emissivity function)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Then every time you want to make an observation, you simply draw a subset of them and project along a line of sight"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"pipeline.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Why use yt?"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* http://yt-project.org"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* If you really want to know, you should come to Nathan Goldbaum's talk at 3:50 in this room!"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Reads simulation data from a variety of simulation codes (FLASH, Enzo, Gadget, etc.)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Provides windows onto the data that make more sense from a *physical* perspective, not only a *computational* perspective"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Instead of thinking about cells, particles, and I/O, think about things like spheres, disks, fields, etc."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Make use of the rest of the scientific Python ecosystem for astronomy (SciPy, AstroPy, APLpy, etc.)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Creating a Synthetic Observation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* This example code will be in the proceedings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* As well as a notebook at http://www.jzuhone.com/files/photon_simulator_example.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* This code will be implemented in ``yt`` v. 3.0 beta (though it is also part of the current stable version, 2.6.2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* ``yt.analysis_modules.photon_simulator``"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"import yt\n",
"from yt.analysis_modules.photon_simulator.api \\\n",
" import TableApecModel, ThermalPhotonModel, \\\n",
" PhotonList, TableAbsorbModel\n",
"from yt.utilities.cosmology import Cosmology"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"parameters={\"time_unit\":(1.0,\"Myr\"),\n",
" \"length_unit\":(1.0,\"Mpc\"),\n",
" \"mass_unit\":(1.0e14,\"Msun\")}\n",
"\n",
"ds = yt.load(\"MHDSloshing/virgo_low_res.0054.vtk\",\n",
" parameters=parameters)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"sp = ds.sphere(\"c\", (250., \"kpc\"))"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"sloshing.png\" align=\"center\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Step 1: Generating the Original Photon Sample"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Models for Generating Photons"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Imagine we have some extended object with density, temperature, velocity, metallicity, etc. as a function of position"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Spectral models define a X-ray emissivity in ${\\rm photons~s^{-1}~cm^{-3}~keV^{-1}}$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"schematic.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Emissivity:\n",
"\n",
"$\\epsilon_E^\\gamma = n_en_H\\Lambda_E(T,Z)~{\\rm photons~s^{-1}~cm^{-3}~keV^{-1}}$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"model_spec.png\">"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"atomdb_path = \"/Users/jzuhone/Data/atomdb\"\n",
"\n",
"apec_model = TableApecModel(atomdb_path,\n",
" 0.01, 10.0, 2000,\n",
" apec_vers=\"2.0.2\",\n",
" thermal_broad=False)"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"thermal_model = ThermalPhotonModel(apec_model, \n",
" X_H=0.75, \n",
" Zmet=0.3)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## How many photons?"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* We want a *large* number of photons compared to the amount we might expect to get in an observation, so that the sample is statistically representative."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* The number of photons received by the observer is basically determined by the distance to the source $D_A$, the collecting area of the instrument $A_{\\rm det}$, and the exposure time of the instrument $t_{\\rm exp}$."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* So choose values for these parameters that are much larger than realistic values"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Flux: \n",
"\n",
"$F^{\\gamma}_i = \\frac{\\Delta{V}_i\\int{\\epsilon_E^\\gamma}dE}{4\\pi{D_{A,0}^2}(1+z_0)^2}~{\\rm photons~s^{-1}~cm^{-2}}$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"Number of Photons:\n",
" \n",
"$N_{\\rm phot} = t_{\\rm exp,0}A_{\\rm det,0}\\displaystyle\\sum_i{F^{\\gamma}_i}~{\\rm photons}$"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"A = 6000. # must be in cm**2!\n",
"exp_time = 4.0e5 # must be in seconds!\n",
"redshift = 0.05\n",
"cosmo = Cosmology() # WMAP7 cosmology by default, \n",
" # can pass in other values for parameters"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"photons = PhotonList.from_scratch(sp, redshift, A, \n",
" exp_time,\n",
" thermal_model, \n",
" center=\"c\",\n",
" cosmology=cosmo)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"photons.write_h5_file(\"my_photons.h5\")\n",
"#photons = PhotonList.from_file(\"my_photons.h5\")"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Step 2: Projecting Photons to Create Observations"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<img src=\"schematic.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"We need to choose a line-of-sight vector $\\hat{n}$ along which the 3D photons will be projected to produce an image. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"L = [0.0,0.0,1.0] # line-of-sight vector"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"The photons will be Doppler-shifted according to the velocity of the local gas element. They will also be redshifted by the cosmological expansion.\n",
"\n",
"$E_1 = E_0\\sqrt{\\frac{c+v_{z'}}{c-v_{z'}}}\\frac{1}{1+z}$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Some photons get absorbed by foreground galactic gas. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"N_H = 0.1 # 10^22 cm**-2\n",
"a_mod = TableAbsorbModel(\"tbabs_table.h5\", N_H) "
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"How many photons get observed?\n",
"\n",
"$f = \\frac{t_{\\rm exp}}{t_{\\rm exp,0}}\\frac{A_{\\rm det}}{A_{\\rm det,0}}\\frac{D_{A,0}^2}{D_A^2}\\frac{(1+z_0)^3}{(1+z)^3}$"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"texp = 1.0e5 # realistic exposure\n",
"z = 0.07 # realistic redshift"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"events = photons.project_photons(L, \n",
" exp_time_new=texp, \n",
" redshift_new=z, \n",
" absorb_model=a_mod)"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Step 3: Modeling Instrumental Effects"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"* Real astronomical instruments have a number of effects that alter the distribution of photons that is actually \"observed\"."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* The \"effective area\" of the instrument is typically energy-dependent. Encapsulated in an \"ancillary response file\" (ARF)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* The photon energies are mapped to CCD channels in a non-trivial way. Encapsulated in an \"redistribution matrix file\" (RMF)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* The ``photon_simulator`` analysis module provides a simple way to convolve photons with these responses. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ARF = \"chandra_ACIS-S3_onaxis_arf.fits\"\n",
"RMF = \"chandra_ACIS-S3_onaxis_rmf.fits\"\n",
"resp = [ARF,RMF]"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"events = photons.project_photons(L, \n",
" exp_time_new=texp, \n",
" redshift_new=z, \n",
" absorb_model=a_mod,\n",
" responses=resp)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"* However, sometimes a fuller simulation of a particular instrument is needed. "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"* For this, we provide output formats for export to existing software packages for simulating X-ray instruments."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"For the ``MARX`` *Chandra* simulator, an HDF5 format in conjunction with a user source model:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"events.write_h5_file(\"my_events.h5\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"For ``SIMX`` and ``Sixte``, two packages that simulate a variety of instruments, output in the ``SIMPUT`` format:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"events = photons.project_photons(L, \n",
" exp_time_new=texp, \n",
" redshift_new=z, \n",
" absorb_model=a_mod)"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"events.write_simput_file(\"my_events\", \n",
" clobber=True, \n",
" emin=0.1, emax=10.0)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Image"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"<img src=\"aplpy_figure.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Spectrum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"spectrum.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Simulate Different Instruments"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"<img src=\"comparison.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"* You don't have to use data from a simulation\n",
"* In-memory datasets based on NumPy arrays work too!\n",
"* Spherically symmetric cluster with bubbles evacuated"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"bubbles.png\" align=\"center\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Summary\n",
"\n",
"* Bridging the gap between simulations and observations is essential in astrophysics\n",
"* Implemented a synthetic X-ray observation generator (based on ``PHOX``) in ``yt``\n",
"* Great for use for comparison with real observations, or as a tool for proposals\n",
"* ``yt.analysis_modules.photon_simulator``\n",
"* http://yt-project.org/docs/dev-3.0/analyzing/analysis_modules/photon_simulator.html"
]
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment