In [ ]:
import h5py
import numpy as np
import matplotlib
matplotlib.rcParams['figure.dpi'] = 150
import matplotlib.pyplot as plt

Read the hdf5 file using h5py


In [ ]:
h5f = h5py.File('apec_emissivity_v2.h5', 'r')

It works similar to a dictionary in python. We can print the keys and values in this file.


In [ ]:
for k, v in h5f.items():
    print(k, v)

There are 4 datasets in this file, E, emissivity_metals, emissivity_primordial, and log_T.

E is a 1D array that has 151 numbers. These are the edges of the energy bin.

log_T is a 1D array that has 100 numbers.

emissivity_metals and emissivity_primordial are 2D arrays that have 100 by 150. These are the average emissivity in each energy bin corresponding to the 100 temperatures in log_T. The unit is in [erg/s/keV$\cdot$cm$^3$].

Use h5f['key'].value To acceess the data. For example, to get the energy bins


In [ ]:
h5f['E'].value

This will read all the data into memory


In [ ]:
E = h5f['E'].value
emis_primordial = h5f['emissivity_primordial'].value
emis_metals = h5f['emissivity_metals'].value
log_T = h5f['log_T'].value

# Close the file as we don't need it anymore
h5f.close()

How to get the energy differences in each bin as an array?


In [ ]:
dE = E[1:] - E[:-1]
print(dE.shape)
print(dE)

In [ ]:

Exercise 0a: How to get the average energy in each energy bin as an array?


In [ ]:

Exercise 1a: Plot the spectrum (emissivity as a function of energy) at T = 10^6 K

Hint: np.argmin might be useful.


In [ ]:

Exercise 1b: Plot the spectrum at T = 10^7 K


In [ ]:

Exercise 1c: Plot the spectrum at T = 10^8 K


In [ ]:

Exercise 2a: Plot the cooling function (emissivity as a function of T) in the energy range from 0.1 to 100 keV with metallicity Z=1.


In [ ]:

Exercise 2b: Plot the cooling function in the three energy bands that you chose for the 3-color image

Hint: Use the masks in python to select the energy range (http://danielandreasen.github.io/:about/2015/01/19/masks-in-python/)


In [ ]:


In [ ]: