DataWriter

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

Bases: ctapipe.core.component.Component

Serialize a sequence of events into a HDF5 file, in the correct format

Examples

inside a Tool:

with DataWriter(parent=self) as write_data:
    for event in source:
        calibrate(event)
        process_images(event)
        write_data(event)

Attributes Summary

compression_level

An int trait.

compression_type

An enum of strings where the case should be ignored.

contact_info

A trait whose value must be an instance of a specified class.

context_metadata

An instance of a Python dict.

datalevels

returns a list of data levels requested

image_dtype

A trait for unicode strings.

image_offset

An int trait.

image_scale

A float trait.

instrument_info

A trait whose value must be an instance of a specified class.

output_path

A path Trait for input/output files.

overwrite

A boolean (True, False) trait.

peak_time_dtype

A trait for unicode strings.

peak_time_offset

An int trait.

peak_time_scale

A float trait.

transform_image

A boolean (True, False) trait.

transform_peak_time

A boolean (True, False) trait.

transform_waveform

A boolean (True, False) trait.

waveform_dtype

A trait for unicode strings.

waveform_offset

An int trait.

waveform_scale

A float trait.

write_images

A boolean (True, False) trait.

write_index_tables

A boolean (True, False) trait.

write_parameters

A boolean (True, False) trait.

write_raw_waveforms

A boolean (True, False) trait.

write_showers

A boolean (True, False) trait.

write_waveforms

A boolean (True, False) trait.

Methods Summary

__call__(event)

Write a single event to the output file.

finish()

called after all events are done

table_name(tel_id)

construct dataset table names depending on chosen split method

write_simulation_histograms(event_source)

Write the distribution of thrown showers

Attributes Documentation

compression_level

An int trait.

compression_type

An enum of strings where the case should be ignored.

contact_info

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

context_metadata

An instance of a Python dict.

One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.

Changed in version 5.0: Added key_trait for validating dict keys.

Changed in version 5.0: Deprecated ambiguous trait, traits args in favor of value_trait, per_key_traits.

datalevels

returns a list of data levels requested

image_dtype

A trait for unicode strings.

image_offset

An int trait.

image_scale

A float trait.

instrument_info

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

output_path

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

overwrite

A boolean (True, False) trait.

peak_time_dtype

A trait for unicode strings.

peak_time_offset

An int trait.

peak_time_scale

A float trait.

transform_image

A boolean (True, False) trait.

transform_peak_time

A boolean (True, False) trait.

transform_waveform

A boolean (True, False) trait.

waveform_dtype

A trait for unicode strings.

waveform_offset

An int trait.

waveform_scale

A float trait.

write_images

A boolean (True, False) trait.

write_index_tables

A boolean (True, False) trait.

write_parameters

A boolean (True, False) trait.

write_raw_waveforms

A boolean (True, False) trait.

write_showers

A boolean (True, False) trait.

write_waveforms

A boolean (True, False) trait.

Methods Documentation

__call__(event: ctapipe.containers.ArrayEventContainer)[source]

Write a single event to the output file.

finish()[source]

called after all events are done

table_name(tel_id)[source]

construct dataset table names depending on chosen split method

write_simulation_histograms(event_source)[source]

Write the distribution of thrown showers

Notes

  • this only runs if this is a simulation file. The current implementation is a bit of a hack and implies we should improve SimTelEventSource to read this info.

  • Currently the histograms are at the end of the simtel file, so if max_events is set to non-zero, the end of the file may not be read, and this no histograms will be found.