FITS X-ray Images in ytΒΆ

Notebook
In [1]:
%matplotlib inline
import yt
import numpy as np

This notebook shows how to use yt to make plots and examine FITS X-ray images and events files.

Sloshing, Shocks, and Bubbles in Abell 2052

This example uses data provided by Scott Randall, presented originally in Blanton, E.L., Randall, S.W., Clarke, T.E., et al. 2011, ApJ, 737, 99. They consist of two files, a "flux map" in counts/s/pixel between 0.3 and 2 keV, and a spectroscopic temperature map in keV.

In [2]:
ds = yt.load("xray_fits/A2052_merged_0.3-2_match-core_tmap_bgecorr.fits", 
             auxiliary_files=["xray_fits/A2052_core_tmap_b1_m2000_.fits"])
/usr/lib64/python3.4/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
WARNING:yt:Cannot find time
WARNING:yt:No length conversion provided. Assuming 1 = 1 cm.

Since the flux and projected temperature images are in two different files, we had to use one of them (in this case the "flux" file) as a master file, and pass in the "temperature" file with the auxiliary_files keyword to load.

Next, let's derive some new fields for the number of counts, the "pseudo-pressure", and the "pseudo-entropy":

In [3]:
def _counts(field, data):
    exposure_time = data.get_field_parameter("exposure_time")
    return data["flux"]*data["pixel"]*exposure_time
ds.add_field(("gas","counts"), function=_counts, units="counts", take_log=False)

def _pp(field, data):
    return np.sqrt(data["counts"])*data["projected_temperature"]
ds.add_field(("gas","pseudo_pressure"), function=_pp, units="sqrt(counts)*keV", take_log=False)

def _pe(field, data):
    return data["projected_temperature"]*data["counts"]**(-1./3.)
ds.add_field(("gas","pseudo_entropy"), function=_pe, units="keV*(counts)**(-1/3)", take_log=False)
/var/jenkins_home/workspace/yt_docs/sandbox/temp/lib64/python3.4/site-packages/yt-3.3.5-py3.4-linux-x86_64.egg/yt/units/yt_array.py:1071: RuntimeWarning: divide by zero encountered in power
  return super(YTArray, self).__pow__(power)

Here, we're deriving a "counts" field from the "flux" field by passing it a field_parameter for the exposure time of the time and multiplying by the pixel scale. Second, we use the fact that the surface brightness is strongly dependent on density ($S_X \propto \rho^2$) to use the counts in each pixel as a "stand-in". Next, we'll grab the exposure time from the primary FITS header of the flux file and create a YTQuantity from it, to be used as a field_parameter:

In [4]:
exposure_time = ds.quan(ds.primary_header["exposure"], "s")

Now, we can make the SlicePlot object of the fields we want, passing in the exposure_time as a field_parameter. We'll also set the width of the image to 250 pixels.

In [5]:
slc = yt.SlicePlot(ds, "z", 
                   ["flux","projected_temperature","pseudo_pressure","pseudo_entropy"], 
                   origin="native", field_parameters={"exposure_time":exposure_time})
slc.set_log("flux",True)
slc.set_log("pseudo_pressure",False)
slc.set_log("pseudo_entropy",False)
slc.set_width(250.)
slc.show()
/usr/lib64/python3.4/site-packages/ipykernel/__main__.py:7: RuntimeWarning: invalid value encountered in sqrt
/var/jenkins_home/workspace/yt_docs/sandbox/temp/lib64/python3.4/site-packages/yt-3.3.5-py3.4-linux-x86_64.egg/yt/units/yt_array.py:1071: RuntimeWarning: divide by zero encountered in power
  return super(YTArray, self).__pow__(power)
/var/jenkins_home/workspace/yt_docs/sandbox/temp/lib64/python3.4/site-packages/yt-3.3.5-py3.4-linux-x86_64.egg/yt/units/yt_array.py:1071: RuntimeWarning: invalid value encountered in power
  return super(YTArray, self).__pow__(power)
/var/jenkins_home/workspace/yt_docs/sandbox/temp/lib64/python3.4/site-packages/yt-3.3.5-py3.4-linux-x86_64.egg/yt/units/yt_array.py:956: RuntimeWarning: invalid value encountered in multiply
  return super(YTArray, self).__mul__(ro)
WARNING:yt:Plot image for field ('fits', 'flux') has both positive and negative values. Min = -0.000000, Max = 0.001258.
WARNING:yt:Switching to symlog colorbar scaling unless linear scaling is specified later