Datasets#

class gammapy.datasets.Datasets(datasets=None)[source]#

Bases: collections.abc.MutableSequence

Container class that holds a list of datasets.

Parameters
datasetsDataset or list of Dataset

Datasets

Attributes Summary

contributes_to_stat

Stat contributions.

energy_axes_are_aligned

Whether all contained datasets have aligned energy axis.

energy_ranges

Get global energy range of datasets.

gti

GTI table.

is_all_same_energy_shape

Whether all contained datasets have the same data shape.

is_all_same_shape

Whether all contained datasets have the same data shape.

is_all_same_type

Whether all contained datasets are of the same type.

meta_table

Meta table

models

Unique models (Models).

names

parameters

Unique parameters (Parameters).

Methods Summary

append(value)

S.append(value) -- append value to the end of the sequence

clear()

copy()

A deep copy.

count(value)

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

index(value, [start, [stop]])

Raises ValueError if the value is not present.

info_table([cumulative])

Get info table for datasets.

insert(idx, dataset)

S.insert(index, value) -- insert value before index

pop([index])

Raise IndexError if list is empty or index is out of range.

read(filename[, filename_models, lazy, cache])

De-serialize datasets from YAML and FITS files.

remove(value)

S.remove(value) -- remove first occurrence of value.

reverse()

S.reverse() -- reverse IN PLACE

select_time(time_min, time_max[, atol])

Select datasets in a given time interval.

slice_by_energy(energy_min, energy_max)

Select and slice datasets in energy range.

stack_reduce([name, nan_to_num])

Reduce the Datasets to a unique Dataset by stacking them together.

stat_sum()

Compute joint statistic function value.

to_spectrum_datasets(region)

Extract spectrum datasets for the given region.

write(filename[, filename_models, ...])

Serialize datasets to YAML and FITS files.

Attributes Documentation

contributes_to_stat#

Stat contributions.

Returns
contributionsarray

Array indicating which dataset contributes to the likelihood.

energy_axes_are_aligned#

Whether all contained datasets have aligned energy axis.

energy_ranges#

Get global energy range of datasets.

The energy range is derived as the minimum / maximum of the energy ranges of all datasets.

Returns
energy_min, energy_maxQuantity

Energy range

gti#

GTI table.

is_all_same_energy_shape#

Whether all contained datasets have the same data shape.

is_all_same_shape#

Whether all contained datasets have the same data shape.

is_all_same_type#

Whether all contained datasets are of the same type.

meta_table#

Meta table

models#

Unique models (Models).

Duplicate model objects have been removed. The order of the unique models remains.

names#
parameters#

Unique parameters (Parameters).

Duplicate parameter objects have been removed. The order of the unique parameters remains.

Methods Documentation

append(value)#

S.append(value) – append value to the end of the sequence

clear() None -- remove all items from S#
copy()[source]#

A deep copy.

count(value) integer -- return number of occurrences of value#
extend(values)#

S.extend(iterable) – extend sequence by appending elements from the iterable

index(value[, start[, stop]]) integer -- return first index of value.[source]#

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

info_table(cumulative=False)[source]#

Get info table for datasets.

Parameters
cumulativebool

Cumulate info across all observations

Returns
info_tableTable

Info table.

insert(idx, dataset)[source]#

S.insert(index, value) – insert value before index

pop([index]) item -- remove and return item at index (default last).#

Raise IndexError if list is empty or index is out of range.

classmethod read(filename, filename_models=None, lazy=True, cache=True)[source]#

De-serialize datasets from YAML and FITS files.

Parameters
filenamestr or Path

File path or name of datasets yaml file

filename_modelsstr or Path

File path or name of models yaml file

lazybool

Whether to lazy load data into memory

cachebool

Whether to cache the data after loading

Returns
datasetgammapy.datasets.Datasets

Datasets

remove(value)#

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()#

S.reverse() – reverse IN PLACE

select_time(time_min, time_max, atol='1e-6 s')[source]#

Select datasets in a given time interval.

Parameters
time_min, time_maxTime

Time interval

atolQuantity

Tolerance value for time comparison with different scale. Default 1e-6 sec.

Returns
datasetsDatasets

Datasets in the given time interval.

slice_by_energy(energy_min, energy_max)[source]#

Select and slice datasets in energy range.

The method keeps the current dataset names. Datasets that do not contribute to the selected energy range are dismissed.

Parameters
energy_min, energy_maxQuantity

Energy bounds to compute the flux point for

Returns
datasetsDatasets

Datasets

stack_reduce(name=None, nan_to_num=True)[source]#

Reduce the Datasets to a unique Dataset by stacking them together.

This works only if all datasets are of the same type and with aligned geometries, and if a proper in-place stack method exists for the Dataset type.

Parameters
namestr

Name of the stacked dataset

nan_to_num: bool

Non-finite values are replaced by zero if True (default)

Returns
datasetDataset

the stacked dataset

stat_sum()[source]#

Compute joint statistic function value.

to_spectrum_datasets(region)[source]#

Extract spectrum datasets for the given region.

To get more detailed information, see the corresponding function associated to each dataset type: to_spectrum_dataset or to_spectrum_dataset.

Parameters
regionSkyRegion

Region definition

Returns
datasetsDatasets

List of SpectrumDataset

write(filename, filename_models=None, overwrite=False, write_covariance=True)[source]#

Serialize datasets to YAML and FITS files.

Parameters
filenamestr or Path

File path or name of datasets yaml file

filename_modelsstr or Path

File path or name of models yaml file

overwritebool

overwrite datasets FITS files

write_covariancebool

save covariance or not