Example #1
0
def analyse_reconstructions(data):
    cq = CoincidenceQuery(data)
    c_ids = data.root.coincidences.coincidences.read_where('s505 & (timestamp < 1366761600)', field='id')
    c_recs = cq.reconstructions.read_coordinates(c_ids)

    s_ids = data.root.hisparc.cluster_amsterdam.station_505.events.get_where_list('timestamp < 1366761600')
    s_recs = data.root.hisparc.cluster_amsterdam.station_505.reconstructions.read_coordinates(s_ids)

    assert len(c_recs) == len(s_recs)

    zenc = c_recs['zenith']
    azic = c_recs['azimuth']

    zens = s_recs['zenith']
    azis = s_recs['azimuth']

    high_zenith = (zenc > .2) & (zens > .2)

    for minn in [1, 2, 4, 8, 16]:
        filter = (s_recs['min_n'] > minn)

        length = len(azis.compress(high_zenith & filter))
        shifts501 = np.random.normal(0, .06, length)
        azicounts, x, y = np.histogram2d(azis.compress(high_zenith & filter) + shifts501,
                                         azic.compress(high_zenith & filter),
                                         bins=np.linspace(-np.pi, np.pi, 73))
        plota = Plot()
        plota.histogram2d(azicounts, np.degrees(x), np.degrees(y), type='reverse_bw', bitmap=True)
#         plota.set_title('Reconstructed azimuths for events in coincidence (zenith gt .2 rad)')
        plota.set_xlabel(r'$\phi_{505}$ [\si{\degree}]')
        plota.set_ylabel(r'$\phi_{Science Park}$ [\si{\degree}]')
        plota.set_xticks([-180, -90, 0, 90, 180])
        plota.set_yticks([-180, -90, 0, 90, 180])
        plota.save_as_pdf('azimuth_505_spa_minn%d' % minn)
Example #2
0
def plot_detected_v_energy():
    plot = Plot(width=r'.6\textwidth')
    # plot.set_title('Detected core distances vs shower energy')
    c, xb, yb = histogram2d(r_in,
                            energy_in,
                            bins=(arange(0, 600, 40), arange(15.75, 17.76,
                                                             .5)))
    plot.histogram2d(c, xb, yb, bitmap=True)
    plot.set_yticks([16, 16.5, 17, 17.5])
    plot.set_ytick_labels(['$10^{%.1f}$' % e for e in [16, 16.5, 17, 17.5]])
    plot.set_ylabel(r'Shower energy [\si{\eV}]')
    plot.set_xlabel(r'Core distance [\si{\meter}]')
    plot.save_as_pdf('detected_v_energy')

    plot = Plot(width=r'.6\textwidth')
    # plot.set_title('Detected core distances vs shower energy, scaled to bin area')
    counts, xbins, ybins = histogram2d(r_in,
                                       energy_in,
                                       bins=(arange(0, 600, 40),
                                             arange(15.75, 17.76, .5)))
    plot.histogram2d((-counts.T / (pi * (xbins[:-1]**2 - xbins[1:]**2))).T,
                     xbins,
                     ybins,
                     type='area')
    plot.set_yticks([16, 16.5, 17, 17.5])
    plot.set_ytick_labels(['$10^{%.1f}$' % e for e in [16, 16.5, 17, 17.5]])
    plot.set_ylabel(r'Shower energy [\si{\eV}]')
    plot.set_xlabel(r'Core distance [\si{\meter}]')
    plot.save_as_pdf('detected_v_energy_scaled_area')
