Skip to content

bsafdi/NPTFit

Repository files navigation

NPTFit

Non-Poissonian template fitting in Python/Cython

Build Status Code Coverage Documentation Status License: MIT arXiv

AUTHORS

  • Benjamin Safdi; bsafdi at mit dot edu
  • Nicholas Rodd; nrodd at mit dot edu
  • Siddharth Mishra-Sharma; smsharma at princeton dot edu

A full list of the people who have contributed to NPTFit can be found here: AUTHORS.txt.

If you make use of NPTFit in a publication, please cite 1612.03173.

INSTALLATION AND DEPENDENCIES

Out of the box, NPTFit relies on MultiNest for Bayesian inference, which must be installed and linked prior to use. See here for a helpful set of installation instructions.

NPTFit supports both Python 2 and 3, specifically 2.7 and 3.5. It may work with earlier 3.* versions, although this has not been tested.

Make sure Cython is installed (e.g. pip install Cython). The easiest way to install NPTFit along with its dependent Python packages is using pip:

$ pip install NPTFit

NB: The pip install version is not always completely up to date.

The most up to date version is available through this repository, and can be installed using the setup script:

$ python setup.py install

which also builds the Cython modules. To just compile the Cython modules locally:

$ make build

NPTFit uses either GSL (faster) or mpmath for back-end calculations. By default, the GSL version is compiled during setup if this is available and linked, in which case the setup script concludes with "GSL compilation successful!". Otherwise, "mpmath compilation successful!" is shown.

The code is parallelizable through MPI (e.g. OpenMPI), which can considerably speed up computationally intensive scans. This requires the MPI4Py Python package for use with MultiNest, which can be installed, for example, with pip:

$ pip install mpi4py

DOCUMENTATION AND EXAMPLES

Detailed documentation of the code can be found here. There we also provide a series of examples, all of which are also available either in the form of interactive Jupyter notebooks, found here.

BASIC USAGE

Here's how easy it is to perform a non-Poissonian template fit with NPTFit.

# Import modules
import numpy as np
from NPTFit import nptfit # module for performing scan
from NPTFit import create_mask as cm # module for creating the mask
from NPTFit import psf_correction as pc # module for determining the PSF correction
from NPTFit import dnds_analysis # module for analysing the output

# Initiate NPTF
n = nptfit.NPTF()

# Load data and templates
fermi_data = np.load('fermi_data/fermidata_counts.npy').astype(np.int32)
fermi_exposure = np.load('fermi_data/fermidata_exposure.npy')
iso_temp = np.load('fermi_data/template_iso.npy')

n.load_data(fermi_data, fermi_exposure)
n.add_template(iso_temp, 'iso')
n.add_template(np.ones(len(iso_temp)), 'iso_ps', units='PS')

# Define the Region of Interest with a Mask
analysis_mask = cm.make_mask_total(mask_ring=True, inner=0, outer=5, ring_b=90, ring_l=0)
n.load_mask(analysis_mask)

# Add a Poissonian and non-Poissonian model
n.add_poiss_model('iso','$A_\mathrm{iso}$', False, fixed=True, fixed_norm=1.47)
n.add_non_poiss_model('iso_ps',
                      ['$A^\mathrm{ps}_\mathrm{iso}$','$n_1$','$n_2$','$S_b$'],
                      [[-6,1],[2.05,30],[-2,1.95]],
                      [True,False,False],
                      fixed_params = [[3,22.]])

# Calculate the PSF Correction
pc_inst = pc.PSFCorrection(psf_sigma_deg=0.1812)
f_ary = pc_inst.f_ary
df_rho_div_f_ary = pc_inst.df_rho_div_f_ary

# Configure and perform scan
n.configure_for_scan(f_ary=f_ary, df_rho_div_f_ary=df_rho_div_f_ary)
n.perform_scan(nlive=500)

An interactive version of this example can be found in the example here.

The following source-count distribution is an unmasked version of the one produced in this example, which analyzed the output of this example exploring the point source origin of the galactic center excess.

SourceCount

ISSUES

Problems with the code should be reported to the authors, or preferably noted through the issue tracker.