TimeMapAxis#

class gammapy.maps.TimeMapAxis(edges_min, edges_max, reference_time, name='time', interp='lin')[source]#

Bases: object

Class representing a time axis.

Provides methods for transforming to/from axis and pixel coordinates. A time axis can represent non-contiguous sequences of non-overlapping time intervals.

Time intervals must be provided in increasing order.

Parameters
edges_minQuantity

Array of edge time values. This the time delta w.r.t. to the reference time.

edges_maxQuantity

Array of edge time values. This the time delta w.r.t. to the reference time.

reference_timeTime

Reference time to use.

namestr

Axis name

interpstr

Interpolation method used to transform between axis and pixel coordinates. For now only ‘lin’ is supported.

Attributes Summary

as_plot_center

Plot center

as_plot_edges

Plot edges

as_plot_labels

Plot labels

as_plot_xerr

Plot x error

bin_width

Return time interval width (Quantity).

bounds

Bounds of the axis (~astropy.units.Quantity)

center

Return Quantity at interval centers.

edges

Return array of bin edges values.

edges_max

Return array of bin edges min values.

edges_min

Return array of bin edges max values.

interp

Interp

is_contiguous

Whether the axis is contiguous

iter_by_edges

Iterate by intervals defined by the edges

name

Return axis name.

nbin

Return number of bins in the axis.

node_type

reference_time

Return reference time used for the axis.

time_bounds

Bounds of the axis (~astropy.units.Quantity)

time_delta

Return axis time bin width (TimeDelta).

time_edges

Time edges

time_format

time_max

Return axis upper edges as Time objects.

time_mid

Return time bin center (Time).

time_min

Return axis lower edges as Time objects.

unit

Axes unit

Methods Summary

assert_name(required_name)

Assert axis name if a specific one is required.

coord_to_idx(coord, **kwargs)

Transform from axis time coordinate to bin index.

coord_to_pix(coord, **kwargs)

Transform from time to coordinate to pixel position.

copy(**kwargs)

Copy MapAxis instance and overwrite given attributes.

downsample()

format_plot_xaxis(ax)

Format plot axis

from_gti(gti[, name])

Create a time axis from an input GTI.

from_table(table[, format, idx])

Create time map axis from table

from_time_bounds(time_min, time_max, nbin[, ...])

Create linearly spaced time axis from bounds

from_time_edges(time_min, time_max[, unit, ...])

Create TimeMapAxis from the time interval edges defined as Time.

is_aligned(other[, atol])

is_allclose(other, **kwargs)

Check if other map axis is all close.

pix_to_idx(pix[, clip])

slice(idx)

Create a new axis object by extracting a slice from this axis.

squash()

Create a new axis object by squashing the axis into one bin.

to_contiguous()

Make the time axis contiguous

to_header([format, idx])

Create FITS header

upsample()

Attributes Documentation

as_plot_center#

Plot center

as_plot_edges#

Plot edges

as_plot_labels#

Plot labels

as_plot_xerr#

Plot x error

bin_width#

Return time interval width (Quantity).

bounds#

Bounds of the axis (~astropy.units.Quantity)

center#

Return Quantity at interval centers.

edges#

Return array of bin edges values.

edges_max#

Return array of bin edges min values.

edges_min#

Return array of bin edges max values.

interp#

Interp

is_contiguous#

Whether the axis is contiguous

iter_by_edges#

Iterate by intervals defined by the edges

name#

Return axis name.

nbin#

Return number of bins in the axis.

node_type = 'intervals'#
reference_time#

Return reference time used for the axis.

time_bounds#

Bounds of the axis (~astropy.units.Quantity)

time_delta#

Return axis time bin width (TimeDelta).

time_edges#

Time edges

time_format = 'iso'#
time_max#

Return axis upper edges as Time objects.

time_mid#

Return time bin center (Time).

time_min#

Return axis lower edges as Time objects.

unit#

Axes unit

Methods Documentation

assert_name(required_name)[source]#

Assert axis name if a specific one is required.

Parameters
required_namestr

Required

coord_to_idx(coord, **kwargs)[source]#

Transform from axis time coordinate to bin index.

Indices of time values falling outside time bins will be set to -1.

Parameters
coordTime or Quantity

Array of axis coordinate values. The quantity is assumed to be relative to the reference time.

Returns
idxndarray

Array of bin indices.

coord_to_pix(coord, **kwargs)[source]#

Transform from time to coordinate to pixel position.

Pixels of time values falling outside time bins will be set to -1.

Parameters
coordTime

Array of axis coordinate values.

Returns
pixndarray

Array of pixel positions.

copy(**kwargs)[source]#

Copy MapAxis instance and overwrite given attributes.

Parameters
**kwargsdict

Keyword arguments to overwrite in the map axis constructor.

Returns
copyMapAxis

Copied map axis.

downsample()[source]#
format_plot_xaxis(ax)[source]#

Format plot axis

Parameters
axAxis

Plot axis to format

Returns
axAxis

Formatted plot axis

classmethod from_gti(gti, name='time')[source]#

Create a time axis from an input GTI.

Parameters
gtiGTI

GTI table

namestr

Axis name

Returns
axisTimeMapAxis

Time map axis.

classmethod from_table(table, format='gadf', idx=0)[source]#

Create time map axis from table

Parameters
tableTable

Bin table HDU

format{“gadf”, “fermi-fgl”, “lightcurve”}

Format to use.

Returns
axisTimeMapAxis

Time map axis.

classmethod from_time_bounds(time_min, time_max, nbin, unit='d', name='time')[source]#

Create linearly spaced time axis from bounds

Parameters
time_minTime

Lower bound

time_maxTime

Upper bound

nbinint

Number of bins

namestr

Name of the axis.

classmethod from_time_edges(time_min, time_max, unit='d', interp='lin', name='time')[source]#

Create TimeMapAxis from the time interval edges defined as Time.

The reference time is defined as the lower edge of the first interval.

Parameters
time_minTime

Array of lower edge times.

time_maxTime

Array of lower edge times.

unitUnit or str

The unit to convert the edges to. Default is ‘d’ (day).

interpstr

Interpolation method used to transform between axis and pixel coordinates. Valid options are ‘log’, ‘lin’, and ‘sqrt’.

namestr

Axis name

Returns
axisTimeMapAxis

Time map axis.

is_aligned(other, atol=0.02)[source]#
is_allclose(other, **kwargs)[source]#

Check if other map axis is all close.

Parameters
otherTimeMapAxis

Other map axis

**kwargsdict

Keyword arguments forwarded to allclose

Returns
is_allclosebool

Whether other axis is allclose

static pix_to_idx(pix, clip=False)[source]#
slice(idx)[source]#

Create a new axis object by extracting a slice from this axis.

Parameters
idxslice

Slice object selecting a subselection of the axis.

Returns
axisTimeMapAxis

Sliced axis object.

squash()[source]#

Create a new axis object by squashing the axis into one bin.

Returns
axisMapAxis

Sliced axis object.

to_contiguous()[source]#

Make the time axis contiguous

Returns
axisTimeMapAxis

Contiguous time axis

to_header(format='gadf', idx=0)[source]#

Create FITS header

Parameters
format{“ogip”}

Format specification

idxint

Column index of the axis.

Returns
headerHeader

Header to extend.

upsample()[source]#