.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "modeling/gallery/spectral/plot_naima.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_modeling_gallery_spectral_plot_naima.py: .. _naima-spectral-model: Naima spectral model ==================== This class provides an interface with the models defined in the naima models module. The model accepts as a positional argument a `Naima `_ radiative `~naima.models` instance, used to compute the non-thermal emission from populations of relativistic electrons or protons due to interactions with the ISM or with radiation and magnetic fields. One of the advantages provided by this class consists in the possibility of performing a maximum likelihood spectral fit of the model's parameters directly on observations, as opposed to the MCMC `fit to flux points `_ featured in Naima. All the parameters defining the parent population of charged particles are stored as `~gammapy.modeling.Parameter` and left free by default. In case that the radiative model is `~naima.radiative.Synchrotron`, the magnetic field strength may also be fitted. Parameters can be freezed/unfreezed before the fit, and maximum/minimum values can be set to limit the parameters space to the physically interesting region. .. GENERATED FROM PYTHON SOURCE LINES 26-30 Example plot ------------ Here we create and plot a spectral model that convolves an `~gammapy.modeling.models.ExpCutoffPowerLawSpectralModel` electron distribution with an `InverseCompton` radiative model, in the presence of multiple seed photon fields. .. GENERATED FROM PYTHON SOURCE LINES 30-63 .. code-block:: default from astropy import units as u import matplotlib.pyplot as plt import naima from gammapy.modeling.models import Models, NaimaSpectralModel, SkyModel particle_distribution = naima.models.ExponentialCutoffPowerLaw( 1e30 / u.eV, 10 * u.TeV, 3.0, 30 * u.TeV ) radiative_model = naima.radiative.InverseCompton( particle_distribution, seed_photon_fields=["CMB", ["FIR", 26.5 * u.K, 0.415 * u.eV / u.cm ** 3]], Eemin=100 * u.GeV, ) model = NaimaSpectralModel(radiative_model, distance=1.5 * u.kpc) opts = { "energy_bounds": [10 * u.GeV, 80 * u.TeV], "sed_type": "e2dnde", } # Plot the total inverse Compton emission model.plot(label="IC (total)", **opts) # Plot the separate contributions from each seed photon field for seed, ls in zip(["CMB", "FIR"], ["-", "--"]): model = NaimaSpectralModel(radiative_model, seed=seed, distance=1.5 * u.kpc) model.plot(label=f"IC ({seed})", ls=ls, color="gray", **opts) plt.legend(loc="best") plt.grid(which="both") .. image-sg:: /modeling/gallery/spectral/images/sphx_glr_plot_naima_001.png :alt: plot naima :srcset: /modeling/gallery/spectral/images/sphx_glr_plot_naima_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-67 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. code-block:: default model = SkyModel(spectral_model=model, name="naima-model") models = Models([model]) print(models.to_yaml()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none components: - name: naima-model type: SkyModel spectral: type: NaimaSpectralModel parameters: - name: amplitude value: 1.0e+30 unit: eV-1 error: 0 min: .nan max: .nan frozen: false interp: lin scale_method: scale10 - name: e_0 value: 10.0 unit: TeV error: 0 min: .nan max: .nan frozen: false interp: lin scale_method: scale10 - name: alpha value: 3.0 unit: '' error: 0 min: .nan max: .nan frozen: false interp: lin scale_method: scale10 - name: e_cutoff value: 30.0 unit: TeV error: 0 min: .nan max: .nan frozen: false interp: lin scale_method: scale10 - name: beta value: 1.0 unit: '' error: 0 min: .nan max: .nan frozen: false interp: lin scale_method: scale10 .. _sphx_glr_download_modeling_gallery_spectral_plot_naima.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_naima.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_naima.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_