# Importing important modules
import numpy as np
from astropy.io import fits
from astropy.table import Table
import matplotlib.pyplot as plt
hdu_list = fits.open(path_to_file, memmap=True) ## Replace path_to_file by the location of the fits file
hdu_list.info() ## To see the contents of fits header
cat_data = Table(hdu_list[1].data) # Save the data in Table format
cat_data ## To see the content of the Table
keyname = 'Z_QSO' # type keyname (e.g. 'Z_ABS', 'Z_QSO', 'REST_EW_MGII_2796', ...)
hist_data = cat_data[keyname]
# histogram plotter
def plot_hist(hist_data, bins, ylog, xlabel, ylabel, fig_file=None):
fig = plt.figure(figsize=(6.5, 5.5))
ax = fig.add_subplot(111)
ax.hist(hist_data, bins=bins, alpha=0.5)
if ylog:
ax.set_yscale('log')
ax.set_xlabel(xlabel, fontsize=16)
ax.set_ylabel(ylabel, fontsize=16)
fig.tight_layout()
if fig_file is not None:
plt.savefig(fig_file)
else:
plt.show()
return None
plot_hist(hist_data, bins=50, ylog=True, xlabel='Redshifts', ylabel='Number of Absorbers', fig_file=None)
def plot_scatter_plot(xvals, yvals, xlog, ylog, xlabel, ylabel, fig_file):
fig = plt.figure(figsize=(6.5, 5.5))
ax = fig.add_subplot(111)
ax.scatter(xvals, yvals, color='g', s=2, marker='o', alpha=0.5, rasterized=True)
if ylog:
ax.set_yscale('log')
if xlog:
ax.set_xscale('log')
ax.set_xlabel(xlabel, fontsize=16)
ax.set_ylabel(ylabel, fontsize=16)
fig.tight_layout()
if fig_file is not None:
plt.savefig(fig_file)
else:
plt.show()
return None
x_key = 'Z_QSO' # type keyname (e.g. 'Z_ABS', 'Z_QSO', 'REST_EW_MGII_2796', ...)
y_key = 'Z_ABS' # type keyname (e.g. 'Z_ABS', 'Z_QSO', 'REST_EW_MGII_2796', ...)
xvals = cat_data[x_key]
yvals = cat_data[y_key]
plot_scatter_plot(xvals, yvals, xlog=False, ylog=False, xlabel='z_QSO', ylabel='z_MgII', fig_file=None)