TableLoader

class ctapipe.io.tableloader.TableLoader(**kwargs: Any)[source]

Bases: ctapipe.core.component.Component

Load telescope-event or subarray-event data from ctapipe HDF5 files

This class provides high-level access to data stored in ctapipe HDF5 files, such as created by the ctapipe-process tool (ProcessorTool).

The following TableLoader methods load data from all relevant tables, depending on the options, and joins them into single tables:

Attributes
subarraySubarrayDescription

The subarray as read from input_url.

Attributes Summary

focal_length_choice

Use a Enum class as model for the data type description.

input_url

A path Trait for input/output files.

load_dl1_images

A boolean (True, False) trait.

load_dl1_parameters

A boolean (True, False) trait.

load_dl2

A boolean (True, False) trait.

load_instrument

A boolean (True, False) trait.

load_observation_info

A boolean (True, False) trait.

load_simulated

A boolean (True, False) trait.

load_true_images

A boolean (True, False) trait.

load_true_parameters

A boolean (True, False) trait.

Methods Summary

close()

Close the underlying hdf5 file

read_observation_information([start, stop])

Read the observation information

read_shower_distribution()

Read the simulated shower distribution histograms

read_simulation_configuration()

Read the simulation configuration table

read_subarray_events([start, stop, keep_order])

Read subarray-based event information.

read_subarray_events_chunked(chunk_size, …)

Iterate over chunks of subarray events.

read_telescope_events([telescopes, start, stop])

Read telescope-based event information.

read_telescope_events_by_id([telescopes, …])

Read telescope-based event information.

read_telescope_events_by_id_chunked(…)

Iterate over chunks of telescope events and return a dict of one table per telescope id.

read_telescope_events_by_type([telescopes, …])

Read telescope-based event information.

read_telescope_events_by_type_chunked(…)

Iterate over chunks of telescope events as dicts of telescope type to tables.

read_telescope_events_chunked(chunk_size, …)

Iterate over chunks of telescope events.

Attributes Documentation

focal_length_choice

Use a Enum class as model for the data type description. Note that if no default-value is provided, the first enum-value is used as default-value.

# -- SINCE: Python 3.4 (or install backport: pip install enum34)
import enum
from traitlets import HasTraits, UseEnum

class Color(enum.Enum):
    red = 1         # -- IMPLICIT: default_value
    blue = 2
    green = 3

class MyEntity(HasTraits):
    color = UseEnum(Color, default_value=Color.blue)

entity = MyEntity(color=Color.red)
entity.color = Color.green    # USE: Enum-value (preferred)
entity.color = "green"        # USE: name (as string)
entity.color = "Color.green"  # USE: scoped-name (as string)
entity.color = 3              # USE: number (as int)
assert entity.color is Color.green
input_url

A path Trait for input/output files.

Attributes
exists: boolean or None

If True, path must exist, if False path must not exist

directory_ok: boolean

If False, path must not be a directory

file_ok: boolean

If False, path must not be a file

load_dl1_images

A boolean (True, False) trait.

load_dl1_parameters

A boolean (True, False) trait.

load_dl2

A boolean (True, False) trait.

load_instrument

A boolean (True, False) trait.

load_observation_info

A boolean (True, False) trait.

load_simulated

A boolean (True, False) trait.

load_true_images

A boolean (True, False) trait.

load_true_parameters

A boolean (True, False) trait.

Methods Documentation

close()[source]

Close the underlying hdf5 file

read_observation_information(start=None, stop=None)[source]

Read the observation information

read_shower_distribution()[source]

Read the simulated shower distribution histograms

read_simulation_configuration()[source]

Read the simulation configuration table

read_subarray_events(start=None, stop=None, keep_order=True)[source]

Read subarray-based event information.

Returns
table: astropy.io.Table

Table with primary index columns “obs_id” and “event_id”.

read_subarray_events_chunked(chunk_size, *args, **kwargs)[source]

Iterate over chunks of subarray events.

Parameters
chunk_size: int

Number of subarray events to load per chunk

read_telescope_events(telescopes=None, start=None, stop=None)[source]

Read telescope-based event information.

If the corresponding traitlets are True, also subarray event information is joined onto the table.

The start, stop parameters enable to only load parts of the file, note however, to maintain integrity of subarray events, these refer to the subarray indices in the file. E.g. start=0, stop=10 would load the telescope events corresponding to the first 10 subarray events in the input file.

Parameters
telescopes: Optional[List[Union[int, str, TelescopeDescription]]]

A list containing any combination of telescope IDs and/or telescope descriptions. If None, all available telescopes are read.

start: int

First subarray event to read

stop: int

Last subarray event (non-inclusive)

Returns
events: astropy.io.Table

Table with primary index columns “obs_id”, “event_id” and “tel_id”.

read_telescope_events_by_id(telescopes=None, start=None, stop=None)Dict[int, astropy.table.table.Table][source]

Read telescope-based event information.

Parameters
telescopes: List[Union[int, str, TelescopeDescription]]

Any list containing a combination of telescope IDs or telescope_descriptions.

Returns
tables: dict(astropy.io.Table)

Dictionary of tables organized by telescope ids Table with primary index columns “obs_id”, “event_id” and “tel_id”.

read_telescope_events_by_id_chunked(chunk_size, *args, **kwargs)[source]

Iterate over chunks of telescope events and return a dict of one table per telescope id.

Parameters
chunk_size: int

Number of subarray events to load per chunk. The telescope tables might be larger or smaller than chunk_size depending on the selected telescopes.

*args, **kwargs are passed to `read_telescope_events_by_id`
read_telescope_events_by_type(telescopes=None, start=None, stop=None)Dict[str, astropy.table.table.Table][source]

Read telescope-based event information.

Parameters
telescopes: List[Union[int, str, TelescopeDescription]]

Any list containing a combination of telescope IDs or telescope_descriptions.

Returns
tables: dict(astropy.io.Table)

Dictionary of tables organized by telescope types Table with primary index columns “obs_id”, “event_id” and “tel_id”.

read_telescope_events_by_type_chunked(chunk_size, *args, **kwargs)[source]

Iterate over chunks of telescope events as dicts of telescope type to tables.

Parameters
chunk_size: int

Number of subarray events to load per chunk. The telescope tables might be larger or smaller than chunk_size depending on the selected telescopes.

**kwargs are passed to `read_telescope_events`
read_telescope_events_chunked(chunk_size, *args, **kwargs)[source]

Iterate over chunks of telescope events.

Parameters
chunk_size: int

Number of subarray events to load per chunk. The telescope tables might be larger or smaller than chunk_size depending on the selected telescopes.

**kwargs are passed to `read_telescope_events`