Example #3
0
def main():
    # data series
    x = [0, 40, 60, 69, 80, 90, 100]
    y = [0, 0, 0.5, 2.96, 2, 1, .5]

    # make graph
    graph = Plot()

    # make Plot
    graph.plot(x, y, mark=None, linestyle='smooth,very thick')

    # set labels and limits
    graph.set_xlabel(r"$f [\si{\mega\hertz}]$")
    graph.set_ylabel("signal strength")
    graph.set_xlimits(0, 100)
    graph.set_ylimits(0, 5)

    # set scale: 1cm equals 10 units along the x-axis
    graph.set_xscale(cm=10)
    # set scale: 1cm equals 1 unit along the y-axis
    graph.set_yscale(cm=1)

    # set ticks at every unit along the y axis
    graph.set_yticks(range(6))

    # set graph paper
    graph.use_graph_paper()

    # save graph to file
    graph.save('mm_paper')
Example #4
0
def make_map(station=None, label='map', detectors=False):

    get_locations = (get_detector_locations
                     if detectors else get_station_locations)

    latitudes, longitudes = get_locations(station)

    bounds = (min(latitudes), min(longitudes), max(latitudes), max(longitudes))

    map = Map(bounds, margin=0, z=18)
    image = map.to_pil()

    map_w, map_h = image.size

    xmin, ymin = map.to_pixels(map.box[:2])
    xmax, ymax = map.to_pixels(map.box[2:])
    aspect = abs(xmax - xmin) / abs(ymax - ymin)

    width = 0.67
    height = width / aspect
    plot = Plot(width=r'%.2f\linewidth' % width,
                height=r'%.2f\linewidth' % height)

    plot.draw_image(image, 0, 0, map_w, map_h)
    plot.set_axis_equal()

    plot.set_xlimits(xmin, xmax)
    plot.set_ylimits(map_h - ymin, map_h - ymax)

    x, y = map.to_pixels(array(latitudes), array(longitudes))

    marks = cycle(['o'] * 4 + ['triangle'] * 4 + ['*'] * 4)
    colors = cycle(['black', 'red', 'green', 'blue'])
    if detectors:
        for xi, yi in zip(x, y):
            plot.scatter([xi], [map_h - yi],
                         markstyle="%s, thick" % colors.next(),
                         mark=marks.next())
    else:
        plot.scatter(x, map_h - y, markstyle="black!50!green")

    plot.set_xlabel('Longitude [$^\circ$]')
    plot.set_xticks([xmin, xmax])
    plot.set_xtick_labels(['%.4f' % x for x in (map.box[1], map.box[3])])

    plot.set_ylabel('Latitude [$^\circ$]')
    plot.set_yticks([map_h - ymin, map_h - ymax])
    plot.set_ytick_labels(['%.4f' % x for x in (map.box[0], map.box[2])])
    #     plot.set_title(label)

    # save plot to file
    plot.save_as_pdf(label.replace(' ', '-'))
Example #5
0
def make_logo():
    size = '.02\linewidth'
    x = arange(0, 2*pi, .01)
    y = sin(x)
    plot = Plot(width=size, height=size)
    plot.set_ylimits(-1.3, 1.3)
    plot.set_yticks([-1, 0, 1])
    plot.set_ytick_labels(['', '', ''])
    plot.set_xticks([0, pi, 2*pi])
    plot.set_xtick_labels(['', '', ''])
    plot.plot(x, y, mark=None, linestyle='thick')
    plot.set_axis_options("axis line style=thick, major tick length=.04cm")
    plot.save_as_pdf('logo')
Example #6
0
def main():
    stations = np.genfromtxt("data/cluster-utrecht-stations.txt", names=["x", "y"])
    image = Image.open("data/cluster-utrecht-background.png")

    graph = Plot(width=r".75\linewidth", height=r".5\linewidth")

    graph.scatter(stations["x"], stations["y"])
    graph.draw_image(image)

    graph.set_axis_equal()

    nw = ["%.4f" % i for i in (52.10650519075632, 5.053710938)]
    se = ["%.4f" % i for i in (52.05249047600099, 5.185546875)]

    graph.set_xlabel("Longitude [$^\circ$]")
    graph.set_xticks([0, image.size[0]])
    graph.set_xtick_labels([nw[1], se[1]])

    graph.set_ylabel("Latitude [$^\circ$]")
    graph.set_yticks([0, image.size[1]])
    graph.set_ytick_labels([se[0], nw[0]])

    graph.save("utrecht")
