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.TableObservation table.
This is an
Tablesub-class, with a few convenience methods. The format of the observation table is described in Observation lists.Attributes Summary
pointing_galacticPointing positions as Galactic ( SkyCoord)pointing_radecPointing 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 ObservationTablecontaining 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 :
ObservationTableSubset observation table (a copy).
-
select_obs_id(obs_id)[source]¶ Get
ObservationTablecontaining 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
Quantityobject
Allowed selection criteria are interpreted using the following keywords in the selection dictionary under the type key.
sky_boxandsky_circleare 2D selection criteria acting on sky coordinatessky_boxis a squared region delimited by the lon and lat keywords: both tuples of format (min, max); usesselect_sky_boxsky_circleis 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.
icrsorgalactic); an aditional border can be defined using the border keywordtime_boxis a 1D selection criterion acting on the observation start time (TSTART); the interval is set via the time_range keyword; usesselect_time_rangepar_boxis a 1D selection criterion acting on any parameter defined in the observation table that can be casted into anQuantityobject; 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 :
ObservationTableObservation 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
Quantityobject.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 :
ObservationTableObservation 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
Timevariables 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 :
TimeAllowed time range (min, max).
inverted : bool, optional
Invert selection: keep all entries outside the (min, max) range.
Returns: obs_table :
ObservationTableObservation table after selection.
-