Exemple #1
0
def coincidences_each_cluster():
    network = Network()
    for cluster in network.clusters():
        stations = network.stations(cluster=cluster['number'])
        station_numbers = [station['number'] for station in stations]
        group_name = '%s cluster' % cluster['name']
        coincidences_stations(station_numbers, group_name=group_name)
Exemple #2
0
def write_jsons(data):
    if not os.path.exists(os.path.join(EVENT_DISPLAY_DIR, 'data/')):
        os.mkdir(os.path.join(EVENT_DISPLAY_DIR, 'data'))

    # Create subcluster station location and coincidences JSONs
    for subcluster in Network().subclusters():
        subcluster_name = subcluster['name'].lower().replace(' ', '_')

        stations = build_station_json(data, subcluster['number'])
        with open('data/stations_' + subcluster_name + '.json', 'w') as f:
            json.dump(stations, f)

        coincidences = build_coincidence_json(data, subcluster_name)
        with open('data/coincidences_' + subcluster_name + '.json', 'w') as f:
            json.dump(coincidences, f)

    # Create network station location and coincidences JSONs
    stations = build_station_json(data)
    with open('data/stations_network.json', 'w') as f:
        json.dump(stations, f)

    coincidences = build_coincidence_json(data)
    with open('data/coincidences_network.json', 'w') as f:
        json.dump(coincidences, f)

    # Create station events JSONs
    for station in pbar(STATIONS):
        events = build_events_json(data, station)
        with open('data/events_s%d.json' % station, 'w') as f:
            json.dump(events, f)
Exemple #3
0
def get_active_stations():
    """ return a list of all *active* station numbers in the HiSPAC Network"""
    stations = Network(force_fresh=True).station_numbers()
    for sn in stations:
        s = Station(sn)
        if s.info['active']:
            yield sn
Exemple #4
0
def get_station_ids_with_data(date):
    """Return the station ids having data on this day."""

    station_list = Network.stations_with_data(date.year, date.month, date.day)
    station_ids = [int(station['number']) for station in station_list]

    return station_ids
Exemple #5
0
def get_station_ids_with_data(date):
    """Return the station ids having data on this day."""

    station_list = Network.stations_with_data(date.year, date.month, date.day)
    station_ids = [int(station['number']) for station in station_list]

    return station_ids
Exemple #6
0
def download_coincidences_data(data):
    """Download coincidence data for each subcluster and for all stations"""

    for subcluster in Network().subclusters():
        group = ('/coincidences_%s' %
                 subcluster['name'].lower().replace(' ', '_'))
        if group in data:
            continue
        stations = Network().station_numbers(subcluster=subcluster['number'])
        if len(stations) < 2:
            continue
        download_coincidences(data,
                              group=group,
                              stations=stations,
                              start=START,
                              end=END)

    # Entire network
    if '/coincidences' not in data:
        download_coincidences(data, start=START, end=END)
Exemple #7
0
def generate_json():
    """Get the API info data for each station"""

    station_numbers = Network().station_numbers()
    station_info = {}

    for number in pbar(station_numbers):
        try:
            station = Station(number)
            station_info[number] = station.info
        except:
            continue

    return station_info
Exemple #8
0
def build_station_json(data, subcluster=None):
    """Create the station JSON files for each subcluster and the network

    Each JSON contains the GPS coordintes of all stations in that subcluster
    (or network). Also the start and end timestamp (in ns) of the dataset are
    included to synchronize the event and coincidence datasets.

    """
    stations = {}
    if subcluster is None:
        station_numbers = STATIONS
    else:
        station_numbers = Network().station_numbers(subcluster=subcluster)
    for station_number in station_numbers:
        try:
            loc = get_latlon_coordinates(station_number)
            if 0. not in loc:
                stations[station_number] = loc
        except:
            continue
    station_json = {'limits': LIMITS, 'stations': stations}
    return station_json
Exemple #9
0
#!/usr/bin/env python

import datetime
import json
import re
import os

import tables

from sapphire import (Network, Station, download_data, download_coincidences,
                      datetime_to_gps)
