region = CircleSkyRegion(center=src_pos, radius=0.6 * u.deg) mask = geom2d.region_mask([region]) # ## Modeling the source # # This is the important thing to note in this analysis. Since modeling and fitting in `gammapy.maps` needs to have a combination of spectral models, we have to use a dummy Powerlaw as for the spectral model and fix its index to 2. Since we are interested only in the integral flux, we will use the `PowerLaw2SpectralModel` model which directly fits an integral flux. # In[ ]: spatial_model = PointSpatialModel( lon_0="0.01 deg", lat_0="0.01 deg", frame="galactic" ) spectral_model = PowerLaw2SpectralModel( emin=emin, emax=emax, index=2.0, amplitude="3e-12 cm-2 s-1" ) model = SkyModel(spatial_model=spatial_model, spectral_model=spectral_model) model.parameters["index"].frozen = True # ## Modeling the background # # Gammapy fitting framework assumes the background to be an integrated model. # Thus, we will define the background as a model, and freeze its parameters for now. # In[ ]: background_model = BackgroundModel(maps2D["background"]) background_model.parameters["norm"].frozen = True
dict( name="powerlaw", model=PowerLawSpectralModel( index=2 * u.Unit(""), amplitude=4 / u.cm**2 / u.s / u.TeV, reference=1 * u.TeV, ), val_at_2TeV=u.Quantity(1.0, "cm-2 s-1 TeV-1"), integral_1_10TeV=u.Quantity(3.6, "cm-2 s-1"), eflux_1_10TeV=u.Quantity(9.210340371976184, "TeV cm-2 s-1"), ), dict( name="powerlaw2", model=PowerLaw2SpectralModel( amplitude=u.Quantity(2.9227116204223784, "cm-2 s-1"), index=2.3 * u.Unit(""), emin=1 * u.TeV, emax=10 * u.TeV, ), val_at_2TeV=u.Quantity(4 * 2.0**(-2.3), "cm-2 s-1 TeV-1"), integral_1_10TeV=u.Quantity(2.9227116204223784, "cm-2 s-1"), eflux_1_10TeV=u.Quantity(6.650836884969039, "TeV cm-2 s-1"), ), dict( name="ecpl", model=ExpCutoffPowerLawSpectralModel( index=1.6 * u.Unit(""), amplitude=4 / u.cm**2 / u.s / u.TeV, reference=1 * u.TeV, lambda_=0.1 / u.TeV, ), val_at_2TeV=u.Quantity(1.080321705479446, "cm-2 s-1 TeV-1"),
See also: https://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/source_models.html """ # %% # Example plot # ------------ # Here is an example plot of the model: from astropy import units as u import matplotlib.pyplot as plt from gammapy.modeling.models import Models, PowerLaw2SpectralModel, SkyModel energy_bounds = [0.1, 100] * u.TeV model = PowerLaw2SpectralModel( amplitude=u.Quantity(1e-12, "cm-2 s-1"), index=2.3, emin=1 * u.TeV, emax=10 * u.TeV, ) model.plot(energy_bounds) plt.grid(which="both") # %% # YAML representation # ------------------- # Here is an example YAML file using the model: model = SkyModel(spectral_model=model, name="power-law2-model") models = Models([model]) print(models.to_yaml())