Ejemplo n.º 1
0
def get_coincidences_from_esd_in_range(start, end, stations, n):
    """Get coincidences from ESD in time range.

    :param start: start of datetime range
    :param end: end of datetime range
    :param stations: station numbers
    :param n: minimum number of events in coincidence
    :yield: id, station number and event

    """
    id = -1
    for t0, t1 in single_day_ranges(start, end):
        try:
            NetworkSummary.objects.get(date=t0)
        except NetworkSummary.DoesNotExist:
            continue
        with tables.open_file(esd.get_esd_data_path(t0)) as f:
            try:
                cq = CoincidenceQuery(f)
                ts0 = datetime_to_gps(t0)
                ts1 = datetime_to_gps(t1)
                if stations:
                    coincidences = cq.at_least(stations, n, start=ts0, stop=ts1)
                    events = cq.events_from_stations(coincidences, stations, n)
                else:
                    coincidences = cq.timerange(start=ts0, stop=ts1)
                    events = cq.all_events(coincidences, n)
                for id, coin in enumerate(events, id + 1):
                    for number, event in coin:
                        yield id, number, event
            except (IOError, tables.NoSuchNodeError):
                continue
Ejemplo n.º 2
0
def plot_map(data):
    cluster = data.root.coincidences._v_attrs['cluster']

    map = make_map(cluster)
    cq = CoincidenceQuery(data)
    cq.reconstructions = cq.data.get_node('/coincidences', 'recs_curved')
    cq.reconstructed = True

    for i, coincidence in enumerate(cq.coincidences.read_where('N > 6')):
        if i > 50:
            break
        coincidence_events = next(cq.all_events([coincidence]))
        reconstruction = cq._get_reconstruction(coincidence)
        display_coincidences(cluster, coincidence_events, coincidence,
                             reconstruction, map)
Ejemplo n.º 3
0
def plot_distance_vs_delay(data):
    colors = {
        501: 'black',
        502: 'red!80!black',
        503: 'blue!80!black',
        504: 'green!80!black',
        505: 'orange!80!black',
        506: 'pink!80!black',
        508: 'blue!40!black',
        509: 'red!40!black',
        510: 'green!40!black',
        511: 'orange!40!black'
    }

    cq = CoincidenceQuery(data)
    cq.reconstructions = cq.data.get_node('/coincidences', 'recs_curved')
    cq.reconstructed = True

    cluster = data.root.coincidences._v_attrs['cluster']
    offsets = {
        s.number: [d.offset + s.gps_offset for d in s.detectors]
        for s in cluster.stations
    }

    front = CorsikaStationFront()
    front_r = np.arange(500)
    front_t = front.delay_at_r(front_r)

    for i, coincidence in enumerate(cq.coincidences.read_where('N > 6')):
        if i > 50:
            break
        coincidence_events = next(cq.all_events([coincidence]))
        reconstruction = cq._get_reconstruction(coincidence)

        core_x = coincidence['x']
        core_y = coincidence['y']

        plot = MultiPlot(2, 1)
        splot = plot.get_subplot_at(0, 0)
        rplot = plot.get_subplot_at(1, 0)

        splot.plot(front_r, front_t, mark=None)

        ref_extts = coincidence_events[0][1]['ext_timestamp']

        front_detect_r = []
        front_detect_t = []

        for station_number, event in coincidence_events:
            station = cluster.get_station(station_number)
            t = event_utils.relative_detector_arrival_times(
                event,
                ref_extts,
                offsets=offsets[station_number],
                detector_ids=DETECTOR_IDS)
            core_distances = []
            for i, d in enumerate(station.detectors):
                x, y, z = d.get_coordinates()
                core_distances.append(distance_between(core_x, core_y, x, y))
                t += d.get_coordinates()[-1] / c
            splot.scatter(core_distances,
                          t,
                          mark='o',
                          markstyle=colors[station_number])
            splot.scatter([np.mean(core_distances)], [np.nanmin(t)],
                          mark='*',
                          markstyle=colors[station_number])
            rplot.scatter(
                [np.mean(core_distances)],
                [np.nanmin(t) - front.delay_at_r(np.mean(core_distances))],
                mark='*',
                markstyle=colors[station_number])

        splot.set_ylabel('Relative arrival time [ns]')
        rplot.set_ylabel(r'Residuals')
        rplot.set_axis_options(r'height=0.25\textwidth')
        splot.set_ylimits(-10, 150)

        plot.set_xlimits_for_all(None, 0, 400)
        plot.set_xlabel('Distance from core [m]')
        plot.show_xticklabels(1, 0)
        plot.show_yticklabels_for_all()

        plot.save_as_pdf('front_shape/distance_v_time_%d_core' %
                         coincidence['id'])