from sapphire.utils import pbar

EVENT_DISPLAY_DIR = os.path.dirname(__file__)
STATIONS = Network().station_numbers()
START = datetime.datetime(2016, 2, 1, 11, 0)
END = datetime.datetime(2016, 2, 1, 11, 20)
LIMITS = [datetime_to_gps(START) * int(1e9), datetime_to_gps(END) * int(1e9)]

re_station_number = re.compile(".*/station_([0-9]+)$")


def download_coincidences_data(data):
    """Download coincidence data for each subcluster and for all stations"""

    for subcluster in Network().subclusters():
        group = ('/coincidences_%s' %
                 subcluster['name'].lower().replace(' ', '_'))
        if group in data:
            continue
        stations = Network().station_numbers(subcluster=subcluster['number'])
Exemple #10
0
    ./stations_on_map --detectors --stations 102,104,105
    ./stations_on_map --detectors --station 501

"""
import argparse

from ast import literal_eval

from numpy import array
from smopy import Map

from artist import Plot

from sapphire import HiSPARCStations, Network, Station

NETWORK = Network(force_stale=True)


def get_detector_locations(country=None,
                           cluster=None,
                           subcluster=None,
                           station=None,
                           stations=None):
    latitudes = []
    longitudes = []

    if station is not None:
        station_numbers = [station]
    elif stations is not None:
        station_numbers = stations
    else:
Exemple #11
0
def get_station_numbers():
    """Get all station numbers"""
    return Network(force_stale=True).station_numbers()
Exemple #12
0
def coincidences_all_stations():
    network = Network()
    station_numbers = [station for station in network.station_numbers()]
    coincidences_stations(station_numbers, group_name='All stations')
Exemple #13
0
def get_versions_api():
    station_numbers = Network().station_numbers()
    for station_number in station_numbers:
        config = Station(station_number).config()
        print '% 5d' % station_number, config['mas_version']
Exemple #14
0
import os
import urllib

from sapphire import Network
from sapphire.utils import pbar

BASE = 'http://data.hisparc.nl/show/source/eventtime/%d/'
PATH = '/Users/arne/Datastore/publicdb_csv/eventtime/'

if __name__ == "__main__":
    station_numbers = Network().station_numbers()

    for sn in pbar(station_numbers):
        path = PATH + '%d.tsv' % sn
        if not os.path.exists(path):
            urllib.urlretrieve(BASE % sn, path)
Exemple #15
0
        return

    if len(gps_locations) < 2:
        return

    for p1, p2 in itertools.combinations(gps_locations, 2):
        d = distance(p1, p2)
        if d > .25:
            print station.station, d
            break


def distance(s1, s2):
    """
    returns distance in km
    """
    R = 6371  # km Radius of earth
    d_lat = numpy.radians(s2['latitude'] - s1['latitude'])
    d_lon = numpy.radians(s2['longitude'] - s1['longitude'])
    a = (numpy.sin(d_lat / 2)**2 + numpy.cos(numpy.radians(s1['latitude'])) *
         numpy.cos(numpy.radians(s2['latitude'])) * numpy.sin(d_lon / 2)**2)
    c = 2 * numpy.arctan2(numpy.sqrt(a), numpy.sqrt(1 - a))
    distance = R * c
    return distance


if __name__ == "__main__":
    for sn in Network().station_numbers():
        station = Station(sn)
        detect_problems(station)
Exemple #16
0
def coincidences_sciencepark():
    network = Network()
    stations = network.stations(subcluster=500)
    station_numbers = [station['number'] for station in stations]
    group_name = 'Science Park subcluster'
    coincidences_stations(station_numbers, group_name=group_name)
Exemple #17
0
def distances_netherlands():
    sn = Network(force_stale=True).station_numbers(country=0)
    cluster = HiSPARCStations(sn, force_stale=True, skip_missing=True)
    distances_stations(cluster, name='_netherlands')
Exemple #18
0
def get_offsets_dict():
    offsets = {
        s: Station(s).detector_timing_offset
        for s in Network().station_numbers()
    }
    return offsets