.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "user-guide/model-gallery/spatial/plot_gen_gauss.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_user-guide_model-gallery_spatial_plot_gen_gauss.py: .. _generalized-gaussian-spatial-model: Generalized gaussian spatial model ================================== This is a spatial model parametrising a generalized Gaussian function. By default, the Generalized Gaussian is defined as : .. math:: \phi(\text{lon}, \text{lat}) = \phi(\text{r}) = N \times \exp \left[ - \left( \frac{r}{r_{\rm eff}} \right)^ \left( 1/\eta \right) \right] \,, the normalization is expressed as: .. math:: N = \frac{1}{ 2 \pi \sqrt(1-e^2) r_{0}^2 \eta \Gamma(2\eta)}\, where :math:`\Gamma` is the gamma function. This analytical norm is approximated so it may not integrate to unity in extreme cases if ellipticity tend to one and radius is large or :math:`\eta` much larger than one (outside the default range). The effective radius is given by: .. math:: r_{rm eff}(\text{lon}, \text{lat}) = \sqrt{ (r_M \sin(\Delta \phi))^2 + (r_m \cos(\Delta \phi))^2 }. where :math:`r_M` (:math:`r_m`) is the major (minor) semiaxis, and :math:`\Delta \phi` is the difference between `phi`, the position angle of the model, and the position angle of the evaluation point. If the eccentricity (:math:`e`) is null it reduces to :math:`r_0`. .. GENERATED FROM PYTHON SOURCE LINES 40-43 Example plot ------------ Here is an example plot of the model for different shape parameter: .. GENERATED FROM PYTHON SOURCE LINES 43-90 .. code-block:: Python from astropy import units as u import matplotlib.pyplot as plt from gammapy.maps import Map, WcsGeom from gammapy.modeling.models import ( GeneralizedGaussianSpatialModel, Models, PowerLawSpectralModel, SkyModel, ) lon_0 = 20 lat_0 = 0 reval = 3 dr = 0.02 geom = WcsGeom.create( skydir=(lon_0, lat_0), binsz=dr, width=(2 * reval, 2 * reval), frame="galactic", ) tags = [r"Disk, $\eta=0.01$", r"Gaussian, $\eta=0.5$", r"Laplace, $\eta=1$"] eta_range = [0.01, 0.5, 1] r_0 = 1 e = 0.5 phi = 45 * u.deg fig, axes = plt.subplots(1, 3, figsize=(9, 6)) for ax, eta, tag in zip(axes, eta_range, tags): model = GeneralizedGaussianSpatialModel( lon_0=lon_0 * u.deg, lat_0=lat_0 * u.deg, eta=eta, r_0=r_0 * u.deg, e=e, phi=phi, frame="galactic", ) meval = model.evaluate_geom(geom) Map.from_geom(geom=geom, data=meval.value, unit=meval.unit).plot(ax=ax) pixreg = model.to_region().to_pixel(geom.wcs) pixreg.plot(ax=ax, edgecolor="g", facecolor="none", lw=2) ax.set_title(tag) ax.set_xticks([]) ax.set_yticks([]) plt.tight_layout() .. image-sg:: /user-guide/model-gallery/spatial/images/sphx_glr_plot_gen_gauss_001.png :alt: Disk, $\eta=0.01$, Gaussian, $\eta=0.5$, Laplace, $\eta=1$ :srcset: /user-guide/model-gallery/spatial/images/sphx_glr_plot_gen_gauss_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 91-94 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 94-102 .. code-block:: Python pwl = PowerLawSpectralModel() gengauss = GeneralizedGaussianSpatialModel() model = SkyModel(spectral_model=pwl, spatial_model=gengauss, name="pwl-gengauss-model") models = Models([model]) print(models.to_yaml()) .. rst-class:: sphx-glr-script-out .. code-block:: none components: - name: pwl-gengauss-model type: SkyModel spectral: type: PowerLawSpectralModel parameters: - name: index value: 2.0 - name: amplitude value: 1.0e-12 unit: cm-2 s-1 TeV-1 - name: reference value: 1.0 unit: TeV spatial: type: GeneralizedGaussianSpatialModel frame: icrs parameters: - name: lon_0 value: 0.0 unit: deg - name: lat_0 value: 0.0 unit: deg - name: r_0 value: 1.0 unit: deg - name: eta value: 0.5 - name: e value: 0.0 - name: phi value: 0.0 unit: deg metadata: creator: Gammapy 1.3 date: '2024-11-26T10:08:39.908583' origin: null .. _sphx_glr_download_user-guide_model-gallery_spatial_plot_gen_gauss.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/gammapy/gammapy-webpage/v1.3?urlpath=lab/tree/notebooks/1.3/user-guide/model-gallery/spatial/plot_gen_gauss.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gen_gauss.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gen_gauss.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_gen_gauss.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_