Example #7
0
def plot_histogram(data, timestamps, station_numbers):
    """Make a 2D histogram plot of the number of events over time per station

    :param data: list of lists, with the number of events.
    :param station_numbers: list of station numbers in the data list.

    """
    plot = Plot(width=r'\linewidth', height=r'1.3\linewidth')
    plot.histogram2d(data.T[::7][1:],
                     timestamps[::7] / 1e9,
                     np.arange(len(station_numbers) + 1),
                     type='reverse_bw',
                     bitmap=True)
    plot.set_label(
        gps_to_datetime(timestamps[-1]).date().isoformat(), 'upper left')
    plot.set_xlimits(min=YEARS_TICKS[0] / 1e9, max=timestamps[-1] / 1e9)
    plot.set_xticks(YEARS_TICKS / 1e9)
    plot.set_xtick_labels(YEARS_LABELS)
    plot.set_yticks(np.arange(0.5, len(station_numbers) + 0.5))
    plot.set_ytick_labels(['%d' % s for s in sorted(station_numbers)],
                          style=r'font=\sffamily\tiny')
    plot.set_axis_options('ytick pos=right')
    plot.save_as_pdf('eventtime_histogram_network_hour')
Example #8
0
def plot_traces(coincidence_events):
    plot = Plot()
    t0 = int(coincidence_events[0][1]['ext_timestamp'])
    tick_labels = []
    tick_positions = []

    for i, station_event in enumerate(coincidence_events):
        station_number, event = station_event
        station = Station(station_number)
        traces = station.event_trace(event['timestamp'], event['nanoseconds'])
        start_trace = (int(event['ext_timestamp']) - t0) - event['t_trigger']
        t = arange(start_trace, start_trace + (2.5 * len(traces[0])), 2.5)
        t = insert(t, 0, -20000)
        t = append(t, 20000)
        # trace = array(traces).sum(0)
        for j, trace in enumerate(traces):
            if max(trace) <= 10:
                trace = array(trace)
            else:
                trace = array(trace) / float(max(trace)) * 100
            trace = insert(trace, 0, 0)
            trace = append(trace, 0)
            plot.plot(t,
                      trace + (100 * j) + (500 * i),
                      mark=None,
                      linestyle=COLORS[j])
        tick_labels.append(station_number)
        tick_positions.append(500 * i)

    plot.set_yticks(tick_positions)
    plot.set_ytick_labels(tick_labels)
    plot.set_xlimits(min=-250, max=1300)
    plot.set_xlabel('t [\si{n\second}]')
    plot.set_ylabel('Signal strength')

    plot.save_as_pdf('traces_%d' % t0)
