This notebook show how to do source detection with Gammapy using one of the methods available in gammapy.detect.
We will do this:
Note that what we do here is a quick-look analysis, the production of real source catalogs use more elaborate procedures.
We will work with the following functions and classes:
As always, let's get started with some setup ...
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from gammapy.maps import Map
from gammapy.detect import TSMapEstimator, find_peaks
from gammapy.catalog import source_catalogs
from gammapy.cube import PSFKernel
We first read in the counts cube and sum over the energy axis:
counts = Map.read("$GAMMAPY_DATA/fermi-3fhl-gc/fermi-3fhl-gc-counts.fits.gz")
background = Map.read(
"$GAMMAPY_DATA/fermi-3fhl-gc/fermi-3fhl-gc-background.fits.gz"
)
exposure = Map.read(
"$GAMMAPY_DATA/fermi-3fhl-gc/fermi-3fhl-gc-exposure.fits.gz"
)
maps = {"counts": counts, "background": background, "exposure": exposure}
kernel = PSFKernel.read(
"$GAMMAPY_DATA/fermi-3fhl-gc/fermi-3fhl-gc-psf.fits.gz"
)
%%time
estimator = TSMapEstimator()
images = estimator.run(maps, kernel.data)
plt.figure(figsize=(15, 5))
images["sqrt_ts"].plot(add_cbar=True);
plt.figure(figsize=(15, 5))
images["flux"].plot(add_cbar=True, stretch="sqrt", vmin=0);
plt.figure(figsize=(15, 5))
images["niter"].plot(add_cbar=True);
Let's run a peak finder on the sqrt_ts
image to get a list of sources (positions and peak sqrt_ts
values).
sources = find_peaks(images["sqrt_ts"], threshold=8)
sources
# Plot sources on top of significance sky image
plt.figure(figsize=(15, 5))
_, ax, _ = images["sqrt_ts"].plot(add_cbar=True)
ax.scatter(
sources["ra"],
sources["dec"],
transform=plt.gca().get_transform("icrs"),
color="none",
edgecolor="w",
marker="o",
s=600,
lw=1.5,
);
# TODO
TODO
fermi_3fhl = source_catalogs["3fhl"]
selection = counts.geom.contains(fermi_3fhl.positions)
fermi_3fhl.table = fermi_3fhl.table[selection]
fermi_3fhl.table[["Source_Name", "GLON", "GLAT"]]
TODO: put one or more exercises
# Start exercises here!
In this notebook, we have seen how to work with images and compute TS images from counts data, if a background estimate is already available.
Here's some suggestions what to do next: