Maps#

class gammapy.maps.Maps(**kwargs)[source]#

Bases: collections.abc.MutableMapping

A Dictionary containing Map objects sharing the same geometry.

This class simplifies handling and I/O of maps collections.

For maps with different geometries, use a regular dict.

Attributes Summary

geom

Map geometry (Geom)

Methods Summary

clear()

from_geom(geom, names[, kwargs_list])

Create map dictionary from geometry.

from_hdulist(hdulist[, hdu_bands])

Create map dictionary from list of HDUs.

get(k[,d])

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

read(filename)

Read map dictionary from file.

setdefault(k[,d])

to_hdulist([hdu_bands])

Convert map dictionary to list of HDUs.

update([E, ]**F)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values()

write(filename[, overwrite])

Write map dictionary to file.

Attributes Documentation

geom#

Map geometry (Geom)

Methods Documentation

clear() None.  Remove all items from D.#
classmethod from_geom(geom, names, kwargs_list=None)[source]#

Create map dictionary from geometry.

Parameters
geomGeom

the input geometry that will be used by all maps

nameslist of str

the list of all map names

kwargs_listlist of dict

the list of arguments to be passed to from_geom()

Returns
mapsMaps

Maps object.

classmethod from_hdulist(hdulist, hdu_bands='BANDS')[source]#

Create map dictionary from list of HDUs.

Because FITS keywords are case insensitive, all key names will return as lower-case.

Parameters
hdulistHDUList

List of HDUs.

hdu_bandsstr

Name of the HDU with the BANDS table. Default is ‘BANDS’ If set to None, each map should have its own hdu_band

Returns
mapsMaps

Maps object.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair#

as a 2-tuple; but raise KeyError if D is empty.

classmethod read(filename)[source]#

Read map dictionary from file.

Because FITS keywords are case insensitive, all key names will return as lower-case.

Parameters
filenamestr

Filename to read from.

Returns
mapsMaps

Maps object.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
to_hdulist(hdu_bands='BANDS')[source]#

Convert map dictionary to list of HDUs.

Parameters
hdu_bandsstr

Name of the HDU with the BANDS table. Default is ‘BANDS’ If set to None, each map will have its own hdu_band

Returns
hdulistHDUList

Map dataset list of HDUs.

update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values#
write(filename, overwrite=False)[source]#

Write map dictionary to file.

Parameters
filenamestr

Filename to write to.

overwritebool

Overwrite file if it exists.