HiSPARC API

Access the HiSPARC public database API.

This provides easy classes and functions to access the HiSPARC publicdb API. This takes care of the url retrieval and conversion from JSON to Python dictionaries.

Example usage:

>>> from sapphire import Station
>>> stations = [5, 3102, 504, 7101, 8008, 13005]
>>> clusters = [Station(station).cluster for station in stations]
>>> for station, cluster in zip(stations, clusters):
...     print 'Station %d is in cluster %s.' % (station, cluster)
Station 5 is in cluster Amsterdam.
Station 3102 is in cluster Leiden.
Station 504 is in cluster Amsterdam.
Station 7101 is in cluster Enschede.
Station 8008 is in cluster Eindhoven.
Station 13005 is in cluster Bristol.
class sapphire.api.API(force_fresh=False, force_stale=False)

Base API class

This provided the methods to retrieve data from the API. The results are converted from JSON data to Python objects (dict/list/etc). Support is also provided for the retrieval of Source TSV data, which is returned as NumPy arrays.

Initialize API class

Parameters:force_fresh,force_stale – if either of these is set to True the data must either loaded from server or from local data. Be default fresh data is prefered, but falls back to local data.
urls = {'stations_in_subcluster': 'subclusters/{subcluster_number}/', 'event_trace': 'station/{station_number}/trace/{ext_timestamp}/', 'subclusters_in_cluster': 'clusters/{cluster_number}/', 'pulseheight_drift': 'station/{station_number}/plate/{plate_number}/pulseheight/drift/{year}/{month}/{day}/{number_of_days}/', 'stations': 'stations/', 'clusters_in_country': 'countries/{country_number}/', 'station_info': 'station/{station_number}/', 'countries': 'countries/', 'subclusters': 'subclusters/', 'pulseheight_fit': 'station/{station_number}/plate/{plate_number}/pulseheight/fit/{year}/{month}/{day}/', 'stations_with_data': 'stations/data/{year}/{month}/{day}/', 'number_of_events': 'station/{station_number}/num_events/{year}/{month}/{day}/{hour}/', 'clusters': 'clusters/', 'configuration': 'station/{station_number}/config/{year}/{month}/{day}/', 'has_weather': 'station/{station_number}/weather/{year}/{month}/{day}/', 'stations_with_weather': 'stations/weather/{year}/{month}/{day}/', 'has_data': 'station/{station_number}/data/{year}/{month}/{day}/'}
src_urls = {'coincidencetime': 'coincidencetime/{year}/{month}/{day}/', 'eventtime': 'eventtime/{station_number}/{year}/{month}/{day}/', 'barometer': 'barometer/{station_number}/{year}/{month}/{day}/', 'temperature': 'temperature/{station_number}/{year}/{month}/{day}/', 'zenith': 'zenith/{station_number}/{year}/{month}/{day}/', 'pulseheight': 'pulseheight/{station_number}/{year}/{month}/{day}/', 'integral': 'pulseintegral/{station_number}/{year}/{month}/{day}/', 'detector_timing_offsets': 'detector_timing_offsets/{station_number}/', 'current': 'current/{station_number}/', 'station_timing_offsets': 'station_timing_offsets/{station_1}/{station_2}/', 'trigger': 'trigger/{station_number}/', 'voltage': 'voltage/{station_number}/', 'azimuth': 'azimuth/{station_number}/{year}/{month}/{day}/', 'layout': 'layout/{station_number}/', 'electronics': 'electronics/{station_number}/', 'coincidencenumber': 'coincidencenumber/{year}/{month}/{day}/', 'gps': 'gps/{station_number}/'}
static check_connection()

Open the API man page URL to test the connection

Returns:boolean indicating the internet status
static validate_partial_date(year='', month='', day='', hour='')
class sapphire.api.Network(force_fresh=False, force_stale=False)

Get info about the network (countries/clusters/subclusters/stations)

Initialize API class

Parameters:force_fresh,force_stale – if either of these is set to True the data must either loaded from server or from local data. Be default fresh data is prefered, but falls back to local data.
countries()

Get a list of countries

Returns:all countries in the region
country_numbers()

Same as countries but only retuns a list of country numbers

clusters(country=None)

Get a list of clusters

Parameters:country – the number of the country for which to get all clusters.
Returns:all clusters in the region
cluster_numbers(country=None)

Same as clusters but only retuns a list of cluster numbers

subclusters(country=None, cluster=None)

Get a list of subclusters

Parameters:country,cluster – the number of the region for which to get the subclusters it contains, only one or none should be specified.
Returns:all subclusters in the region
subcluster_numbers(country=None, cluster=None)

Same as subclusters but only retuns a list of subcluster numbers

stations(country=None, cluster=None, subcluster=None)

Get a list of stations

Parameters:country,cluster,subcluster – the number of the region for which to get all stations, only one or none should be specified.
Returns:all stations in the region
station_numbers(country=None, cluster=None, subcluster=None)

Same as stations but only retuns a list of station numbers

nested_network()

Get a nested list of the full network

stations_with_data(year='', month='', day='')

Get a list of stations with data on the specified date

Parameters:year,month,day – the date for which to check. It is possible to be less specific.
Returns:all stations with data.
stations_with_weather(year='', month='', day='')

Get a list of stations with weather data on the specified date

Parameters:year,month,day – the date for which to check. It is possible to be less specific.
Returns:all stations with weather data.
coincidence_time(year, month, day)

Get the coincidences per hour histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
coincidence_number(year, month, day)

Get the number of stations in coincidence histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
static validate_numbers(country=None, cluster=None, subcluster=None)
uptime(stations, start=None, end=None)

Get number of hours which stations have been simultaneously active

Using hourly eventrate data the number of hours in which the given stations all had data is determined. Only hours in which each station had a reasonable eventrate are counted, to exclude bad data.

Parameters:
  • stations – station number or a list of station numbers.
  • start,end – start, end timestamp.
Returns:

number of hours with simultaneous data.

class sapphire.api.Station(station, force_fresh=False, force_stale=False)

Access data about a single station

Initialize station

Parameters:
  • station – station number.
  • force_fresh – set to True to require data to be fresh from the server.
  • force_stale – set to True to require data to be taken from local data, not valid for all methods.
info

Get general station info

country()
cluster()
subcluster()
n_detectors()

Get the number of detectors in this station

config(date=None)

Get station config

Retrieve either the latest, or a config for a specific date.

Parameters:date – date object for which to get the config
Returns:the full config for the station
n_events(year='', month='', day='', hour='')

Get number of events

Note that it is possible to give only the year to get the total number of events in that year. If both year and month are given, the total events in that month are returned.

Parameters:year,month,day,hour – the date and time for which to get the number. It is possible to be less specific.
Returns:the number of events recorded by the station on date.
has_data(year='', month='', day='')

Check for HiSPARC data

Parameters:year,month,day – the date for which to check. It is possible to be less specific.
Returns:boolean, indicating wether the station had air shower data on the date.
has_weather(year='', month='', day='')

Check for weather data

Parameters:year,month,day – the date for which to check. It is possible to be less specific.
Returns:boolean, indicating wether the station had weather data on the date.
event_trace(timestamp, nanoseconds, raw=False)

Get the traces for a specific event

The exact timestamp and nanoseconds for the event have to be given.

Parameters:
  • timestamp,nanoseconds – the extended timestamp for which to get the traces.
  • raw – get the raw trace, without the subtracted baselines.
Returns:

an array with the traces for each detector in ADCcounts

event_time(year='', month='', day='')

Get the number of events per hour histogram

If no date is given the full event time histogram for this station will be returned. That means for the entire time this station has collected data.

This data (the full histogram) can made available locally using the extend_local_data command.

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
pulse_height(year, month, day)

Get the pulseheight histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
pulse_integral(year, month, day)

Get the pulseintegral histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
azimuth(year, month, day)

Get the azimuth histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
zenith(year, month, day)

Get the zenith histogram

Parameters:year,month,day – the date for which to get the histogram.
Returns:array of bins and counts.
barometer(year, month, day)

Get the barometer dataset

Parameters:year,month,day – the date for which to get the dataset.
Returns:array of timestamps and values.
temperature(year, month, day)

Get the temperature dataset

Parameters:year,month,day – the date for which to get the dataset.
Returns:array of timestamps and values.
electronics

Get the electronics version data

Returns:array of timestamps and values.
electronic(timestamp=None)

Get electronics version data for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:list of values for given timestamp.
voltages

Get the PMT voltage data

Returns:array of timestamps and values.
voltage(timestamp=None)

Get PMT voltage data for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:list of values for given timestamp.
currents

Get the PMT current data

Returns:array of timestamps and values.
current(timestamp=None)

Get PMT current data for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:list of values for given timestamp.
gps_locations

Get the GPS location data

Returns:array of timestamps and values.
gps_location(timestamp=None)

Get GPS location for specific timestamp

Parameters:timestamp – optional timestamp or datetime object for which the values are valid.
Returns:dictionary with the values for given timestamp.
triggers

Get the trigger config data

Returns:array of timestamps and values.
trigger(timestamp=None)

Get trigger config for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:thresholds and trigger values for given timestamp.
station_layouts

Get the station layout data

Returns:array of timestamps and values.
station_layout(timestamp=None)

Get station layout data for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:list of coordinates for given timestamp.
detector_timing_offsets

Get the detector timing offsets data

Returns:array of timestamps and values.
detector_timing_offset(timestamp=None)

Get detector timing offset data for specific timestamp

Parameters:timestamp – timestamp for which the values are valid.
Returns:list of values for given timestamp.
station_timing_offsets(*args, **kwargs)

Get the station timing offset relative to reference_station

Parameters:reference_station – reference station
Returns:array of timestamps and values.
station_timing_offset(reference_station, timestamp=None)

Get station timing offset data for specific timestamp

Parameters:
  • reference_station – reference station
  • timestamp – timestamp for which the value is valid.
Returns:

the offset and error for given timestamp.