Example #1
0
    def from_dict(cls, data):
        """Create SkyModel from dict"""
        from gammapy.modeling.models import (
            SPATIAL_MODEL_REGISTRY,
            SPECTRAL_MODEL_REGISTRY,
            TEMPORAL_MODEL_REGISTRY,
        )

        model_class = SPECTRAL_MODEL_REGISTRY.get_cls(data["spectral"]["type"])
        spectral_model = model_class.from_dict(data["spectral"])

        spatial_data = data.get("spatial")

        if spatial_data is not None:
            model_class = SPATIAL_MODEL_REGISTRY.get_cls(spatial_data["type"])
            spatial_model = model_class.from_dict(spatial_data)
        else:
            spatial_model = None

        temporal_data = data.get("temporal")

        if temporal_data is not None:
            model_class = TEMPORAL_MODEL_REGISTRY.get_cls(temporal_data["type"])
            temporal_model = model_class.from_dict(temporal_data)
        else:
            temporal_model = None

        return cls(
            name=data["name"],
            spatial_model=spatial_model,
            spectral_model=spectral_model,
            temporal_model=temporal_model,
            apply_irf=data.get("apply_irf", cls._apply_irf_default),
            datasets_names=data.get("datasets_names"),
        )
Example #2
0
extent = [
    np.log10(values["r_0"][0]) - log_dr / 2,
    np.log10(values["r_0"][-1]) + log_dr / 2,
    values["e"][0] - de / 2,
    values["e"][-1] + de / 2,
]

# model tags and parameter names
tags = ["disk", "gauss-general", "gauss-general", "gauss", "shell2"]
par_x = ["r_0", "r_0", "r_0", "sigma", "r_0"]
par_y = ["e", "e", "e", "e", "eta"]
eta_val = [None, 0.1, 0.9, None, None]

# norm correction array
for k, tag in enumerate(tags):
    class_ = SPATIAL_MODEL_REGISTRY.get_cls(tag)
    class_.norm_correction = norm_correction
    m = class_()
    ngrid = np.zeros((nr, ne))
    if eta_val[k] is not None:
        m.eta.value = eta_val[k]
        tag += f"_eta{eta_val[k]}"
    for kr in range(nr):
        for ke in range(ne):
            m.parameters[par_x[k]].value = values[par_x[k]][kr]
            m.parameters[par_y[k]].value = values[par_y[k]][ke]
            ngrid[kr, ke] = m.norm_correction()
    plt.figure(figsize=(12, 4), dpi=100)
    plt.imshow(ngrid.T,
               origin="lower",
               extent=extent,