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 is the time delta w.r.t. to the reference time.

edges_maxQuantity

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

reference_timeTime

Reference time to use.

namestr, optional

Axis name. Default is “time”.

interp{‘lin’}

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

Attributes Summary

as_plot_center

Return center for plotting.

as_plot_edges

Return edges for plotting.

as_plot_labels

Return labels for plotting.

as_plot_xerr

Return x errors for plotting.

bin_width

Return time interval width as a Quantity.

bounds

Bounds of the axis as a ~astropy.units.Quantity.

center

Return interval centers as a Quantity.

edges

Return the array of bin edges values.

edges_max

Return the array of bin edges minimum values.

edges_min

Return the array of bin edges maximum values.

interp

Interpolation scale of the axis.

is_contiguous

Whether the axis is contiguous.

iter_by_edges

Iterate by intervals defined by the edges.

name

Return the axis name.

nbin

Return the number of bins in the axis.

node_type

reference_time

Return reference time used for the axis.

time_bounds

Bounds of the axis as a ~astropy.units.Quantity.

time_delta

Return axis time bin width as a TimeDelta object.

time_edges

Time edges as a Time object.

time_format

time_max

Return axis upper edges as a Time object.

time_mid

Return time bin center as a Time object.

time_min

Return axis lower edges as Time object.

unit

Axis unit.

Methods Summary

assert_name(required_name)

Assert axis name if a specific one is required.

coord_to_idx(coord, **kwargs)

Transform time axis coordinate to bin index.

coord_to_pix(coord, **kwargs)

Transform time axis coordinate to pixel position.

copy(**kwargs)

Copy TimeMapAxis instance and overwrite given attributes.

downsample()

Not supported for time axis.

format_plot_xaxis(ax)

Format the x-axis.

from_gti(gti[, name])

Create a time axis from an input GTI.

from_gti_bounds(gti, t_delta[, 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 a Time object.

group_table(interval_edges)

Compute bin groups table for the TimeMapAxis, given coarser bin edges.

is_aligned(other[, atol])

Not supported for time axis.

is_allclose(other, **kwargs)

Check if other time map axis is all close.

pix_to_coord(pix)

Transform from pixel position to time coordinate.

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_gti()

Convert the axis to a GTI table.

to_header([format, idx])

Create FITS header.

upsample()

Not supported for time axis.

Attributes Documentation

as_plot_center#

Return center for plotting.

as_plot_edges#

Return edges for plotting.

as_plot_labels#

Return labels for plotting.

as_plot_xerr#

Return x errors for plotting.

bin_width#

Return time interval width as a Quantity.

bounds#

Bounds of the axis as a ~astropy.units.Quantity.

center#

Return interval centers as a Quantity.

edges#

Return the array of bin edges values.

edges_max#

Return the array of bin edges minimum values.

edges_min#

Return the array of bin edges maximum values.

interp#

Interpolation scale of the axis.

is_contiguous#

Whether the axis is contiguous.

iter_by_edges#

Iterate by intervals defined by the edges.

name#

Return the axis name.

nbin#

Return the number of bins in the axis.

node_type = 'intervals'#
reference_time#

Return reference time used for the axis.

time_bounds#

Bounds of the axis as a ~astropy.units.Quantity.

time_delta#

Return axis time bin width as a TimeDelta object.

time_edges#

Time edges as a Time object.

time_format = 'iso'#
time_max#

Return axis upper edges as a Time object.

time_mid#

Return time bin center as a Time object.

time_min#

Return axis lower edges as Time object.

unit#

Axis unit.

Methods Documentation

assert_name(required_name)[source]#

Assert axis name if a specific one is required.

Parameters
required_namestr

Required name.

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

Transform time axis coordinate to bin index.

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

Parameters
coordTime or Quantity

Array of time 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 time axis coordinate to pixel position.

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

Parameters
coordTime

Array of time axis coordinate values.

Returns
pixndarray

Array of pixel positions.

copy(**kwargs)[source]#

Copy TimeMapAxis instance and overwrite given attributes.

Parameters
**kwargsdict, optional

Keyword arguments to overwrite in the map axis constructor.

Returns
copyTimeMapAxis

Copied time map axis.

downsample()[source]#

Not supported for time axis.

format_plot_xaxis(ax)[source]#

Format the x-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, optional

Axis name. Default is “time”.

Returns
axisTimeMapAxis

Time map axis.

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

Create a time axis from an input GTI.

The unit for the axis is taken from the t_delta quantity.

Parameters
gtiGTI

GTI table.

t_deltaQuantity

Time binning.

namestr, optional

Axis name. Default is “time”.

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. Default is “gadf”.

idxint

Axis index. Default is 0.

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.

unitUnit or str, optional

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

namestr, optional

Name of the axis. Default is “time”.

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

Create TimeMapAxis from the time interval edges defined as a Time object.

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, optional

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

interp{‘lin’}

Interpolation method used to transform between axis and pixel coordinates. Currently, only ‘lin’ is supported. Default is ‘lin’.

namestr, optional

Axis name. Default is “time”.

Returns
axisTimeMapAxis

Time map axis.

group_table(interval_edges)[source]#

Compute bin groups table for the TimeMapAxis, given coarser bin edges.

Parameters
interval_edgeslist of Time or Quantity

Start and stop time for each interval to compute the LC.

Returns
groupsTable

Group table. Bin groups are divided in:

*”normal” for the bins containing data *”underflow” for the bins falling below the minimum axis threshold *”overflow” for the bins falling above the maximum axis threshold *”outflow” for other states

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

Not supported for time axis.

is_allclose(other, **kwargs)[source]#

Check if other time map axis is all close.

Parameters
otherTimeMapAxis

Other time map axis.

**kwargsdict, optional

Keyword arguments forwarded to allclose.

Returns
is_allclosebool

Whether the other time map axis is allclose.

pix_to_coord(pix)[source]#

Transform from pixel position to time coordinate. Currently, works only for linear interpolation scheme.

Parameters
pixndarray

Array of pixel positions.

Returns
coordTime

Array of time axis coordinate values.

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 sub-selection of the axis.

Returns
axisTimeMapAxis

Sliced time map axis object.

squash()[source]#

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

Returns
axisMapAxis

Squashed time map axis object.

to_contiguous()[source]#

Make the time axis contiguous.

Returns
axisTimeMapAxis

Contiguous time axis.

to_gti()[source]#

Convert the axis to a GTI table.

Returns
gtiGTI

GTI table.

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

Create FITS header.

Parameters
format{“ogip”}

Format specification. Default is “gadf”.

idxint, optional

Column index of the axis. Default is 0.

Returns
headerHeader

Corresponding FITS header.

upsample()[source]#

Not supported for time axis.