Exemplo n.º 1
0
def test_generalized_gaussian(eta, r_0, e):
    reval = 6
    dr = 0.01
    geom = WcsGeom.create(
        skydir=(0, 0),
        binsz=dr,
        width=(2 * reval, 2 * reval),
        frame="galactic",
    )

    # check normalization is robust for a large set of values
    model = GeneralizedGaussianSpatialModel(eta=eta,
                                            r_0=r_0 * u.deg,
                                            e=e,
                                            frame="galactic")

    eval_geom = model.evaluate_geom(geom)
    integ_geom = model.integrate_geom(geom)
    assert eval_geom.unit.is_equivalent("sr-1")
    assert integ_geom.unit.is_equivalent("")
    assert_allclose(integ_geom.data.sum(), 1.0, atol=3e-2)
    assert isinstance(model.to_region(), EllipseSkyRegion)
    new_model = GeneralizedGaussianSpatialModel.from_dict(model.to_dict())
    assert isinstance(new_model, GeneralizedGaussianSpatialModel)
    assert_allclose(
        new_model.integrate_geom(geom).data.sum(), integ_geom.data.sum())
Exemplo n.º 2
0
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()

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

pwl = PowerLawSpectralModel()
gengauss = GeneralizedGaussianSpatialModel()