Reconstructions

Reconstruct HiSPARC events and coincidences

This module contains classes that can be used to reconstruct HiSPARC events and coincidences. These classes can be used to automate the tasks of reconstructing directions and/or cores.

The classes can reconstruct measured data from the ESD as well as simulated data from sapphire.simulations.

The classes read data stored in HDF5 files and extract station metadata (cluster and detector layout, station and detector offsets) from various sources:

Reconstructed data is stored in HDF5 files.
class sapphire.analysis.reconstructions.ReconstructESDEvents(data, station_group, station, overwrite=False, progress=True, verbose=False, destination='reconstructions', force_fresh=False, force_stale=False)

Reconstruct events from single stations

Example usage:

>>> import tables
>>> from sapphire import ReconstructESDEvents

>>> data = tables.open_file('2014_1_1.h5', 'a')
>>> station_path = '/hisparc/cluster_amsterdam/station_506'
>>> rec = ReconstructESDEvents(data, station_path, 506, overwrite=True)
>>> rec.reconstruct_and_store()

To visualize the results:

>>> import matplotlib.pyplot as plt
>>> plt.polar([p for p in rec.phi if not isnan(p)],
...           [t for t in rec.theta if not isnan(t)], 'ko', alpha=0.2)

or:

>>> plt.polar(rec.reconstructions.col('azimuth'),
...           rec.reconstructions.col('zenith'), 'ko', alpha=0.2)

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • station_group – the group containing the event table, the results will also be stored in this group.
  • station – either a station number or sapphire.clusters.Station object. If it is a number the positions and offsets will be retrieved from the public database or retrieved from the datafile when stored by a simulation. Otherwise the offsets will be determined with the available data.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
reconstruct_and_store(detector_ids=None)

Shorthand function to reconstruct event and store the results

reconstruct_directions(detector_ids=None)

Reconstruct direction for all events

Parameters:detector_ids – list of detector ids to use for reconstructions.
reconstruct_cores(detector_ids=None)

Reconstruct core for all events

Parameters:detector_ids – list of detector ids to use for reconstructions.
prepare_output()

Prepare output table

get_detector_offsets()

Get or determine detector offsets

Try to extract the offsets from the provided cluster object. If those are not available use the sapphire.api.Station object for the station number. Else determine the offsets from the event table.

  • if a cluster object is provided:
    • use offsets from that object if available in the object
    • else determine the offsets from the events in datafile with the provided cluster object.
  • if a station number is provided:
    • if a cluster object is stored in the datafile use offsets from that object if available.
    • else get offsets from api.Station object.
store_offsets()

Store the determined offset in a table.

store_reconstructions()

Loop over list of reconstructed data and store results

Unsuccessful reconstructions are also stored but with the NumPy NaN as reconstructed value.

class sapphire.analysis.reconstructions.ReconstructESDEventsFromSource(source_data, dest_data, source_group, dest_group, station, overwrite=False, progress=True, verbose=False, destination='reconstructions', force_fresh=False, force_stale=False)

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • station_group – the group containing the event table, the results will also be stored in this group.
  • station – either a station number or sapphire.clusters.Station object. If number the positions and offsets are retrieved from the public database. Otherwise the offsets will be determined with the available data.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
prepare_output()

Prepare output table

class sapphire.analysis.reconstructions.ReconstructSimulatedEvents(data, station_group, station, overwrite=False, progress=True, verbose=False, destination='reconstructions', force_fresh=False, force_stale=False)

Reconstruct simulated events from single stations

Simulated events use simulated meta-data (e.g. timing offsets) which are stored as a BaseCluster object The object is stored as an node attribute of ‘/coincidences’ in the HDF5 file. This class will try to read that object and use it’s meta-data in reconstructions.

The station number must match the station number in the stored object.

Example usage:

>>> import tables
>>> from sapphire import ReconstructESDEvents

>>> data = tables.open_file('simulation.h5', 'a')
>>> station_path = '/cluster_simulations/station_506'
>>> rec = ReconstructESDEvents(data, station_path, 506, overwrite=True)
>>> rec.reconstruct_and_store()

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • station_group – the group containing the event table, the results will also be stored in this group.
  • station – either a station number or sapphire.clusters.Station object. If it is a number the positions and offsets will be retrieved from the public database or retrieved from the datafile when stored by a simulation. Otherwise the offsets will be determined with the available data.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
class sapphire.analysis.reconstructions.ReconstructESDCoincidences(data, coincidences_group='/coincidences', overwrite=False, progress=True, verbose=False, destination='reconstructions', cluster=None, force_fresh=False, force_stale=False)

Reconstruct coincidences, e.g. event between multiple stations

Example usage:

>>> import tables
>>> from sapphire import ReconstructESDCoincidences

>>> data = tables.open_file('2014_1_1.h5', 'a')
>>> rec = ReconstructESDCoincidences(data, overwrite=True)
>>> rec.reconstruct_and_store()

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • coincidences_group – the destination group.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
  • cluster – a Cluster object to use for the reconstructions.
reconstruct_and_store(station_numbers=None)

Shorthand function to reconstruct coincidences and store results

reconstruct_directions(station_numbers=None)

Reconstruct direction for all events

Parameters:station_numbers – list of stations to use for reconstructions.
reconstruct_cores(station_numbers=None)

Reconstruct core for all events

Parameters:station_numbers – list of stations to use for reconstructions.
prepare_output()

Prepare output table

get_station_timing_offsets()

Construct a dict of Station objects

Try to extract offsets from provided cluster objects into a dictionary, to be used by the reconstructions. If the cluster is not available create a Station object for each station in the cluster.

store_reconstructions()

Loop over list of reconstructed data and store results

Unsuccessful reconstructions are also stored but with the NumPy NaN as reconstructed value.

class sapphire.analysis.reconstructions.ReconstructESDCoincidencesFromSource(source_data, dest_data, source_group, dest_group, overwrite=False, progress=True, verbose=False, destination='reconstructions', cluster=None, force_fresh=False, force_stale=False)

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • station_group – the group containing the event table, the results will also be stored in this group.
  • station – either a station number or sapphire.clusters.Station object. If number the positions and offsets are retrieved from the public database. Otherwise the offsets will be determined with the available data.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
prepare_output()

Prepare output table

class sapphire.analysis.reconstructions.ReconstructSimulatedCoincidences(data, coincidences_group='/coincidences', overwrite=False, progress=True, verbose=False, destination='reconstructions', cluster=None, force_fresh=False, force_stale=False)

Reconstruct simulated coincidences.

Simulated coincidences use simulated meta-data (e.g. timing offsets) which are stored as a BaseCluster object The object is stored as an node attribute of ‘/coincidences’ in the HDF5 file. This class will try to read that object and use it’s meta-data in reconstructions.

Example usage:

>>> import tables
>>> from sapphire import ReconstructSimulatedCoincidences

>>> data = tables.open_file('simulated.h5', 'a')
>>> rec = ReconstructSimulatedCoincidences(data, overwrite=True)
>>> rec.reconstruct_and_store()

Initialize the class.

Parameters:
  • data – the PyTables datafile.
  • coincidences_group – the destination group.
  • overwrite – if True overwrite existing reconstruction table.
  • progress – if True show a progressbar while reconstructing.
  • verbose – if True be verbose about station metadata usage.
  • destination – alternative name for reconstruction table.
  • cluster – a Cluster object to use for the reconstructions.