This tutorial demonstrates some of the methods that can be used to manipulate FileFunction sources in fermipy. For this example we'll use the draco analysis.
In [23]:
import os
if os.path.isfile('../data/draco.tar.gz'):
!tar xzf ../data/draco.tar.gz
else:
!curl -OL https://raw.githubusercontent.com/fermiPy/fermipy-extras/master/data/draco.tar.gz
!tar xzf draco.tar.gz
In [24]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from fermipy.gtanalysis import GTAnalysis
gta = GTAnalysis('draco/config.yaml')
gta.setup()
By default all sources are initialized with parametric spectral models (PowerLaw, etc.). The spectral model of a source an be updated by calling set_source_spectrum()
.
In [25]:
print gta.roi['3FGL J1725.3+5853']
Running set_source_spectrum()
with no additional arguments will substitute the source spectrum with a FileFunction with the same distribution in differential flux. The normalization parameter is defined such that 1.0 corresponds to the normalization of the original source spectrum.
In [26]:
gta.set_source_spectrum('3FGL J1725.3+5853','FileFunction')
print gta.roi['3FGL J1725.3+5853']
The differential flux of a FileFunction source can be accessed or modified at runtime by calling the get_source_dfde()
and set_source_dfde()
methods:
In [27]:
x, y = gta.get_source_dfde('3FGL J1725.3+5853')
y1 = 1E-12*10**(-2.0*(x-3.0))*np.exp(-10**(x-3.0))
plt.figure()
plt.plot(x,y)
plt.plot(x,y1)
plt.gca().set_yscale('log')
plt.gca().set_ylim(1E-17,1E-5)
print gta.like()
gta.set_source_dfde('3FGL J1725.3+5853',y1)
print gta.like()
Calling set_source_spectrum()
with the optional dictionary argument can be used to explicitly set the parameters of the new spectral model.
In [28]:
gta.set_source_spectrum('3FGL J1725.3+5853','PowerLaw',{'Index' : 2.179, 'Scale' : 1701, 'Prefactor' : 1.627e-13})
gta.like()
Out[28]: