Query coincidences from a datafile

class sapphire.analysis.coincidence_queries.CoincidenceQuery(data, coincidence_group='/coincidences')

Perform queries on an ESD file where coincidences have been analysed.

Functions in this class build and perform queries to easily filter coincidences based on station participation and station organization. This assumes coincidences have been analysed using CoincidencesESD.

First initiate the class so it can get the correct tables, then get coincidences using one of the functions (all_coincidences, any, all, at_least), then get the events for these coincidences using other functions (all_events, events_from_[stations, subcluster, cluster]).

An exception will occur when you include a station in a query that does not occur in the datafile.

Example usage:

>>> from sapphire import CoincidenceQuery
>>> cq = CoincidenceQuery('2013_8_1.h5')
>>> coincidences = cq.all([501, 502, 503, 504], iterator=True)
>>> events = cq.all_events(coincidences)
>>> specific_events = cq.events_from_stations(coincidences,
...                                          [501, 502, 503, 504])
>>> cq.finish()

Setup variables to point to the tables

Parameters:
  • data – either a PyTables file or path to a HDF5 file.
  • coincidence_group – path to the coincidences group.
finish()

Clean-up after using

Do not use if you opened the file yourself and still intent to use it.

all_coincidences(iterator=False)

Get all coincidences

Returns:all coincidences.
any(stations, start=None, stop=None, iterator=False)

Filter for coincidences that contain any of the given stations

Parameters:stations – list of stations from which any need to be in a coincidence.
Returns:coincidences matching the query.
all(stations, start=None, stop=None, iterator=False)

Filter for coincidences that contain all of the given stations

Parameters:stations – list of stations which all need to be in a coincidence.
Returns:coincidences matching the query.
at_least(stations, n, start=None, stop=None, iterator=False)

Filter coincidences to contain at least n of the given stations

Parameters:
  • stations – list of stations from which any at least n of any combinations need to be in a coincidence.
  • n – minimum number of given stations to be in a coincidence.
Returns:

coincidences matching the query.

timerange(start, stop, iterator=False)

Query based on timestamps

Parameters:
  • start – timestamp from which to look for coincidences.
  • stop – end timestamp for coincidences.
Returns:

coincidences within the specified timerange.

perform_query(query, iterator=False)

Perform a query on the coincidences table

Parameters:query – a valid PyTables query string for the coincidences table.
Returns:coincidences matching the query.
all_events(coincidences, n=0)

Get all events for the given coincidences.

Parameters:
  • coincidences – list of coincidence rows.
  • n – minimum number of events per coincidence.
Returns:

list of events for each coincidence.

all_reconstructions(coincidences, n=0)

Get all reconstructed events for the given coincidences.

Parameters:
  • coincidences – list of coincidence rows.
  • n – minimum number of events per coincidence.
Returns:

list of reconstructed events for each coincidence.

minimum_events_for_coincidence(coincidences_events, n=2)

Filter coincidences to only include those with at least n events.

Parameters:
  • coincidences_events – list of events for each coincidence.
  • n – minimum number of events per coincidence.
events_from_stations(coincidences, stations, n=2)

Only get events for specific stations for coincidences.

Parameters:
  • coincidences – list of coincidence rows.
  • stations – list of station numbers to filter events for.
Returns:

list of filtered events for each coincidence.

reconstructions_from_stations(coincidences, stations, n=2)

Only get reconstructions for specific stations for coincidences.

Parameters:
  • coincidences – list of coincidence rows.
  • stations – list of station numbers to filter events for.
Returns:

list of filtered reconstructed events for each coincidence.

events_in_subcluster(coincidences, subcluster, n=2)

Filter to only events from stations in a specific subcluster

Parameters:
  • coincidences – list of events for each coincidence.
  • subcluster – subcluster number to filter events for.
Returns:

tuples of station numbers and events for matched events.

events_in_cluster(coincidences, cluster, n=2)

Filter to only events from stations in a specific subcluster

Parameters:
  • coincidences – list of events for each coincidence.
  • cluster – cluster number to filter events for.
Returns:

tuples of station numbers and events for matched events.