ObservationTable¶
-
class
gammapy.data.
ObservationTable
(data=None, masked=None, names=None, dtype=None, meta=None, copy=True, rows=None, copy_indices=True, **kwargs)[source]¶ Bases:
astropy.table.Table
Observation table.
This is an
Table
sub-class, with a few convenience methods. The format of the observation table is described in Observation lists.Attributes Summary
pointing_galactic
Pointing positions as Galactic ( SkyCoord
)pointing_radec
Pointing positions as ICRS ( SkyCoord
)Methods Summary
get_obs_idx
(obs_id)Get row index for given obs_id
.read
(filename, **kwargs)Read an observation table from file. select_linspace_subset
(num)Select subset of observations. select_obs_id
(obs_id)Get ObservationTable
containing onlyobs_id
.select_observations
([selection])Select subset of observations. select_range
(selection_variable, value_range)Make an observation table, applying some selection. select_time_range
(selection_variable, time_range)Make an observation table, applying a time selection. summary
([file])Info string (str) Attributes Documentation
Methods Documentation
-
get_obs_idx
(obs_id)[source]¶ Get row index for given
obs_id
.Raises KeyError if observation is not available.
Parameters: obs_id : int, list
observation ids
Returns: idx : list
indices corresponding to obs_id
-
classmethod
read
(filename, **kwargs)[source]¶ Read an observation table from file.
Parameters: filename :
Path
, strFilename
-
select_linspace_subset
(num)[source]¶ Select subset of observations.
This is mostly useful for testing, if you want to make the analysis run faster.
Parameters: num : int
Number of samples to select.
Returns: table :
ObservationTable
Subset observation table (a copy).
-
select_obs_id
(obs_id)[source]¶ Get
ObservationTable
containing onlyobs_id
.Raises KeyError if observation is not available.
Parameters: obs_id: int, list
observation ids
-
select_observations
(selection=None)[source]¶ Select subset of observations.
Returns a new observation table representing the subset.
There are 3 main kinds of selection criteria, according to the value of the type keyword in the selection dictionary:
- sky regions (boxes or circles)
- time intervals (min, max)
- intervals (min, max) on any other parameter present in the
observation table, that can be casted into an
Quantity
object
Allowed selection criteria are interpreted using the following keywords in the selection dictionary under the type key.
sky_box
andsky_circle
are 2D selection criteria acting on sky coordinatessky_box
is a squared region delimited by the lon and lat keywords: both tuples of format (min, max); usesselect_sky_box
sky_circle
is a circular region centered in the coordinate marked by the lon and lat keywords, and radius radius; usesselect_sky_circle
in each case, the coordinate system can be specified by the frame keyword (built-in Astropy coordinate frames are supported, e.g.
icrs
orgalactic
); an aditional border can be defined using the border keywordtime_box
is a 1D selection criterion acting on the observation start time (TSTART); the interval is set via the time_range keyword; usesselect_time_range
par_box
is a 1D selection criterion acting on any parameter defined in the observation table that can be casted into anQuantity
object; the parameter name and interval can be specified using the keywords variable and value_range respectively; min = max selects exact values of the parameter; usesselect_range
In all cases, the selection can be inverted by activating the inverted flag, in which case, the selection is applied to keep all elements outside the selected range.
A few examples of selection criteria are given below.
Parameters: selection : dict
Dictionary with a few keywords for applying selection cuts.
Returns: obs_table :
ObservationTable
Observation table after selection.
Examples
>>> selection = dict(type='sky_box', frame='icrs', ... lon=Angle([150, 300], 'deg'), ... lat=Angle([-50, 0], 'deg'), ... border=Angle(2, 'deg')) >>> selected_obs_table = obs_table.select_observations(selection)
>>> selection = dict(type='sky_circle', frame='galactic', ... lon=Angle(0, 'deg'), ... lat=Angle(0, 'deg'), ... radius=Angle(5, 'deg'), ... border=Angle(2, 'deg')) >>> selected_obs_table = obs_table.select_observations(selection)
>>> selection = dict(type='time_box', ... time_range=Time(['2012-01-01T01:00:00', '2012-01-01T02:00:00'])) >>> selected_obs_table = obs_table.select_observations(selection)
>>> selection = dict(type='par_box', variable='ALT', ... value_range=Angle([60., 70.], 'deg')) >>> selected_obs_table = obs_table.select_observations(selection)
>>> selection = dict(type='par_box', variable='OBS_ID', ... value_range=[2, 5]) >>> selected_obs_table = obs_table.select_observations(selection)
>>> selection = dict(type='par_box', variable='N_TELS', ... value_range=[4, 4]) >>> selected_obs_table = obs_table.select_observations(selection)
-
select_range
(selection_variable, value_range, inverted=False)[source]¶ Make an observation table, applying some selection.
Generic function to apply a 1D box selection (min, max) to a table on any variable that is in the observation table and can be casted into a
Quantity
object.If the range length is 0 (min = max), the selection is applied to the exact value indicated by the min value. This is useful for selection of exact values, for instance in discrete variables like the number of telescopes.
If the inverted flag is activated, the selection is applied to keep all elements outside the selected range.
Parameters: selection_variable : str
Name of variable to apply a cut (it should exist on the table).
value_range :
Quantity
-likeAllowed range of values (min, max). The type should be consistent with the selection_variable.
inverted : bool, optional
Invert selection: keep all entries outside the (min, max) range.
Returns: obs_table :
ObservationTable
Observation table after selection.
-
select_time_range
(selection_variable, time_range, inverted=False)[source]¶ Make an observation table, applying a time selection.
Apply a 1D box selection (min, max) to a table on any time variable that is in the observation table. It supports both fomats: absolute times in
Time
variables and [MET].If the inverted flag is activated, the selection is applied to keep all elements outside the selected range.
Parameters: selection_variable : str
Name of variable to apply a cut (it should exist on the table).
time_range :
Time
Allowed time range (min, max).
inverted : bool, optional
Invert selection: keep all entries outside the (min, max) range.
Returns: obs_table :
ObservationTable
Observation table after selection.
-