Example #9
0
def plot_angles(data):
    """Make azimuth and zenith plots to compare the results"""

    rec501 = data.get_node('/hisparc/cluster_amsterdam/station_501',
                           'reconstructions')
    rec510 = data.get_node('/hisparc/cluster_amsterdam/station_510',
                           'reconstructions')

    zen501 = rec501.col('zenith')
    zen510 = rec510.col('zenith')
    azi501 = rec501.col('azimuth')
    azi510 = rec510.col('azimuth')
    minn501 = rec501.col('min_n')
    minn510 = rec510.col('min_n')

    sigmas = []
    blas = []
    minns = [0, 1, 2, 4, 8, 16, 24]

    high_zenith = (zen501 > .2) & (zen510 > .2)

    for minn in minns:
        filter = (minn501 > minn) & (minn510 > minn)

        length = len(azi501.compress(high_zenith & filter))
        shifts501 = np.random.normal(0, .06, length)
        shifts510 = np.random.normal(0, .06, length)
        azicounts, x, y = np.histogram2d(
            azi501.compress(high_zenith & filter) + shifts501,
            azi510.compress(high_zenith & filter) + shifts510,
            bins=np.linspace(-pi, pi, 73))
        plota = Plot()
        plota.histogram2d(azicounts,
                          degrees(x),
                          degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        #         plota.set_title('Reconstructed azimuths for events in coincidence (zenith gt .2 rad)')
        plota.set_xlabel(r'$\phi_{501}$ [\si{\degree}]')
        plota.set_ylabel(r'$\phi_{510}$ [\si{\degree}]')
        plota.set_xticks([-180, -90, 0, 90, 180])
        plota.set_yticks([-180, -90, 0, 90, 180])
        plota.save_as_pdf('azimuth_501_510_minn%d' % minn)

        length = len(zen501.compress(filter))
        shifts501 = np.random.normal(0, .04, length)
        shifts510 = np.random.normal(0, .04, length)
        zencounts, x, y = np.histogram2d(zen501.compress(filter) + shifts501,
                                         zen510.compress(filter) + shifts510,
                                         bins=np.linspace(0, pi / 3., 41))
        plotz = Plot()
        plotz.histogram2d(zencounts,
                          degrees(x),
                          degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        #         plotz.set_title('Reconstructed zeniths for station events in coincidence')
        plotz.set_xlabel(r'$\theta_{501}$ [\si{\degree}]')
        plotz.set_ylabel(r'$\theta_{510}$ [\si{\degree}]')
        plotz.set_xticks([0, 15, 30, 45, 60])
        plotz.set_yticks([0, 15, 30, 45, 60])
        plotz.save_as_pdf('zenith_501_510_minn%d' % minn)

        distances = angle_between(zen501.compress(filter),
                                  azi501.compress(filter),
                                  zen510.compress(filter),
                                  azi510.compress(filter))
        counts, bins = np.histogram(distances, bins=linspace(0, pi, 100))
        plotd = Plot()
        plotd.histogram(counts, degrees(bins))
        sigma = degrees(percentile(distances[isfinite(distances)], 68))
        sigmas.append(sigma)
        bla = degrees(percentile(distances[isfinite(distances)], 95))
        blas.append(bla)
        plotd.set_label(r'67\%% within \SI{%.1f}{\degree}' % sigma)
        #         plotd.set_title('Distance between reconstructed angles for station events')
        plotd.set_xlabel(r'Angle between reconstructions [\si{\degree}]')
        plotd.set_ylabel('Counts')
        plotd.set_xlimits(min=0, max=90)
        plotd.set_ylimits(min=0)
        plotd.save_as_pdf('angle_between_501_510_minn%d' % minn)

    plot = Plot()
    plot.plot(minns, sigmas, mark='*')
    plot.plot(minns, blas)
    plot.set_ylimits(min=0, max=40)
    plot.set_xlabel('Minimum number of particles in each station')
    plot.set_ylabel(r'Angle between reconstructions [\si{\degree}]')
    plot.save_as_pdf('angle_between_501_510_v_minn')
Example #10
0
def display_coincidences(cluster, coincidence_events, coincidence,
                         reconstruction, map):
    offsets = {
        s.number: [d.offset + s.gps_offset for d in s.detectors]
        for s in cluster.stations
    }
    ts0 = coincidence_events[0][1]['ext_timestamp']

    latitudes = []
    longitudes = []
    t = []
    p = []

    for station_number, event in coincidence_events:
        station = cluster.get_station(station_number)
        for detector in station.detectors:
            latitude, longitude, _ = detector.get_lla_coordinates()
            latitudes.append(latitude)
            longitudes.append(longitude)
        t.extend(
            event_utils.relative_detector_arrival_times(
                event, ts0, DETECTOR_IDS, offsets=offsets[station_number]))
        p.extend(event_utils.detector_densities(event, DETECTOR_IDS))

    image = map.to_pil()

    map_w, map_h = image.size
    aspect = float(map_w) / float(map_h)
    width = 0.67
    height = width / aspect
    plot = Plot(width=r'%.2f\linewidth' % width,
                height=r'%.2f\linewidth' % height)

    plot.draw_image(image, 0, 0, map_w, map_h)

    x, y = map.to_pixels(np.array(latitudes), np.array(longitudes))
    mint = np.nanmin(t)

    xx = []
    yy = []
    tt = []
    pp = []

    for xv, yv, tv, pv in zip(x, y, t, p):
        if np.isnan(tv) or np.isnan(pv):
            plot.scatter([xv], [map_h - yv], mark='diamond')
        else:
            xx.append(xv)
            yy.append(map_h - yv)
            tt.append(tv - mint)
            pp.append(pv)

    plot.scatter_table(xx, yy, tt, pp)

    transform = geographic.FromWGS84ToENUTransformation(cluster.lla)

    # Plot reconstructed core
    dx = np.cos(reconstruction['azimuth'])
    dy = np.sin(reconstruction['azimuth'])
    direction_length = reconstruction['zenith'] * 300
    core_x = reconstruction['x']
    core_y = reconstruction['y']

    core_lat, core_lon, _ = transform.enu_to_lla((core_x, core_y, 0))
    core_x, core_y = map.to_pixels(core_lat, core_lon)
    plot.scatter([core_x], [image.size[1] - core_y],
                 mark='10-pointed star',
                 markstyle='red')
    plot.plot([core_x, core_x + direction_length * dx], [
        image.size[1] - core_y, image.size[1] -
        (core_y - direction_length * dy)
    ],
              mark=None)

    # Plot simulated core
    dx = np.cos(reconstruction['reference_azimuth'])
    dy = np.sin(reconstruction['reference_azimuth'])
    direction_length = reconstruction['reference_zenith'] * 300
    core_x = reconstruction['reference_x']
    core_y = reconstruction['reference_y']

    core_lat, core_lon, _ = transform.enu_to_lla((core_x, core_y, 0))
    core_x, core_y = map.to_pixels(core_lat, core_lon)
    plot.scatter([core_x], [image.size[1] - core_y],
                 mark='asterisk',
                 markstyle='orange')
    plot.plot([core_x, core_x + direction_length * dx], [
        image.size[1] - core_y, image.size[1] -
        (core_y - direction_length * dy)
    ],
              mark=None)

    plot.set_scalebar(location="lower left")
    plot.set_slimits(min=1, max=30)
    plot.set_colorbar('$\Delta$t [\si{n\second}]')
    plot.set_axis_equal()
    plot.set_colormap('viridis')

    nw = num2deg(map.xmin, map.ymin, map.z)
    se = num2deg(map.xmin + map_w / TILE_SIZE, map.ymin + map_h / TILE_SIZE,
                 map.z)

    x0, y0, _ = transform.lla_to_enu((nw[0], nw[1], 0))
    x1, y1, _ = transform.lla_to_enu((se[0], se[1], 0))

    plot.set_xlabel('x [\si{\meter}]')
    plot.set_xticks([0, map_w])
    plot.set_xtick_labels([int(x0), int(x1)])

    plot.set_ylabel('y [\si{\meter}]')
    plot.set_yticks([0, map_h])
    plot.set_ytick_labels([int(y1), int(y0)])

    plot.save_as_pdf('map/event_display_%d' % coincidence['id'])
Example #11
0
def make_map(country=None,
             cluster=None,
             subcluster=None,
             station=None,
             stations=None,
             label='map',
             detectors=False,
             weather=False,
             knmi=False):

    get_locations = (get_detector_locations
                     if detectors else get_station_locations)

    if (country is None and cluster is None and subcluster is None
            and station is None and stations is None):
        latitudes, longitudes = ([], [])
    else:
        latitudes, longitudes = get_locations(country, cluster, subcluster,
                                              station, stations)

    if weather:
        weather_latitudes, weather_longitudes = get_weather_locations()
    else:
        weather_latitudes, weather_longitudes = ([], [])

    if knmi:
        knmi_latitudes, knmi_longitudes = get_knmi_locations()
    else:
        knmi_latitudes, knmi_longitudes = ([], [])

    bounds = (min(latitudes + weather_latitudes + knmi_latitudes),
              min(longitudes + weather_longitudes + knmi_longitudes),
              max(latitudes + weather_latitudes + knmi_latitudes),
              max(longitudes + weather_longitudes + knmi_longitudes))

    map = Map(bounds, margin=.1)
    #     map.save_png('map-tiles-background.png')
    image = map.to_pil()

    map_w, map_h = image.size

    xmin, ymin = map.to_pixels(map.box[:2])
    xmax, ymax = map.to_pixels(map.box[2:])
    aspect = abs(xmax - xmin) / abs(ymax - ymin)

    width = 0.67
    height = width / aspect
    plot = Plot(width=r'%.2f\linewidth' % width,
                height=r'%.2f\linewidth' % height)

    plot.draw_image(image, 0, 0, map_w, map_h)
    plot.set_axis_equal()

    plot.set_xlimits(xmin, xmax)
    plot.set_ylimits(map_h - ymin, map_h - ymax)

    if knmi:
        x, y = map.to_pixels(array(knmi_latitudes), array(knmi_longitudes))
        plot.scatter(
            x,
            map_h - y,
            mark='square',
            markstyle="mark size=0.5pt, black!50!blue, thick, opacity=0.6")

    x, y = map.to_pixels(array(latitudes), array(longitudes))
    if detectors:
        mark_size = 1.5
    else:
        mark_size = 3
    plot.scatter(x,
                 map_h - y,
                 markstyle="mark size=%fpt, black!50!green, "
                 "thick, opacity=0.9" % mark_size)

    if weather:
        x, y = map.to_pixels(array(weather_latitudes),
                             array(weather_longitudes))
        plot.scatter(
            x,
            map_h - y,
            markstyle="mark size=1.5pt, black!30!red, thick, opacity=0.9")

    plot.set_xlabel('Longitude [$^\circ$]')
    plot.set_xticks([xmin, xmax])
    plot.set_xtick_labels(['%.4f' % x for x in (map.box[1], map.box[3])])

    plot.set_ylabel('Latitude [$^\circ$]')
    plot.set_yticks([map_h - ymin, map_h - ymax])
    plot.set_ytick_labels(['%.4f' % x for x in (map.box[0], map.box[2])])
    #     plot.set_title(label)

    # save plot to file
    plot.save_as_pdf(label.replace(' ', '-'))
Example #12
0
def analyse_reconstructions(data):
    cq = CoincidenceQuery(data)
    c_ids = data.root.coincidences.coincidences.read_where('s501', field='id')
    c_recs = cq.reconstructions.read_coordinates(c_ids)

    s_recs = data.root.hisparc.cluster_amsterdam.station_501.reconstructions

    zenc = c_recs['zenith']
    azic = c_recs['azimuth']

    zens = s_recs.col('zenith')
    azis = s_recs.col('azimuth')

    high_zenith = (zenc > .2) & (zens > .2)

    for minn in [1, 2, 4, 8, 16]:
        filter = (s_recs.col('min_n') > minn)

        length = len(azis.compress(high_zenith & filter))
        shifts501 = np.random.normal(0, .06, length)
        azicounts, x, y = np.histogram2d(azis.compress(high_zenith & filter) +
                                         shifts501,
                                         azic.compress(high_zenith & filter),
                                         bins=np.linspace(-np.pi, np.pi, 73))
        plota = Plot()
        plota.histogram2d(azicounts,
                          np.degrees(x),
                          np.degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        # plota.set_title('Reconstructed azimuths for events in coincidence (zenith gt .2 rad)')
        plota.set_xlabel(r'$\phi_{501}$ [\si{\degree}]')
        plota.set_ylabel(r'$\phi_{Science Park}$ [\si{\degree}]')
        plota.set_xticks([-180, -90, 0, 90, 180])
        plota.set_yticks([-180, -90, 0, 90, 180])
        plota.save_as_pdf('azimuth_501_spa_minn%d' % minn)

        length = sum(filter)
        shifts501 = np.random.normal(0, .04, length)

        zencounts, x, y = np.histogram2d(zens.compress(filter) + shifts501,
                                         zenc.compress(filter),
                                         bins=np.linspace(0, np.pi / 3., 41))
        plotz = Plot()
        plotz.histogram2d(zencounts,
                          np.degrees(x),
                          np.degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        # plotz.set_title('Reconstructed zeniths for station events in coincidence')
        plotz.set_xlabel(r'$\theta_{501}$ [\si{\degree}]')
        plotz.set_ylabel(r'$\theta_{Science Park}$ [\si{\degree}]')
        plotz.set_xticks([0, 15, 30, 45, 60])
        plotz.set_yticks([0, 15, 30, 45, 60])
        plotz.save_as_pdf('zenith_501_spa_minn%d' % minn)

        distances = angle_between(zens.compress(filter), azis.compress(filter),
                                  zenc.compress(filter), azic.compress(filter))
        counts, bins = np.histogram(distances, bins=np.linspace(0, np.pi, 91))
        plotd = Plot()
        plotd.histogram(counts, np.degrees(bins))
        sigma = np.degrees(np.percentile(distances[np.isfinite(distances)],
                                         67))
        plotd.set_label(r'67\%% within \SI{%.1f}{\degree}' % sigma)
        # plotd.set_title('Distance between reconstructed angles for station and cluster')
        plotd.set_xlabel('Angle between reconstructions [\si{\degree}]')
        plotd.set_ylabel('Counts')
        plotd.set_xlimits(min=0, max=90)
        plotd.set_ylimits(min=0)
        plotd.save_as_pdf('angle_between_501_spa_minn%d' % minn)
Example #13
0
def display_coincidences(coincidence_events, c_id, map):

    cluster = CLUSTER

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

    latitudes = []
    longitudes = []
    t = []
    p = []

    for station_number, event in coincidence_events:
        station = cluster.get_station(station_number)
        for detector in station.detectors:
            latitude, longitude, _ = detector.get_lla_coordinates()
            latitudes.append(latitude)
            longitudes.append(longitude)
        t.extend(
            event_utils.relative_detector_arrival_times(
                event, ts0, DETECTOR_IDS))
        p.extend(event_utils.detector_densities(event, DETECTOR_IDS))

    image = map.to_pil()

    map_w, map_h = image.size
    aspect = float(map_w) / float(map_h)
    width = 0.67
    height = width / aspect
    plot = Plot(width=r'%.2f\linewidth' % width,
                height=r'%.2f\linewidth' % height)

    plot.draw_image(image, 0, 0, map_w, map_h)

    x, y = map.to_pixels(array(latitudes), array(longitudes))
    mint = nanmin(t)

    xx = []
    yy = []
    tt = []
    pp = []

    for xv, yv, tv, pv in zip(x, y, t, p):
        if isnan(tv) or isnan(pv):
            plot.scatter([xv], [map_h - yv], mark='diamond')
        else:
            xx.append(xv)
            yy.append(map_h - yv)
            tt.append(tv - mint)
            pp.append(pv)

    plot.scatter_table(xx, yy, tt, pp)

    transform = geographic.FromWGS84ToENUTransformation(cluster.lla)

    plot.set_scalebar(location="lower left")
    plot.set_slimits(min=1, max=60)
    plot.set_colorbar('$\Delta$t [\si{n\second}]')
    plot.set_axis_equal()

    nw = num2deg(map.xmin, map.ymin, map.z)
    se = num2deg(map.xmin + map_w / TILE_SIZE, map.ymin + map_h / TILE_SIZE,
                 map.z)

    x0, y0, _ = transform.lla_to_enu((nw[0], nw[1], 0))
    x1, y1, _ = transform.lla_to_enu((se[0], se[1], 0))

    plot.set_xlabel('x [\si{\meter}]')
    plot.set_xticks([0, map_w])
    plot.set_xtick_labels([int(x0), int(x1)])

    plot.set_ylabel('y [\si{\meter}]')
    plot.set_yticks([0, map_h])
    plot.set_ytick_labels([int(y1), int(y0)])

    #     plot.set_xlimits(min=-250, max=350)
    #     plot.set_ylimits(min=-250, max=250)
    #     plot.set_xlabel('x [\si{\meter}]')
    #     plot.set_ylabel('y [\si{\meter}]')

    plot.save_as_pdf('coincidences/event_display_%d_%d' % (c_id, ts0))
def plot_angles(data):
    """Make azimuth and zenith plots to compare the results"""

    rec = data.root.reconstructions

    zenhis = rec.col('reconstructed_theta')
    zenkas = rec.col('reference_theta')
    azihis = rec.col('reconstructed_phi')
    azikas = rec.col('reference_phi')
    min_n = rec.col('min_n134')

    high_zenith = (zenhis > .2) & (zenkas > .2)

    for minn in [0, 1, 2, 4]:
        filter = (min_n > minn)

        azicounts, x, y = np.histogram2d(azihis.compress(high_zenith & filter),
                                         azikas.compress(high_zenith & filter),
                                         bins=np.linspace(-pi, pi, 73))
        plota = Plot()
        plota.histogram2d(azicounts,
                          degrees(x),
                          degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        #         plota.set_title('Reconstructed azimuths for events in coincidence (zenith gt .2 rad)')
        plota.set_xlabel(r'$\phi_\textrm{HiSPARC}$ [\si{\degree}]')
        plota.set_ylabel(r'$\phi_\textrm{KASCADE}$ [\si{\degree}]')
        plota.set_xticks([-180, -90, 0, 90, 180])
        plota.set_yticks([-180, -90, 0, 90, 180])
        plota.save_as_pdf('azimuth_his_kas_minn%d' % minn)

        zencounts, x, y = np.histogram2d(zenhis.compress(filter),
                                         zenkas.compress(filter),
                                         bins=np.linspace(0, pi / 3., 41))
        plotz = Plot()
        plotz.histogram2d(zencounts,
                          degrees(x),
                          degrees(y),
                          type='reverse_bw',
                          bitmap=True)
        #         plotz.set_title('Reconstructed zeniths for station events in coincidence')
        plotz.set_xlabel(r'$\theta_\textrm{HiSPARC}$ [\si{\degree}]')
        plotz.set_ylabel(r'$\theta_\textrm{KASCADE}$ [\si{\degree}]')
        plotz.set_xticks([0, 15, 30, 45, 60])
        plotz.set_yticks([0, 15, 30, 45, 60])
        plotz.save_as_pdf('zenith_his_kas_minn%d' % minn)

        distances = angle_between(zenhis.compress(filter),
                                  azihis.compress(filter),
                                  zenkas.compress(filter),
                                  azikas.compress(filter))
        counts, bins = np.histogram(distances, bins=linspace(0, pi, 100))
        plotd = Plot()
        plotd.histogram(counts, degrees(bins))
        sigma = degrees(scoreatpercentile(distances, 67))
        plotd.set_title(r'$N_\textrm{MIP} \geq %d$' % minn)
        plotd.set_label(r'67\%% within \SI{%.1f}{\degree}' % sigma)
        # plotd.set_title('Distance between reconstructed angles for station events')
        plotd.set_xlabel('Angle between reconstructions [\si{\degree}]')
        plotd.set_ylabel('Counts')
        plotd.set_xlimits(min=0, max=90)
        plotd.set_ylimits(min=0)
        plotd.save_as_pdf('angle_between_his_kas_minn%d' % minn)