{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Dark matter utilities\n", "\n", "## Introduction \n", "\n", "Gammapy has some convenience methods for dark matter analyses in [gammapy.astro.darkmatter](https://docs.gammapy.org/dev/astro/darkmatter/index.html). These include J-Factor computation and calculation the expected gamma flux for a number of annihilation channels. They are presented in this notebook. \n", "\n", "The basic concepts of indirect dark matter searches, however, are not explained. So this is aimed at people who already know what the want to do. A good introduction to indirect dark matter searches is given for example in https://arxiv.org/pdf/1012.4515.pdf (Chapter 1 and 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "As always, we start with some setup for the notebook, and with imports." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from gammapy.astro.darkmatter import (\n", " profiles,\n", " JFactory,\n", " PrimaryFlux,\n", " DMAnnihilation,\n", ")\n", "\n", "from gammapy.maps import WcsGeom, WcsNDMap\n", "from astropy.coordinates import SkyCoord\n", "from matplotlib.colors import LogNorm\n", "from regions import CircleSkyRegion\n", "import astropy.units as u\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Profiles\n", "\n", "The following dark matter profiles are currently implemented. Each model can be scaled to a given density at a certain distance. These parameters are controlled by ``profiles.DMProfile.LOCAL_DENSITY`` and ``profiles.DMProfile.DISTANCE_GC``" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "profiles.DMProfile.__subclasses__()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for profile in profiles.DMProfile.__subclasses__():\n", " p = profile()\n", " p.scale_to_local_density()\n", " radii = np.logspace(-3, 2, 100) * u.kpc\n", " plt.plot(radii, p(radii), label=p.__class__.__name__)\n", "\n", "plt.loglog()\n", "plt.axvline(8.5, linestyle=\"dashed\", color=\"black\", label=\"local density\")\n", "plt.legend()\n", "\n", "print(\n", " \"The assumed local density is {} at a distance to the GC of {}\".format(\n", " profiles.DMProfile.LOCAL_DENSITY, profiles.DMProfile.DISTANCE_GC\n", " )\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## J Factors\n", "\n", "There are utilies to compute J-Factor maps can can serve as a basis to compute J-Factors for certain regions. In the following we compute a J-Factor map for the Galactic Centre region" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "profile = profiles.NFWProfile()\n", "\n", "# Adopt standard values used in HESS\n", "profiles.DMProfile.DISTANCE_GC = 8.5 * u.kpc\n", "profiles.DMProfile.LOCAL_DENSITY = 0.39 * u.Unit(\"GeV / cm3\")\n", "\n", "profile.scale_to_local_density()\n", "\n", "position = SkyCoord(0.0, 0.0, frame=\"galactic\", unit=\"deg\")\n", "geom = WcsGeom.create(binsz=0.05, skydir=position, width=3.0, coordsys=\"GAL\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jfactory = JFactory(\n", " geom=geom, profile=profile, distance=profiles.DMProfile.DISTANCE_GC\n", ")\n", "jfact = jfactory.compute_jfactor()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jfact_map = WcsNDMap(geom=geom, data=jfact.value, unit=jfact.unit)\n", "fig, ax, im = jfact_map.plot(cmap=\"viridis\", norm=LogNorm(), add_cbar=True)\n", "plt.title(\"J-Factor [{}]\".format(jfact_map.unit))\n", "\n", "# 1 deg circle usually used in H.E.S.S. analyses\n", "sky_reg = CircleSkyRegion(center=position, radius=1 * u.deg)\n", "pix_reg = sky_reg.to_pixel(wcs=geom.wcs)\n", "pix_reg.plot(ax=ax, facecolor=\"none\", edgecolor=\"red\", label=\"1 deg circle\")\n", "plt.legend()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# NOTE: https://arxiv.org/abs/1607.08142 quote 2.67e21 without the +/- 0.3 deg band around the plane\n", "total_jfact = pix_reg.to_mask().multiply(jfact).sum()\n", "print(\n", " \"J-factor in 1 deg circle around GC assuming a \"\n", " \"{} is {:.3g}\".format(profile.__class__.__name__, total_jfact)\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Gamma-ray spectra at production\n", "\n", "The gamma-ray spectrum per annihilation is a further ingredient for a dark matter analysis. The following annihilation channels are supported. For more info see https://arxiv.org/pdf/1012.4515.pdf" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fluxes = PrimaryFlux(mDM=\"1 TeV\", channel=\"eL\")\n", "print(fluxes.allowed_channels)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, axes = plt.subplots(4, 1, figsize=(6, 16))\n", "mDMs = [0.01, 0.1, 1, 10] * u.TeV\n", "\n", "for mDM, ax in zip(mDMs, axes):\n", " fluxes.mDM = mDM\n", " ax.set_title(r\"m$_{{\\mathrm{{DM}}}}$ = {}\".format(mDM))\n", " ax.set_yscale(\"log\")\n", " ax.set_ylabel(\"dN/dE\")\n", "\n", " for channel in [\"tau\", \"mu\", \"b\", \"Z\"]:\n", " fluxes.channel = channel\n", " fluxes.table_model.plot(\n", " energy_range=[mDM / 100, mDM],\n", " ax=ax,\n", " label=channel,\n", " flux_unit=\"1/GeV\",\n", " )\n", "\n", "axes[0].legend()\n", "plt.subplots_adjust(hspace=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Flux maps\n", "\n", "Finally flux maps can be produced like this:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "channel = \"Z\"\n", "massDM = 10 * u.TeV\n", "diff_flux = DMAnnihilation(mass=massDM, channel=channel)\n", "int_flux = (jfact * diff_flux.integral(emin=0.1 * u.TeV, emax=10 * u.TeV)).to(\n", " \"cm-2 s-1\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flux_map = WcsNDMap(geom=geom, data=int_flux.value, unit=\"cm-2 s-1\")\n", "\n", "fig, ax, im = flux_map.plot(cmap=\"viridis\", norm=LogNorm(), add_cbar=True)\n", "plt.title(\n", " \"Flux [{}]\\n m$_{{DM}}$={}, channel={}\".format(\n", " int_flux.unit, fluxes.mDM.to(\"TeV\"), fluxes.channel\n", " )\n", ");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }