Fermi-LAT via FermiPyLike

In this Example we show how to use the fermipy plugin in threeML. We perform a Binned likelihood analysis and a Bayesian analysis of the Crab, optimizing the parameters of the Crab Pulsar (PSR J0534+2200) keeping fixed the parameters of the Crab Nebula. In the model, the nebula is described by two sources, one representing the synchrotron spectrum, the othet the Inverse Compton emission. In this example we show how to download Fermi-LAT data, how to build a model starting from the 4FGL, how to free and fix parameters of the sources in the model, and how to perform a spectral analysis using the fermipy plugin.

[2]:
%%capture
from threeML import *

The Fermi 4FGL catalog

Let’s interrogate the 4FGL to get the sources in a radius of 20.0 deg around the Crab

[4]:
lat_catalog = FermiLATSourceCatalog()

ra, dec, table = lat_catalog.search_around_source("Crab", radius=20.0)

table
Trying https://heasarc.gsfc.nasa.gov/cgi-bin/vo/cone/coneGet.pl?table=fermilpsc&
[4]:
Table masked=True length=147
namesource_typeshort_source_typeradecassoc_nametevcat_assocSearch_Offset
degdeg
objectstr32objectfloat64float64objectobjectfloat64
4FGL J0534.5+2200pulsar, identified by pulsationsPSR83.636722.0149PSR J0534+2200Crab pulsar0.2022
4FGL J0534.5+2201spulsar wind nebulaPWN83.633122.0199Crab NebulaCrab0.3243
4FGL J0534.5+2201ipulsar wind nebulaPWN83.633022.0200Crab NebulaCrab0.3304
4FGL J0526.3+2246active galaxy of uncertain typebcu81.590822.7778NVSS J052622+224801122.1994
4FGL J0544.4+2238unknown86.109322.6418142.4913
4FGL J0521.7+2112BL Lac type of blazarbll80.444521.2131TXS 0518+211VER J0521+211184.2435
4FGL J0528.3+1817unknownunk82.094618.29431RXS J052829.6+181657239.4351
4FGL J0536.2+1733BL Lac type of blazarbll84.071917.5534TXS 0533+175268.8090
4FGL J0539.0+1644active galaxy of uncertain typebcu84.750016.7432NVSS J053855+164612322.5278
........................
4FGL J0512.8+4041active galaxy of uncertain typebcu78.218640.6945B3 0509+4061153.9906
4FGL J0639.6+3503active galaxy of uncertain typebcu99.902435.0586B2 0635+351157.9315
4FGL J0552.8+0313active galaxy of uncertain typebcu88.21803.2322PKS 0550+0321158.1471
4FGL J0653.6+1636active galaxy of uncertain typebcu103.410516.61062MASX J06533986+16364321164.7254
4FGL J0658.7+2318unknown104.680823.30271166.9322
4FGL J0555.1+0304active galaxy of uncertain typebcu88.77763.0710GB6 J0555+03041175.4617
4FGL J0658.2+2709active galaxy of uncertain typebcu104.573527.1501B2 0655+27A1181.6921
4FGL J0642.4+1048unknown100.608110.81351183.9644
4FGL J0506.9+0323BL Lac type of blazarbll76.73143.3917NVSS J050650+0324011187.4462
4FGL J0409.2+2542unknown62.314425.70221189.1462

This gets a 3ML model (a Model instance) from the table above, where every source in the 4FGL becomes a Source instance. Note that by default all parameters of all sources are fixed.

[5]:
model = lat_catalog.get_model()

Let’s free all the normalizations within 3 deg from the center.

[6]:
model.free_point_sources_within_radius(3.0, normalization_only=True)

model.display()
Model summary:

N
Point sources 147
Extended sources 0
Particle sources 0


Free parameters (5):

value min_value max_value unit
PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2
Crab_synch.spectrum.main.Powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2
Crab_IC.spectrum.main.Log_parabola.K 0.0 0.0 0.0 keV-1 s-1 cm-2
NVSS_J052622p224801.spectrum.main.Powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2
_4FGL_J0544d4p2238.spectrum.main.Powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2


Fixed parameters (788):
(abridged. Use complete=True to see all fixed parameters)


Linked parameters (0):

(none)

Independent variables:

(none)

but then let’s fix the sync and the IC components of the Crab nebula (cannot fit them with just one month of data) (these two methods are equivalent)

[7]:
model["Crab_IC.spectrum.main.Log_parabola.K"].fix = True
model.Crab_synch.spectrum.main.Powerlaw.K.fix = True

However, let’s free the index of the Crab Pulsar

[8]:
model.PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.index.free = True

model.display()
Model summary:

N
Point sources 147
Extended sources 0
Particle sources 0


Free parameters (4):

value min_value max_value unit
PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2
PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.index -1.8833 -10.0 10.0
NVSS_J052622p224801.spectrum.main.Powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2
_4FGL_J0544d4p2238.spectrum.main.Powerlaw.K 0.0 0.0 0.0 keV-1 s-1 cm-2


Fixed parameters (789):
(abridged. Use complete=True to see all fixed parameters)


Linked parameters (0):

(none)

Independent variables:

(none)
[9]:
# Download data from Jan 01 2010 to February 1 2010

tstart = "2010-01-01 00:00:00"
tstop = "2010-02-01 00:00:00"

# Note that this will understand if you already download these files, and will
# not do it twice unless you change your selection or the outdir

evfile, scfile = download_LAT_data(
    ra,
    dec,
    20.0,
    tstart,
    tstop,
    time_type="Gregorian",
    destination_directory="Crab_data",
)

Configuration for Fermipy

3ML provides and intreface into Fermipy via the FermipyLike plugin. We can use it to generate basic configuration files.

Note

Currently, the FermipyLike plugin does not provide an interface to handle extended sources. This will change

[10]:
config = FermipyLike.get_basic_config(
    evfile=evfile,
    scfile=scfile,
    ra=ra,
    dec=dec,
    fermipy_verbosity=1,
    fermitools_chatter=0,
)

# See what we just got

config.display()
binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 100000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 100000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

You can of course modify the configuration as a dictionary

[11]:
config["selection"]["emax"] = 300000.0

and even add sections

[12]:
config["gtlike"] = {"edisp": False}

config.display()
binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
gtlike:
  edisp: false
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 300000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
gtlike:
  edisp: false
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 300000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

FermipyLike

Let’s create an instance of the plugin/ Note that here no processing is made, because fermipy still doesn’t know about the model you want to use.

[13]:
LAT = FermipyLike("LAT", config)

WARNING RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject


WARNING RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject


WARNING RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject

The plugin modifies the configuration as needed to get the output files in a unique place, which will stay the same as long as your selection does not change.

[14]:
config.display()
binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
fileio:
  outdir: __8934dcff054a8ef157affdb2477b8127
gtlike:
  edisp: false
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 300000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

binning:
  binsperdec: 8
  binsz: 0.1
  roiwidth: 10.0
data:
  evfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L31c0b303b32412d3ad16855dca6114b1_FT1.fits
  scfile: /Users/runner/work/threeML/threeML/docs/md_docs/Crab_data/L210527135425B096CEF293_SC00.fits
fileio:
  outdir: __8934dcff054a8ef157affdb2477b8127
gtlike:
  edisp: false
logging:
  chatter: 0
  verbosity: 1
selection:
  dec: 22.0144947866347
  emax: 300000.0
  emin: 100.0
  evclass: 128
  evtype: 3
  filter: DATA_QUAL>0 && LAT_CONFIG==1
  ra: 83.63309095468972
  tmax: 286675202.0
  tmin: 283996802.0
  zmax: 100.0

Here is where the fermipy processing happens (the .setup method)

[15]:
fermipy_output_directory = Path(config["fileio"]["outdir"])
print("Fermipy Output directoty: %s" % fermipy_output_directory)

# This remove the output directory, to start a fresh analysis...

if fermipy_output_directory.exists():
    shutil.rmtree(fermipy_output_directory)

# Here is where the fermipy processing happens (the .setup method)

data = DataList(LAT)

jl = JointLikelihood(model, data)
Fermipy Output directoty: __8934dcff054a8ef157affdb2477b8127

Found Galactic template for IRF. P8R3_SOURCE_V3: /usr/local/miniconda/envs/test_env/share/fermitools/refdata/fermi/galdiffuse/gll_iem_v07.fits

Cutting the template around the ROI:


Found Isotropic template for irf P8R3_SOURCE_V3: /usr/local/miniconda/envs/test_env/share/fermitools/refdata/fermi/galdiffuse/iso_P8R3_SOURCE_V3_v1.txt
WARNING: Point source PKS_0459p060 lies 17.6422 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4C_p06d21 lies 17.7201 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _1ES_0647p250 lies 17.7261 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source NVSS_J065035p205556 lies 17.7267 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0551d7p0446 lies 17.7358 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PSR_J0631p1036 lies 17.7822 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0648p1749 lies 17.8406 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0442d8p3609 lies 18.0652 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0552p39A lies 18.3298 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _1RXS_J064814d1p160708 lies 18.3613 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source MG2_J065230p1934 lies 18.3951 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PKS_0502p049 lies 18.4206 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source RX_J0648d7p1516 lies 18.8083 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0620p3806 lies 18.8393 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PSR_J0622p3749 lies 18.8555 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0653p2816 lies 18.9497 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PMN_J0444p0717 lies 18.9991 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source MG1_J050533p0415 lies 19.0814 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0559d3p0352 lies 19.115 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source TXS_0431p092 lies 19.119 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B3_0509p406 lies 19.2332 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0635p35 lies 19.2989 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PKS_0550p032 lies 19.3025 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _2MASX_J06533986p1636432 lies 19.4121 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0658d7p2318 lies 19.4489 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0555p0304 lies 19.591 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0655p27A lies 19.6949 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0642d4p1048 lies 19.7327 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source NVSS_J050650p032401 lies 19.7908 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0409d2p2542 lies 19.8191 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107

Performing the fit

[16]:
jl.set_minimizer("ROOT")

res = jl.fit()
Best fit values:

result unit
parameter
PSR_J0534p2200...K (1.01 +/- 0.04) x 10^-13 1 / (cm2 keV s)
PSR_J0534p2200...index -1.876 +/- 0.026
NVSS_J052622p224801.spectrum.main.Powerlaw.K (3.8 -2.7 +10) x 10^-17 1 / (cm2 keV s)
_4FGL_J0544d4p2238.spectrum.main.Powerlaw.K (1.0 -0.7 +1.9) x 10^-16 1 / (cm2 keV s)

Correlation matrix:

1.000.77-0.05-0.02
0.771.000.070.13
-0.050.071.000.02
-0.020.130.021.00

Values of -log(likelihood) at the minimum:

-log(likelihood)
LAT 118113.801521
total 118113.801521

Values of statistical measures:

statistical measures
AIC 236235.603185
BIC 236277.773221

Now let’s compute the errors on the best fit parameters

[17]:
res = jl.get_errors()
result unit
parameter
PSR_J0534p2200...K (1.01 +/- 0.04) x 10^-13 1 / (cm2 keV s)
PSR_J0534p2200...index -1.876 -0.027 +0.026
NVSS_J052622p224801.spectrum.main.Powerlaw.K (4 -4 +5) x 10^-17 1 / (cm2 keV s)
_4FGL_J0544d4p2238.spectrum.main.Powerlaw.K (1.0 -1.0 +1.2) x 10^-16 1 / (cm2 keV s)

We might also want to look at the profile of the likelihood for each parameter.

[18]:
res = jl.get_contours(
    model.PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.index, -2.0, -1.6, 30
)
[19]:
res[-1]
[19]:
../_images/notebooks_Fermipy_LAT_36_0.png

Or we might want to produce a contour plot

[20]:
res = jl.get_contours(
    "PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.K",
    0.7e-13,
    1.3e-13,
    20,
    "PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.index",
    -2.0,
    -1.6,
    20,
)
[21]:
res[-1]
[21]:
../_images/notebooks_Fermipy_LAT_39_0.png

Pro-trick: We can also axcess the GTAnalysis object of fermipy:

[22]:
# res = jl.fit()
# LAT.gta.write_roi('test',make_plots=True)

All the plots are saved in the output directory as png files:

[23]:
# pngs=Path(f"{fermipy_output_directory}").glob("*png")
# for png in pngs:
#    print(png)
#    my_image=Image(str(png))
#    display(my_image)

We can also plot the resulting model:

[24]:
energies = sp.logspace(1, 8, 100) * u.MeV
fig, ax = plt.subplots()
# we only want to visualize the relevant sources...
src_to_plot = ["Crab", "PSR_J0534p2200"]
# Now loop over all point sources and plot them
for source_name, point_source in model.point_sources.items():
    for src in src_to_plot:
        if src in source_name:
            # Plot the sum of all components for this source

            ax.loglog(energies, point_source(energies), label=source_name)
            # If there is more than one component, plot them also separately

            if len(point_source.components) > 1:

                for component_name, component in point_source.components.items():
                    ax.loglog(
                        energies,
                        component.shape(energies),
                        "--",
                        label=f"{component_name} of {source_name}",
                    )

# Add a legend
ax.legend(loc=0, frameon=False)

ax.set_xlabel("Energy (MeV)")
ax.set_ylabel(r"Flux (ph cm$^{-2}$ s$^{-1}$ keV$^{-1}$")
ax.set_ylim([1e-20, 1e-3])

# show the plot
fig
[24]:
../_images/notebooks_Fermipy_LAT_45_0.png

We can also do a bayesian analysis.

This will set priors based on the current defined min-max (log-uniform or uniform)

[25]:

for param in model.free_parameters.values():
    if param.has_transformation():
        param.set_uninformative_prior(Log_uniform_prior)
    else:
        param.set_uninformative_prior(Uniform_prior)
[26]:
# It's better to remove the output directory,...
shutil.rmtree(fermipy_output_directory)

bayes = BayesianAnalysis(model, data)

Found Galactic template for IRF. P8R3_SOURCE_V3: /usr/local/miniconda/envs/test_env/share/fermitools/refdata/fermi/galdiffuse/gll_iem_v07.fits

Cutting the template around the ROI:


Found Isotropic template for irf P8R3_SOURCE_V3: /usr/local/miniconda/envs/test_env/share/fermitools/refdata/fermi/galdiffuse/iso_P8R3_SOURCE_V3_v1.txt
WARNING: Point source PKS_0459p060 lies 17.6422 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4C_p06d21 lies 17.7201 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _1ES_0647p250 lies 17.7261 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source NVSS_J065035p205556 lies 17.7267 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0551d7p0446 lies 17.7358 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PSR_J0631p1036 lies 17.7822 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0648p1749 lies 17.8406 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0442d8p3609 lies 18.0652 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0552p39A lies 18.3298 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _1RXS_J064814d1p160708 lies 18.3613 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source MG2_J065230p1934 lies 18.3951 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PKS_0502p049 lies 18.4206 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source RX_J0648d7p1516 lies 18.8083 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0620p3806 lies 18.8393 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PSR_J0622p3749 lies 18.8555 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0653p2816 lies 18.9497 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PMN_J0444p0717 lies 18.9991 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source MG1_J050533p0415 lies 19.0814 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0559d3p0352 lies 19.115 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source TXS_0431p092 lies 19.119 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B3_0509p406 lies 19.2332 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0635p35 lies 19.2989 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source PKS_0550p032 lies 19.3025 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _2MASX_J06533986p1636432 lies 19.4121 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0658d7p2318 lies 19.4489 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source GB6_J0555p0304 lies 19.591 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source B2_0655p27A lies 19.6949 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0642d4p1048 lies 19.7327 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source NVSS_J050650p032401 lies 19.7908 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
WARNING: Point source _4FGL_J0409d2p2542 lies 19.8191 degrees from the ROI center at RA, Dec = 83.6331, 22.0145 7.57107
[27]:
bayes.set_sampler("emcee")

n_walkers = 10
burn_in = 10
n_samples = 500

bayes.sampler.setup(n_iterations=n_samples, n_burn_in=burn_in, n_walkers=n_walkers)

res = bayes.sample()
Maximum a posteriori probability (MAP) point:

result unit
parameter
PSR_J0534p2200...K (1.02 +/- 0.04) x 10^-13 1 / (cm2 keV s)
PSR_J0534p2200...index -1.874 -0.024 +0.025
NVSS_J052622p224801.spectrum.main.Powerlaw.K (4.0 -3.5 +4) x 10^-17 1 / (cm2 keV s)
_4FGL_J0544d4p2238.spectrum.main.Powerlaw.K (1.1 +/- 0.9) x 10^-16 1 / (cm2 keV s)

Values of -log(posterior) at the minimum:

-log(posterior)
LAT -118079.173797
total -118079.173797

Values of statistical measures:

statistical measures
AIC 236166.347737
BIC 236208.517773
DIC 236167.079247
PDIC 2.061270

You can access to the parameter range like this (HPD):

[28]:
this_K = bayes.results.get_variates(
    "PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.K"
)
this_idx = bayes.results.get_variates(
    "PSR_J0534p2200.spectrum.main.Super_cutoff_powerlaw.index"
)

print("Highest_posterior_density_intervals :")
print(
    "K (68%%):     %10.2e,%10.2e" % this_K.highest_posterior_density_interval(cl=0.68)
)
print(
    "K (95%%):     %10.2e,%10.2e" % this_K.highest_posterior_density_interval(cl=0.95)
)
print(
    "Index (68%%): %10.2e,%10.2e" % this_idx.highest_posterior_density_interval(cl=0.68)
)
print(
    "Index (95%%): %10.2e,%10.2e" % this_idx.highest_posterior_density_interval(cl=0.95)
)
Highest_posterior_density_intervals :
K (68%):       9.83e-14,  1.06e-13
K (95%):       9.42e-14,  1.09e-13
Index (68%):  -1.90e+00, -1.85e+00
Index (95%):  -1.92e+00, -1.82e+00
[29]:
corner_figure = bayes.results.corner_plot()
corner_figure
[29]:
../_images/notebooks_Fermipy_LAT_52_0.png
[ ]: