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_min
Quantity
Array of edge time values. This is the time delta w.r.t. to the reference time.
- edges_max
Quantity
Array of edge time values. This is the time delta w.r.t. to the reference time.
- reference_time
Time
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’.
- edges_min
Attributes Summary
Return center for plotting.
Return edges for plotting.
Return labels for plotting.
Return x errors for plotting.
Return time interval width as a
Quantity
.Bounds of the axis as a ~astropy.units.Quantity.
Return interval centers as a
Quantity
.Return the array of bin edges values.
Return the array of bin edges minimum values.
Return the array of bin edges maximum values.
Interpolation scale of the axis.
Whether the axis is contiguous.
Iterate by intervals defined by the edges.
Return the axis name.
Return the number of bins in the axis.
Return reference time used for the axis.
Bounds of the axis as a ~astropy.units.Quantity.
Return axis time bin width as a
TimeDelta
object.Time edges as a
Time
object.Return axis upper edges as a
Time
object.Return time bin center as a
Time
object.Return axis lower edges as
Time
object.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.Not supported for time axis.
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.
Make the time axis contiguous.
to_gti
()Convert the axis to a GTI table.
to_header
([format, idx])Create FITS header.
to_table
()Create table.
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.
- bounds#
Bounds of the axis as a ~astropy.units.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_format = 'iso'#
- 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.
- 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.
- copy(**kwargs)[source]#
Copy
TimeMapAxis
instance and overwrite given attributes.- Parameters:
- **kwargsdict, optional
Keyword arguments to overwrite in the map axis constructor.
- Returns:
- copy
TimeMapAxis
Copied time map axis.
- copy
- format_plot_xaxis(ax)[source]#
Format the x-axis.
- Parameters:
- ax
Axis
Plot axis to format.
- ax
- Returns:
- ax
Axis
Formatted plot axis.
- ax
- classmethod from_gti(gti, name='time')[source]#
Create a time axis from an input GTI.
- Parameters:
- gti
GTI
GTI table.
- namestr, optional
Axis name. Default is “time”.
- gti
- Returns:
- axis
TimeMapAxis
Time map axis.
- 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:
- Returns:
- axis
TimeMapAxis
Time map axis.
- axis
- classmethod from_table(table, format='gadf', idx=0)[source]#
Create time map axis from table
- Parameters:
- table
Table
Bin table HDU.
- format{“gadf”, “fermi-fgl”, “lightcurve”}
Format to use. Default is “gadf”.
- idxint
Axis index. Default is 0.
- table
- Returns:
- axis
TimeMapAxis
Time map axis.
- axis
- classmethod from_time_bounds(time_min, time_max, nbin, unit='d', name='time')[source]#
Create linearly spaced time axis from bounds.
- 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_min
Time
Array of lower edge times.
- time_max
Time
Array of lower edge times.
- unit
Unit
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”.
- time_min
- Returns:
- axis
TimeMapAxis
Time map axis.
- axis
- group_table(interval_edges)[source]#
Compute bin groups table for the TimeMapAxis, given coarser bin edges.
- Parameters:
- Returns:
- groups
Table
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
- groups
- is_allclose(other, **kwargs)[source]#
Check if other time map axis is all close.
- Parameters:
- other
TimeMapAxis
Other time map axis.
- **kwargsdict, optional
Keyword arguments forwarded to
allclose
.
- other
- 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.
- slice(idx)[source]#
Create a new axis object by extracting a slice from this axis.
- Parameters:
- idx
slice
Slice object selecting a sub-selection of the axis.
- idx
- Returns:
- axis
TimeMapAxis
Sliced time map axis object.
- axis
Examples
>>> from gammapy.maps import TimeMapAxis >>> import astropy.units as u >>> from astropy.time import Time >>> time_map_axis = TimeMapAxis( ... edges_min=[1, 5, 10, 15] * u.day, ... edges_max=[2, 7, 13, 18] * u.day, ... reference_time=Time("2020-03-19"), ... ) >>> slices = slice(1, 3) >>> sliced = time_map_axis.slice(slices)
- squash()[source]#
Create a new axis object by squashing the axis into one bin.
- Returns:
- axis
TimeMapAxis
Squashed time map axis object.
- axis
- to_contiguous()[source]#
Make the time axis contiguous.
- Returns:
- axis
TimeMapAxis
Contiguous time axis.
- axis