TemplateNPredModel#

class gammapy.modeling.models.TemplateNPredModel(map, spectral_model=None, name=None, filename=None, datasets_names=None, copy_data=True, spatial_model=None, covariance_data=None)[source]#

Bases: gammapy.modeling.models.core.ModelBase

Background model.

Create a new map by a tilt and normalization on the available map.

Parameters
mapMap

Background model map.

spectral_modelSpectralModel

Normalized spectral model. Default is PowerLawNormSpectralModel.

copy_databool

Create a deepcopy of the map data or directly use the original. Default is True. Use False to save memory in case of large maps.

spatial_modelSpatialModel

Unitless Spatial model (unit is dropped on evaluation if defined). Default is None.

Attributes Summary

covariance

default_parameters

energy_center

True energy axis bin centers as a Quantity.

evaluation_radius

Evaluation radius as a Angle.

frozen

Frozen status of a model, True if all parameters are frozen.

map

A lazy FITS data descriptor.

name

parameters

Parameters as a Parameters object.

position

Position as a SkyCoord.

spectral_model

Spectral model as a SpectralModel object.

tag

type

Methods Summary

copy([name, copy_data])

Copy template npred model.

cutout(position, width[, mode, name])

Cutout background model.

evaluate()

Evaluate background model.

freeze([model_type])

Freeze model parameters.

from_dict(data, **kwargs)

from_parameters(parameters, **kwargs)

Create model from parameter list.

reassign(datasets_names, new_datasets_names)

Reassign a model from one dataset to another.

slice_by_energy([energy_min, energy_max, name])

Select and slice model template in energy range

stack(other[, weights, nan_to_num])

Stack background model in place.

to_dict([full_output])

Create dictionary for YAML serialisation.

unfreeze([model_type])

Restore parameters frozen status to default.

write([overwrite])

Write the map.

Attributes Documentation

covariance#
default_parameters = <gammapy.modeling.parameter.Parameters object>#
energy_center#

True energy axis bin centers as a Quantity.

evaluation_radius#

Evaluation radius as a Angle.

frozen#

Frozen status of a model, True if all parameters are frozen.

map#

A lazy FITS data descriptor.

Parameters
cachebool

Whether to cache the data.

name#
parameters#
position#

Position as a SkyCoord.

spectral_model#

Spectral model as a SpectralModel object.

tag = 'TemplateNPredModel'#
type#

Methods Documentation

copy(name=None, copy_data=False, **kwargs)[source]#

Copy template npred model.

Parameters
namestr, optional

Assign a new name to the copied model. Default is None.

copy_databool, optional

Copy the data arrays attached to models. Default is False.

**kwargsdict

Keyword arguments forwarded to TemplateNPredModel.

Returns
modelTemplateNPredModel

Copied template npred model.

cutout(position, width, mode='trim', name=None)[source]#

Cutout background model.

Parameters
positionSkyCoord

Center position of the cutout region.

widthtuple of Angle

Angular sizes of the region in (lon, lat) in that specific order. If only one value is passed, a square region is extracted.

mode{‘trim’, ‘partial’, ‘strict’}

Mode option for Cutout2D, for details see Cutout2D. Default is “trim”.

namestr, optional

Name of the returned background model. Default is None.

Returns
cutoutTemplateNPredModel

Cutout background model.

evaluate()[source]#

Evaluate background model.

Returns
background_mapMap

Background evaluated on the Map.

freeze(model_type='spectral')[source]#

Freeze model parameters.

classmethod from_dict(data, **kwargs)[source]#
classmethod from_parameters(parameters, **kwargs)#

Create model from parameter list.

Parameters
parametersParameters

Parameters for init.

Returns
modelModel

Model instance.

reassign(datasets_names, new_datasets_names)#

Reassign a model from one dataset to another.

Parameters
datasets_namesstr or list

Name of the datasets where the model is currently defined.

new_datasets_namesstr or list

Name of the datasets where the model should be defined instead. If multiple names are given the two list must have the save length, as the reassignment is element-wise.

Returns
modelModel

Reassigned model.

slice_by_energy(energy_min=None, energy_max=None, name=None)[source]#

Select and slice model template in energy range

Parameters
energy_min, energy_maxQuantity

Energy bounds of the slice. Default is None.

namestr

Name of the sliced model. Default is None.

Returns
modelTemplateNpredModel

Sliced Model.

stack(other, weights=None, nan_to_num=True)[source]#

Stack background model in place.

Stacking the background model resets the current parameters values.

Parameters
otherTemplateNPredModel

Other background model.

weightsfloat, optional

Weights. Default is None.

nan_to_num: bool, optional

Non-finite values are replaced by zero if True. Default is True.

to_dict(full_output=False)[source]#

Create dictionary for YAML serialisation.

unfreeze(model_type='spectral')[source]#

Restore parameters frozen status to default.

write(overwrite=False)[source]#

Write the map.

Parameters
overwrite: bool, optional

Overwrite existing file. Default is False, which will raise a warning if the template file exists already.