Exemple #1
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')
Exemple #2
0
def plot_offset_distribution(ids, **kwargs):
    """Offset distribution"""

    # Begin Figure
    plot = Plot()
    offsets = [
        np.average([x for x in get(id)[1] if abs(x) < 100]) for id in ids
    ]
    bins = np.arange(-70, 70, 2)
    n, bins = np.histogram(offsets, bins)
    plot.histogram(n, bins)

    bin_centers = (bins[:-1] + bins[1:]) / 2
    popt, pcov = curve_fit(gauss,
                           bin_centers,
                           n,
                           p0=[1., np.mean(offsets),
                               np.std(offsets)])
    plot.plot(bin_centers,
              gauss(bin_centers, *popt),
              mark=None,
              linestyle='gray')

    if kwargs.keys():
        plot.set_title('Tijdtest offset distribution ' +
                       kwargs[kwargs.keys()[0]])
    plot.set_label(r'$\mu={1:.1f}$, $\sigma={2:.1f}$'.format(*popt))
    plot.set_xlabel(r'Offset [\si{\nano\second}]')
    plot.set_ylabel(r'Counts')
    plot.set_ylimits(min=0)

    # Save Figure
    name = 'box/tt_offset_distribution'
    if kwargs.keys():
        name += kwargs[kwargs.keys()[0]]
    plot.save_as_pdf(PLOT_PATH + name)

    print 'tt_analyse: Plotted offsets'
Exemple #3
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')
Exemple #4
0
def zoom_baseline(raw_traces):
    plot = Plot()
    length = 500  # ns

    #     for i, raw_trace in enumerate(raw_traces):
    #         plot.plot(arange(0, length, 2.5), raw_trace[:int(length / 2.5)], mark=None, linestyle=COLORS[i])

    #     plot.plot(arange(0, length, 2.5), raw_traces[0][:int(length / 2.5)], mark=None, linestyle=COLORS[0])

    plot.plot(arange(0, length, 5),
              raw_traces[0][:int(length / 2.5):2],
              mark=None,
              linestyle=COLORS[0])
    plot.plot(arange(2.5, length, 5),
              raw_traces[0][1:int(length / 2.5):2],
              mark=None,
              linestyle=COLORS[1])

    plot.set_ylimits(min=180, max=220)
    plot.set_xlimits(min=0, max=length)
    plot.set_ylabel(r'Signal strength [ADC counts]')
    plot.set_xlabel(r'Sample [\si{\nano\second}]')
    plot.save_as_pdf('baseline')
Exemple #5
0
def zoom_pulse(raw_traces):
    plot = Plot()
    start, end = get_outer_limits(raw_traces, 253)

    for i, raw_trace in enumerate(raw_traces):
        plot.plot(arange(start * 2.5, end * 2.5, 2.5),
                  raw_trace[start:end],
                  mark=None,
                  linestyle=COLORS[i])

    hisparc_version = 2

    if hisparc_version == 3:
        low = 81
        high = 150
    elif hisparc_version == 2:
        low = 253
        high = 323

    plot.draw_horizontal_line(low, 'gray')
    plot.add_pin_at_xy(start * 2.5,
                       low,
                       'low',
                       location='above right',
                       use_arrow=False)
    plot.draw_horizontal_line(high, 'gray')
    plot.add_pin_at_xy(start * 2.5,
                       high,
                       'high',
                       location='above right',
                       use_arrow=False)

    plot.set_ylimits(min=0)
    plot.set_xlimits(min=start * 2.5, max=end * 2.5 - 2.5)
    plot.set_ylabel(r'Signal strength [ADC counts]')
    plot.set_xlabel(r'Sample [\si{\nano\second}]')
    plot.save_as_pdf('pulse')
Exemple #6
0
def plot_distribution():
    distances = CORE_DISTANCES
    for e in ENERGIES:
        first_t = []
        first_t_std = []
        median_t = []
        median_t_std = []
        for core_distance in distances:
            first_path = (
                '/Users/arne/Datastore/first_particle/first_{e}_{r}.npy'.
                format(e=e, r=core_distance))
            median_path = (
                '/Users/arne/Datastore/first_particle/median_{e}_{r}.npy'.
                format(e=e, r=core_distance))
            first_times = load(first_path)
            first_t.append(mean(first_times))
            first_t_std.append(std(first_times))
            median_times = load(median_path)
            median_t.append(mean(median_times))
            median_t_std.append(std(median_times))
        plot = Plot('semilogx')
        plot.plot(distances,
                  first_t,
                  yerr=first_t_std,
                  markstyle='mark size=1pt',
                  linestyle=None)
        plot.plot(distances,
                  median_t,
                  yerr=median_t_std,
                  markstyle='mark size=1pt,gray',
                  linestyle=None)
        plot.set_xlabel('Core distance [m]')
        plot.set_ylabel('Time after first [ns]')
        plot.set_ylimits(min=-10)
        plot.set_xlimits(0, 1e3)
        plot.set_label('E=$10^{{{e}}}$eV'.format(e=e), location='upper left')
        plot.save_as_pdf('plots/first_particle_{e}'.format(e=e))
Exemple #7
0
def plot_n_histogram(path='/'):
    with tables.open_file(RESULT_DATA, 'r') as data:
        sims = data.get_node(path + 'cluster_simulations')
        ud_n1 = sims.station_0.events.col('n1')
        ud_n2 = sims.station_0.events.col('n2')
        lr_n1 = sims.station_1.events.col('n1')
        lr_n2 = sims.station_1.events.col('n2')

        bins = np.linspace(0, 80, 40)
        ud_counts1, _ = np.histogram(ud_n1, bins)
        ud_counts2, _ = np.histogram(ud_n2, bins)
        lr_counts1, _ = np.histogram(lr_n1, bins)
        lr_counts2, _ = np.histogram(lr_n2, bins)

        plot = Plot()
        plot.histogram(ud_counts1, bins, linestyle='black')
        plot.histogram(ud_counts2, bins, linestyle='red')
        plot.histogram(lr_counts1, bins + 0.01, linestyle='black, dashed')
        plot.histogram(lr_counts2, bins + 0.01, linestyle='red, dashed')
        plot.set_xlabel(r'Number of detected particles')
        plot.set_ylabel(r'Number of events with n detected')
        plot.set_xlimits(bins[0], bins[-1])
        plot.set_ylimits(0)
        plot.save_as_pdf('n_histogram' + path.replace('/', '_'))
Exemple #8
0
def plot_distance_width():

    distances = []
    widths = []

    with tables.open_file(PATH, 'r') as data:
        cluster = data.root.coincidences._v_attrs.cluster
        station_groups = [(id, data.get_node(sidx, 'events'))
                          for id, sidx in enumerate(data.root.coincidences.s_index)]
        bins = arange(-2000, 2000, 20)
        for ref, other in itertools.combinations(station_groups, 2):
            ref_id, ref_events = ref
            id, events = other
            distances.append(cluster.calc_rphiz_for_stations(ref_id, id)[0])

            dt = (ref_events.col('ext_timestamp').astype(int) -
                  events.col('ext_timestamp').astype(int))
            pre_width = std(dt)
            counts, bins = histogram(dt, bins=linspace(-1.8 * pre_width, 1.8 * pre_width, 100), density=True)
            x = (bins[:-1] + bins[1:]) / 2
            popt, pcov = curve_fit(norm.pdf, x, counts, p0=(0., distances[-1]))
            widths.append(popt[1])
            print std(dt), popt[1]

    popt, pcov = curve_fit(lin, distances, widths, p0=(1.1, 1))
    print popt, pcov

    plot = Plot()
    plot.scatter(distances, widths)
    plot.plot([0, 600], [0, 600 / 0.3], mark=None, linestyle='gray')
    plot.plot([0, 600], [lin(0, *popt), lin(600, *popt)], mark=None)
    plot.set_xlimits(min=0, max=600)
    plot.set_ylimits(min=0, max=700)
    plot.set_xlabel(r'Distance [\si{\meter}]')
    plot.set_ylabel(r'Width of dt distribution [\si{\ns}]')
    plot.save_as_pdf('plots/distance_v_width_pr')
Exemple #9
0
def determine_detector_timing_offsets(s, events):
    """Determine the offsets between the station detectors.

    ADL: Currently assumes detector 1 is a good reference.
    But this is not always the best choice. Perhaps it should be
    determined using more data (more than one day) to be more
    accurate.

    """
    bins = arange(-100 + 1.25, 100, 2.5)
    col = (cl for cl in COLORS)
    graph = Plot()
    ids = range(1, 5)
    reference = 2
    for j in [1, 3, 4]:
        if j == reference:
            continue
        tref = events.col('t%d' % reference)
        tj = events.col('t%d' % j)
        dt = (tj - tref).compress((tref >= 0) & (tj >= 0))
        y, bins = histogram(dt, bins=bins)
        c = col.next()
        graph.histogram(y, bins, linestyle='%s' % c)
        x = (bins[:-1] + bins[1:]) / 2
        try:
            popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 10.))
            graph.draw_vertical_line(popt[1], linestyle='%s' % c)
            print '%d-%d: %f (%f)' % (j, reference, popt[1], popt[2])
        except (IndexError, RuntimeError):
            print '%d-%d: failed' % (j, reference)
    graph.set_title('Time difference, station %d' % (s))
    graph.set_xlimits(-100, 100)
    graph.set_ylimits(min=0)
    graph.set_xlabel('$\Delta t$')
    graph.set_ylabel('Counts')
    graph.save_as_pdf('detector_offsets_%s' % s)
Exemple #10
0
def plot_traces(event, station):
    s = Station(station)
    plot = Plot()
    traces = s.event_trace(event['timestamp'], event['nanoseconds'], raw=True)
    for j, trace in enumerate(traces):
        t = arange(0, (2.5 * len(traces[0])), 2.5)
        plot.plot(t, trace, mark=None, linestyle=COLORS[j])
    n_peaks = event['n_peaks']
    plot.set_title('%d - %d' % (station, event['ext_timestamp']))
    plot.set_label('%d ' * 4 % tuple(n_peak for n_peak in n_peaks))
    plot.set_xlabel('t [\si{n\second}]')
    plot.set_ylabel('Signal strength')
    plot.set_xlimits(min=0, max=2.5 * len(traces[0]))
    plot.set_ylimits(min=150, max=500)  # max=2 ** 12
    plot.draw_horizontal_line(253, linestyle='gray')
    plot.draw_horizontal_line(323, linestyle='gray')
    plot.draw_horizontal_line(event['baseline'][0] + 20, linestyle='thin,gray')
    plot.draw_horizontal_line(event['baseline'][1] + 20,
                              linestyle='thin,red!40!black')
    plot.draw_horizontal_line(event['baseline'][2] + 20,
                              linestyle='thin,green!40!black')
    plot.draw_horizontal_line(event['baseline'][3] + 20,
                              linestyle='thin,blue!40!black')
    plot.save_as_pdf('traces_%d_%d' % (station, event['ext_timestamp']))
Exemple #11
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)
Exemple #12
0
def plot_reconstructions():
    with tables.open_file('data.h5', 'r') as data:
        rec = data.root.s501.reconstructions
        reco = data.root.s501_original.reconstructions

        # Compare azimuth distribution
        bins = linspace(-pi, pi, 20)  # Radians
        plot = Plot()
        plot.histogram(*histogram(rec.col('azimuth'), bins=bins))
        plot.histogram(*histogram(reco.col('azimuth'), bins=bins),
                       linestyle='red')
        plot.set_ylimits(min=0)
        plot.set_xlimits(-pi, pi)
        plot.set_ylabel('counts')
        plot.set_xlabel(r'Azimuth [\si{\radian}]')
        plot.save_as_pdf('azimuth')

        # Compare zenith distribution
        bins = linspace(0, pi / 2, 20)  # Radians
        plot = Plot()
        plot.histogram(*histogram(rec.col('zenith'), bins=bins))
        plot.histogram(*histogram(reco.col('zenith'), bins=bins),
                       linestyle='red')
        plot.set_ylimits(min=0)
        plot.set_xlimits(0, pi / 2)
        plot.set_ylabel('counts')
        plot.set_xlabel(r'Zenith [\si{\radian}]')
        plot.save_as_pdf('zenith')

        # Compare angles between old and new
        bins = linspace(0, 20, 20)  # Degrees
        plot = Plot()
        filter = (rec.col('zenith') > .5)
        d_angle = angle_between(rec.col('zenith'), rec.col('azimuth'),
                                reco.col('zenith'), reco.col('azimuth'))
        plot.histogram(*histogram(degrees(d_angle), bins=bins))
        plot.histogram(*histogram(degrees(d_angle).compress(filter),
                                  bins=bins),
                       linestyle='red')
        plot.histogram(*histogram(degrees(d_angle).compress(invert(filter)),
                                  bins=bins),
                       linestyle='blue')
        plot.set_ylimits(min=0)
        plot.set_xlimits(0, 20)
        plot.set_ylabel('counts')
        plot.set_xlabel(r'Angle between [\si{\degree}]')
        plot.save_as_pdf('angle_between')
Exemple #13
0
import tables

from numpy import degrees, histogram, isnan

from artist import Plot

from sapphire import ReconstructESDEvents

with tables.open_file('/Users/arne/Datastore/esd/2013/10/2013_10_28.h5',
                      'r') as data:
    for s in [501, 502, 503, 504, 505, 506, 508, 509]:
        rec = ReconstructESDEvents(data,
                                   '/hisparc/cluster_amsterdam/station_%d' % s,
                                   s)
        rec.reconstruct_directions(detector_ids=[0, 2, 3])
        azimuths = [
            degrees(a) for a, z in zip(rec.phi, rec.theta)
            if degrees(z) > 10 and not isnan(a)
        ]
        n, bins = histogram(azimuths, bins=range(-180, 190, 10))
        graph = Plot()
        graph.histogram(n, bins)
        graph.set_title('Station %d' % s)
        graph.set_xlabel('Azimuth')
        graph.set_xlimits(-180, 180)
        graph.set_ylimits(min=0)
        graph.save_as_pdf('azimuths_123_s%d' % s)
Exemple #14
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))
Exemple #15
0
def determine_station_timing_offsets(data):
    """Determine the offsets between the stations."""

    c = .3

    ref_station_number = 501
    ref_d_off = DETECTOR_OFFSETS[ref_station_number]
    ref_events = data.root.hisparc.cluster_amsterdam.station_501.events
    ref_t = array([
        where(
            ref_events.col('t1') == -999, 9000,
            ref_events.col('t1') - ref_d_off[0]),
        where(
            ref_events.col('t2') == -999, 9000,
            ref_events.col('t2') - ref_d_off[1]),
        where(
            ref_events.col('t3') == -999, 9000,
            ref_events.col('t3') - ref_d_off[2]),
        where(
            ref_events.col('t4') == -999, 9000,
            ref_events.col('t4') - ref_d_off[3])
    ])
    ref_min_t = ref_t.min(axis=0)

    station_number = 510
    d_off = DETECTOR_OFFSETS[station_number]
    events = data.root.hisparc.cluster_amsterdam.station_510.events
    t = array([
        where(events.col('t1') == -999, 90000,
              events.col('t1') - d_off[0]),
        where(events.col('t2') == -999, 90000,
              events.col('t2') - d_off[1]),
        where(events.col('t3') == -999, 90000,
              events.col('t3') - d_off[2]),
        where(events.col('t4') == -999, 90000,
              events.col('t4') - d_off[3])
    ])
    min_t = t.min(axis=0)

    dt = []
    for event, ref_event in itertools.izip(events, ref_events):
        if (ref_event['t_trigger'] in ERR or event['t_trigger'] in ERR):
            dt.append(nan)
            continue
        dt.append((int(event['ext_timestamp']) -
                   int(ref_event['ext_timestamp'])) -
                  (event['t_trigger'] - ref_event['t_trigger']))

    dt = array(dt)
    dt = dt + (min_t - ref_min_t)

    plot = Plot()
    bins = linspace(-50, 50, 100)
    y, bins = histogram(dt, bins=bins)
    plot.histogram(y, bins)

    x = (bins[:-1] + bins[1:]) / 2
    try:
        popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 10))
        station_offset = popt[1]
        plot.draw_vertical_line(station_offset)
        bins = linspace(-50, 50, 1000)
        plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray')
    except RuntimeError:
        station_offset = 0.
    print station_offset

    plot.set_title('Time difference, station 510-501')
    plot.set_xlimits(-50, 50)
    plot.set_ylimits(min=0)
    plot.set_xlabel('$\Delta t$ [ns]')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('station_offsets')
Exemple #16
0
        if x > 0.0:
            return 1.0
    return 2 * (H(x / L) - H(x / L - 1)) - 1


def fourier(x, N):
    ''' fourier approximation with N terms'''
    term = 0.0
    for n in range(1, N, 2):
        term += (1.0 / n) * math.sin(n * math.pi * x / L)
    return (4.0 / (math.pi)) * term


X     = npy.linspace(0.0, 2 * L, num=1000)
Y_sqr = [square(x) for x in X]
Y     = lambda n: [fourier(x, n) for x in X]

graph = Plot()
graph.set_title("Fourier approximation")

graph.plot(x=X, y=Y( 3), linestyle='red'   , mark=None, legend='n=3' )
graph.plot(x=X, y=Y( 5), linestyle='yellow', mark=None, legend='n=5' )
graph.plot(x=X, y=Y( 8), linestyle='green' , mark=None, legend='n=8' )
graph.plot(x=X, y=Y(13), linestyle='blue'  , mark=None, legend='n=13')
#graph.plot(x=X, y=Y(21), linestyle='violet', mark=None, legend='n=21')
#graph.plot(x=X, y=Y(34), linestyle='violet', mark=None, legend='n=34')
graph.plot(x=X, y=Y(55), linestyle='cyan'  , mark=None, legend='n=55')
graph.plot(x=X, y=Y_sqr, linestyle='black' , mark=None, legend='square')

graph.save_as_pdf('plot')
Exemple #17
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)
Exemple #18
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(' ', '-'))
Exemple #19
0
            cq.events_from_stations([coincidence], STATIONS))
        reconstruction = cq._get_reconstruction(coincidence)
        core_x = reconstruction['x']
        core_y = reconstruction['y']

        plot = Plot()

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

        distances = arange(1, 370, 1)
        times = (2.43 * (1 + distances / 30.)**1.55) + 20
        plot.plot(distances, times, mark=None)

        for station_number, event in coincidence_events:
            station = CLUSTER.get_station(station_number)
            offsets = OFFSETS[station_number]
            t = relative_detector_arrival_times(event,
                                                ref_extts,
                                                offsets=offsets)
            core_distances = []
            for d in station.detectors:
                x, y = d.get_xy_coordinates()
                core_distances.append(distance_between(core_x, core_y, x, y))
            plot.scatter(core_distances,
                         t,
                         mark='*',
                         markstyle=COLORS[station_number])
        plot.set_ylabel('Relative arrival time [ns]')
        plot.set_xlabel('Distance from core [m]')
        plot.save_as_pdf('relative_arrival_times')
    counts_in_years = counts / 24. / 365.
    plot.histogram(counts_in_years, bins, linestyle='semitransparent')

    # Exluding data from before 26-09-2008
    start = argmax(timestamps > datetime_to_gps(date(2008, 9, 26)))
    counts, bins = histogram(summed_data[start:], bins=bins)
    counts_in_years = counts / 24. / 365.
    print[(i, sum(counts_in_years[i:])) for i in range(11)]
    plot.histogram(counts_in_years, bins)

    # Exluding data from before 08-03-2010
    start = argmax(timestamps > datetime_to_gps(date(2010, 3, 8)))
    counts, bins = histogram(summed_data[start:], bins=bins)
    counts_in_years = counts / 24. / 365.
    print[(i, sum(counts_in_years[i:])) for i in range(11)]
    plot.histogram(counts_in_years, bins, linestyle='blue')

    # Exluding data from before 01-07-2011
    start = argmax(timestamps > datetime_to_gps(date(2011, 7, 1)))
    counts, bins = histogram(summed_data[start:], bins=bins)
    counts_in_years = counts / 24. / 365.
    print[(i, sum(counts_in_years[i:])) for i in range(11)]
    plot.histogram(counts_in_years, bins, linestyle='red')

    plot.set_ylimits(min=0)
    plot.set_xlimits(min=-0.5, max=len(STATIONS) + .5)
    plot.set_ylabel('Number of years')
    plot.set_xlabel(
        'Number of simultaneously active stations (Science Park, sans 507)')
    plot.save_as_pdf('n_stations_spa')
                                       (data[sn]['counts'] < 5000))
    return timestamps, extended_data


if __name__ == "__main__":
    timestamps, eventtime = get_aligned()
    summed_data = eventtime.sum(axis=0)
    plot = Plot()

    counts, bins = histogram(summed_data, bins=arange(-.5, 100.5, 1))
    counts_in_years = counts / 24. / 365.
    plot.histogram(counts_in_years, bins)

    # Exluding data from before 08-03-2010
    start = argmax(timestamps > datetime_to_gps(date(2010, 3, 8)))
    counts, bins = histogram(summed_data[start:], bins=bins)
    counts_in_years = counts / 24. / 365.
    plot.histogram(counts_in_years, bins, linestyle='blue')

    # Exluding data from before 01-07-2011
    start = argmax(timestamps > datetime_to_gps(date(2011, 7, 1)))
    counts, bins = histogram(summed_data[start:], bins=bins)
    counts_in_years = counts / 24. / 365.
    plot.histogram(counts_in_years, bins, linestyle='red')

    plot.set_ylimits(min=0)
    plot.set_xlimits(min=-0.5, max=100.5)
    plot.set_ylabel('Number of years')
    plot.set_xlabel('Number of simultaneously active stations')
    plot.save_as_pdf('n_stations_network')
Exemple #22
0
def plot_active_stations(timestamps, stations, aligned_data, data, i):

    first_ts = []
    last_ts = []
    stations_with_data = []

    assert aligned_data.shape[0] == len(stations)

    for n in range(aligned_data.shape[0]):
        prev_ts = 0
        for ts, has_data in zip(timestamps, aligned_data[n]):
            if has_data:
                if prev_ts > 30:
                    # Running for at least 30 hours.
                    first_ts.append(ts)
                    stations_with_data.append(stations[n])
                    break
                else:
                    prev_ts += 1
            else:
                prev_ts = 0

    for station in stations_with_data:
        end_ts = get_station_end_timestamp(station, data)
        if end_ts is not None:
            last_ts.append(end_ts)

    first_ts = sorted(first_ts)
    last_ts = sorted(last_ts)
    diff_stations = array([1] * len(first_ts) + [-1] * len(last_ts))
    idx = argsort(first_ts + last_ts)
    n_stations = diff_stations[idx].cumsum()

    # Get maximinum number of simultaneaously active stations per 7 days
    n_active_aligned = (aligned_data != 0).sum(axis=0)
    n_binned, t_binned, _ = binned_statistic(timestamps,
                                             n_active_aligned,
                                             npmax,
                                             bins=len(timestamps) / (7 * 24))
    # Get average number of detected events per 7 days
    # todo; scale 2/4 detector stations
    summed_data = aligned_data.sum(axis=0)
    e_binned, t_binned, _ = binned_statistic(timestamps,
                                             summed_data,
                                             average,
                                             bins=len(timestamps) / (7 * 24))

    plot = Plot(width=r'.5\textwidth')
    plot.plot([t / 1e9 for t in sorted(first_ts + last_ts)],
              n_stations,
              linestyle='gray, thick',
              mark=None,
              use_steps=True)
    plot.histogram(n_binned, t_binned / 1e9, linestyle='thick')
    plot.histogram(e_binned * max(n_binned) / max(e_binned),
                   t_binned / 1e9,
                   linestyle='blue')
    plot.set_axis_options('line join=round')
    plot.set_ylabel('Number of stations')
    plot.set_xlabel('Date')
    plot.set_ylimits(min=0)
    plot.set_xticks([datetime_to_gps(date(y, 1, 1)) / 1e9 for y in YEARS[::3]])
    plot.set_xtick_labels(['%d' % y for y in YEARS[::3]])
    plot.save_as_pdf('active_stations_%s' % ['network', 'spa'][i])
Exemple #23
0
def analyse_reconstructions(path):
    seed = os.path.basename(os.path.dirname(path))

    cq = CoincidenceQuery(path)
    c_ids = cq.coincidences.get_where_list('N >= 3')
    if not len(cq.reconstructions) or not len(c_ids):
        cq.finish()
        return
    c_recs = cq.reconstructions.read_coordinates(c_ids)

    # Angles
    zen_out = c_recs['zenith']
    azi_out = c_recs['azimuth']
    zen_in = c_recs['reference_zenith']
    azi_in = c_recs['reference_azimuth']

    # Cores
    x_out = c_recs['x']
    y_out = c_recs['y']
    x_in = c_recs['reference_x']
    y_in = c_recs['reference_y']

    # Size
    size_out = c_recs['size']
    energy_out = c_recs['energy']
    size_in = c_recs['reference_size']
    energy_in = c_recs['reference_energy']

    energy = np.log10(energy_in[0])
    zenith = np.degrees(zen_in[0])
    label = r'$E=10^{%d}$eV, $\theta={%.1f}^{\circ}$' % (energy, zenith)

    # Azimuth
    bins = np.linspace(-np.pi, np.pi, 21)
    acounts_out, bins = np.histogram(azi_out, bins)
    acounts_in, bins = np.histogram(azi_in, bins)

    plota = Plot()
    plota.histogram(acounts_out, bins)
    plota.histogram(acounts_in, bins, linestyle='red')
    plota.set_xlabel(r'$\phi$ [\si{\radian}]')
    plota.set_xlimits(-np.pi, np.pi)
    plota.set_ylabel(r'Counts')
    plota.set_ylimits(min=0)
    plota.save_as_pdf('plots/azimuth_in_out_%s' % seed)

    # Zenith
    bins = np.linspace(0, np.pi / 2, 21)
    zcounts_out, bins = np.histogram(zen_out, bins)
    zcounts_in, bins = np.histogram(zen_in, bins)

    plotz = Plot()
    plotz.histogram(zcounts_out, bins)
    plotz.histogram(zcounts_in, bins, linestyle='red')
    plotz.set_xlabel(r'$\theta$ [\si{\radian}]')
    plotz.set_xlimits(0, np.pi / 2)
    plotz.set_ylabel(r'Counts')
    plotz.set_ylimits(min=0)
    plotz.save_as_pdf('plots/zenith_in_out_%s' % seed)

    # Angle between
    angle_distances = angle_between(zen_out, azi_out, zen_in, azi_in)
    if len(np.isfinite(angle_distances)):
        bins = np.linspace(0, np.pi / 2, 91)
        counts, bins = np.histogram(angle_distances, bins=bins)
        plotd = Plot()
        plotd.histogram(counts, np.degrees(bins))
        sigma = np.percentile(angle_distances[np.isfinite(angle_distances)],
                              67)
        plotd.set_label(label + r', 67\%% within \SI{%.1f}{\degree}' %
                        np.degrees(sigma))
        plotd.set_xlabel(r'Angle between reconstructions [\si{\degree}]')
        plotd.set_ylabel('Counts')
        plotd.set_xlimits(np.degrees(bins[0]), np.degrees(bins[-1]))
        plotd.set_ylimits(min=0)
        plotd.save_as_pdf('plots/angle_between_in_out_%s' % seed)

    # Distance beween
    filter = size_out != 1e6
    core_distances = np.sqrt(
        (x_out.compress(filter) - x_in.compress(filter))**2 +
        (y_out.compress(filter) - y_in.compress(filter))**2)
    if len(np.isfinite(core_distances)):
        bins = np.linspace(0, 1000, 100)
        counts, bins = np.histogram(core_distances, bins=bins)
        plotc = Plot()
        plotc.histogram(counts, bins)
        sigma = np.percentile(core_distances[np.isfinite(core_distances)], 67)
        #
        energy = np.log10(energy_in[0])
        zenith = np.degrees(zen_in[0])
        #
        plotc.set_label(r'$E=10^{%d}$eV, $\theta={%.1f}^{\circ}$, 67\%% '
                        'within \SI{%.1f}{\meter}' % (energy, zenith, sigma))
        plotc.set_xlabel(r'Distance between cores [\si{\meter}]')
        plotc.set_ylabel('Counts')
        plotc.set_xlimits(bins[0], bins[-1])
        plotc.set_ylimits(min=0)
        plotc.save_as_pdf('plots/core_distance_between_in_out_%s' % seed)

    # Core positions
    filter = size_out != 1e6
    plotc = Plot()
    for x0, x1, y0, y1 in zip(x_out, x_in, y_out, y_in):
        plotc.plot([x0, x1], [y0, y1])
    plotc.set_xlabel(r'x [\si{\meter}]')
    plotc.set_ylabel(r'y [\si{\meter}]')
    plotc.set_xlimits(bins[0], bins[-1])
    plotc.set_ylimits(min=0)
    plotc.save_as_pdf('plots/core_positions_in_out_%s' % seed)

    # Shower size
    relative_size = size_out.compress(filter) / size_in.compress(filter)
    counts, bins = np.histogram(relative_size, bins=np.logspace(-2, 2, 21))
    plots = Plot('semilogx')
    plots.histogram(counts, bins)
    plots.set_xlabel('Relative size')
    plots.set_ylabel('Counts')
    plots.set_xlimits(bins[0], bins[-1])
    plots.set_ylimits(min=0)
    plots.save_as_pdf('plots/size_in_out_%s' % seed)

    # Cleanup
    cq.finish()
Exemple #24
0
def determine_station_timing_offsets(d, data):
    # First determine detector offsets for each station
    offsets = {}
    for s in [501, 510]:
        station_group = data.get_node('/hisparc/cluster_amsterdam/station_%d' % s)
        offsets[s] = determine_detector_timing_offsets2(station_group.events)

    ref_station = 501
    ref_d_off = offsets[ref_station]

    station = 510

    cq = CoincidenceQuery(data, '/coincidences')
    dt = []
    d_off = offsets[station]
    stations = [ref_station, station]
    coincidences = cq.all(stations)
    c_events = cq.events_from_stations(coincidences, stations)
    for events in c_events:
        # Filter for possibility of same station twice in coincidence
        if len(events) is not 2:
            continue
        if events[0][0] == ref_station:
            ref_event = events[0][1]
            event = events[1][1]
        else:
            ref_event = events[1][1]
            event = events[0][1]

        try:
            ref_t = min([ref_event['t%d' % (i + 1)] - ref_d_off[i]
                         for i in range(4)
                         if ref_event['t%d' % (i + 1)] not in ERR])
            t = min([event['t%d' % (i + 1)] - d_off[i]
                     for i in range(4)
                     if event['t%d' % (i + 1)] not in ERR])
        except ValueError:
            continue
        if (ref_event['t_trigger'] in ERR or event['t_trigger'] in ERR):
            continue
        dt.append((int(event['ext_timestamp']) -
                   int(ref_event['ext_timestamp'])) -
                  (event['t_trigger'] - ref_event['t_trigger']) +
                  (t - ref_t))

    bins = linspace(-150, 150, 200)
    y, bins = histogram(dt, bins=bins)
    x = (bins[:-1] + bins[1:]) / 2
    try:
        popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 50))
        station_offset = popt[1]
    except RuntimeError:
        station_offset = 0.
    offsets[station] = [detector_offset + station_offset
                        for detector_offset in offsets[station]]
    print 'Station 501 - 510: %f (%f)' % (popt[1], popt[2])
    graph = Plot()
    graph.histogram(y, bins)
    graph.set_title('Time difference, between station 501-510')
    graph.set_label('%s' % d.replace('_', ' '))
    graph.set_xlimits(-150, 150)
    graph.set_ylimits(min=0)
    graph.set_xlabel('$\Delta t$')
    graph.set_ylabel('Counts')
    graph.save_as_pdf('%s' % d)
Exemple #25
0
def plot_pulseintegrals():

    station_number = 501
    in_bins = linspace(1, 15000, 200)
    ph_bins = linspace(10, 1500, 200)
    az_bins = linspace(-pi, pi, 40)
    ze_bins = linspace(0, pi / 2., 50)
    min_n = 1.5
    max_zenith = radians(45)

    with tables.open_file(STATION_PATH, 'r') as data:
        sn = data.get_node('/s%d' % station_number)
        n_filter = set(
            sn.events.get_where_list(
                '(n1 >= min_n) & (n2 >= min_n) & (n4 >= min_n)'))
        z_filter = set(
            sn.reconstructions.get_where_list(
                '(zenith < max_zenith) & d1 & d2 & d4'))
        filter = list(n_filter & z_filter)
        integrals = sn.events.col('integrals')[filter]
        pulseheights = sn.events.col('pulseheights')[filter]
        azimuths = sn.reconstructions.col('azimuth')[filter]
        zeniths = sn.reconstructions.col('zenith')[filter]

    plot = Plot()
    counts, az_bins = histogram(azimuths, bins=az_bins)
    plot.histogram(counts, az_bins)

    # Smoothed version of azimuth histogram to counter discreteness at low zenith.
    smoothing = normal(scale=radians(8), size=len(azimuths))
    counts, az_bins = histogram(norm_angle(azimuths + smoothing), bins=az_bins)
    plot.histogram(counts, az_bins, linestyle='gray')

    plot.draw_horizontal_line(mean(counts), linestyle='red')
    plot.draw_horizontal_line(mean(counts) + sqrt(mean(counts)),
                              linestyle='dashed, red')
    plot.draw_horizontal_line(mean(counts) - sqrt(mean(counts)),
                              linestyle='dashed, red')
    plot.set_ylimits(min=0)
    plot.set_xlimits(-pi, pi)
    plot.save_as_pdf('azimuth')

    plot = Plot()
    counts, ze_bins = histogram(zeniths, bins=ze_bins)
    plot.histogram(counts, ze_bins)
    plot.set_ylimits(min=0)
    plot.set_xlimits(0, pi / 2)
    plot.save_as_pdf('zeniths')

    for i in range(4):
        plot = Plot('semilogy')
        counts, in_bins = histogram(integrals[:, i], bins=in_bins)
        plot.histogram(counts, in_bins)
        counts, in_bins = histogram(integrals[:, i] * cos(zeniths),
                                    bins=in_bins)
        plot.histogram(counts, in_bins, linestyle='red')
        plot.set_ylimits(min=1)
        plot.save_as_pdf('integrals_%d' % i)

        plot = Plot('semilogy')
        counts, ph_bins = histogram(pulseheights[:, i], bins=ph_bins)
        plot.histogram(counts, ph_bins)
        counts, ph_bins = histogram(pulseheights[:, i] * cos(zeniths),
                                    bins=ph_bins)
        plot.histogram(counts, ph_bins, linestyle='red')
        plot.set_ylimits(min=1)
        plot.save_as_pdf('pulseheights_%d' % i)
Exemple #26
0
def plot_size_energy():
    cq = CorsikaQuery(OVERVIEW)
    p = 'proton'
    plot = Plot(axis='semilogy')
    for z in cq.available_parameters('zenith', particle=p):
        zen_plot = Plot(axis='semilogy')
        shade = 'black!%f' % (100 - z)

        energies = sorted(cq.available_parameters('energy', particle=p,
                                                  zenith=z))
        sizes_m = []
        sizes_e = []
        sizes_l = []
        energies_m = []
        energies_e = []
        energies_l = []

        for e in energies:
            selection = cq.simulations(zenith=z, energy=e, particle=p)
            if median(selection['n_muon']):
                sizes_m.append(median(selection['n_muon']))
                energies_m.append(e)
            if median(selection['n_electron']):
                sizes_e.append(median(selection['n_electron']))
                energies_e.append(e)
            if median(selection['n_muon'] + selection['n_electron']):
                sizes_l.append(median(selection['n_muon'] + selection['n_electron']))
                energies_l.append(e)

        # Plot data points
        zen_plot.scatter(energies_m, sizes_m, mark='+')
        zen_plot.scatter(energies_e, sizes_e, mark='x')
        zen_plot.scatter(energies_l, sizes_l, mark='square')
        plot.scatter(energies_l, sizes_l, mark='square', markstyle=shade)

        # Fit
        initial = (10.2, 1.)
        popt_m, pcov_m = curve_fit(f, energies_m, log10(sizes_m), p0=initial)
        popt_e, pcov_e = curve_fit(f, energies_e, log10(sizes_e), p0=initial)
        popt, pcov = curve_fit(f, energies_l, log10(sizes_l), p0=initial)

        # Plot fits
        fit_energies = arange(10, 20, 0.25)
        sizes = [10 ** f(e, *popt_m) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None, linestyle='red')

        sizes = [10 ** f(e, *popt_e) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None, linestyle='blue')

        sizes = [10 ** f(e, *popt) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None)
        plot.plot(fit_energies, sizes, mark=None, linestyle=shade)

        zen_plot.set_ylimits(1, 1e9)
        zen_plot.set_xlimits(10.5, 18.5)
        zen_plot.set_ylabel(r'Shower size [number of leptons]')
        zen_plot.set_xlabel(r'Shower energy [log10(E/eV)]')
        zen_plot.save_as_pdf('shower_size_v_energy_%.1f.pdf' % z)
    plot.set_ylimits(1, 1e9)
    plot.set_xlimits(10.5, 18.5)
    plot.set_ylabel(r'Shower size [number of leptons]')
    plot.set_xlabel(r'Shower energy [log10(E/eV)]')
    plot.save_as_pdf('shower_size_v_energy')
    cq.finish()
Exemple #27
0
def combine_delta_data():
    delta_data = genfromtxt('data/time_delta.tsv',
                            delimiter='\t',
                            dtype=None,
                            names=['ext_timestamp', 'time_delta'])
    delta_data = {ets: td for ets, td in delta_data}

    tm = []
    ts = []
    td = []
    te = []
    with tables.open_file('data/data.h5', 'r') as data:
        for row in data.root.s99.events:
            ets = row['ext_timestamp']
            try:
                dt = delta_data[ets]
            except KeyError:
                continue
            tm.append(row['t1'])
            ts.append(row['t3'])
            td.append(dt)
            te.append(ets)
    tm = array(tm)
    ts = array(ts)
    td = array(td)
    te = array(te)
    filter = (tm >= 0) & (ts >= 0)
    tm = tm.compress(filter)
    ts = ts.compress(filter)
    td = td.compress(filter)
    te = te.compress(filter)

    bins = arange(-10.25, 10.26, .5)
    mplot = MultiPlot(3, 2, width=r'.4\linewidth', height=r'.3\linewidth')
    mplot.show_xticklabels_for_all([(2, 0), (2, 1)])
    mplot.show_yticklabels_for_all([(0, 0), (1, 1), (2, 0)])
    mplot.set_xlimits_for_all(min=-11, max=11)
    mplot.set_ylimits_for_all(min=0, max=1500)
    mplot.set_ylabel('Counts')
    mplot.set_xlabel(r'Time difference [\si{\nano\second}]')

    plot = mplot.get_subplot_at(0, 0)
    counts, bins = histogram(tm - ts, bins=bins)
    popt = fit_timing_offset(counts / 3., bins)
    plot.set_label(r'$t_{M} - t_{S}$, $%.1f\pm%.1f$\si{\nano\second}, scaled' %
                   (popt[1], popt[2]))
    plot.histogram(counts / 3., bins)
    plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray')

    plot = mplot.get_subplot_at(1, 0)
    plot.set_label(r'$t_{\delta}$')
    plot.histogram(*histogram(td, bins=bins))

    plot = mplot.get_subplot_at(2, 0)
    counts, bins = histogram(tm - (ts + td), bins=bins)
    popt = fit_timing_offset(counts, bins)
    plot.set_label(
        r'$t_{M} - (t_{S} + t_{\delta})$, $%.1f\pm%.1f$\si{\nano\second}' %
        (popt[1], popt[2]))
    plot.histogram(counts, bins)
    plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray')

    plot = mplot.get_subplot_at(0, 1)
    plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == -5$')
    plot.draw_vertical_line(-5, linestyle='gray')
    plot.histogram(*histogram(td.compress(tm - ts == -5), bins=bins))
    plot = mplot.get_subplot_at(1, 1)
    plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == -2.5$')
    plot.draw_vertical_line(-2.5, linestyle='gray')
    plot.histogram(*histogram(td.compress(tm - ts == -2.5), bins=bins))
    plot = mplot.get_subplot_at(2, 1)
    plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == 0$')
    plot.draw_vertical_line(0, linestyle='gray')
    plot.histogram(*histogram(td.compress(tm - ts == 0), bins=bins))
    mplot.save_as_pdf('dt_time_delta')

    plot = Plot()

    counts, xbins, ybins = histogram2d(tm - ts, td, bins=bins)
    plot.histogram2d(counts, xbins, ybins, bitmap=True, type='reverse_bw')
    plot.set_xlabel(r'$t_{M} - t_{S}$ [\si{\nano\second}]')
    plot.set_ylabel(r'$t_{\delta}$ [\si{\nano\second}]')

    plot.save_as_pdf('dt_vs_time_delta')
Exemple #28
0
CLUSTER = HiSPARCStations(SPA_STAT)

DATA_PATH = '/Users/arne/Datastore/station_offsets/'


def get_station_dt(data, station):
    table = data.get_node('/s%d' % station)
    return table


if __name__ == '__main__':
    t_start = datetime_to_gps(datetime(2010, 1, 1))
    t_end = datetime_to_gps(datetime(2015, 4, 1))

    for i, station in enumerate(STATIONS, 1):
        with tables.open_file(DATA_PATH + 'dt_ref501_%d.h5' % station, 'r') as data:
            distance, _, _ = CLUSTER.calc_rphiz_for_stations(i, 0)
            max_dt = max(distance / .3, 100) * 1.5
            table = get_station_dt(data, station)
            graph = Plot()
            counts, x, y = histogram2d(table.col('timestamp'),
                                       table.col('delta'),
                                       bins=(arange(t_start, t_end, XWEEK),
                                             linspace(-max_dt, max_dt, 150)))
            graph.histogram2d(counts, x, y, bitmap=True, type='color')
            graph.set_ylabel('$\Delta t$ [ns]')
            graph.set_xlabel('Timestamp [s]')
            graph.set_xlimits(t_start, t_end)
            graph.set_ylimits(-max_dt, max_dt)
            graph.save_as_pdf('plots/2d_distribution/dt_%d_xweek' % station)
Exemple #29
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'])
Exemple #30
0
    popt, pcov = curve_fit(gauss, x, y, p0=(len(offsets), 0., 2.5))
    return x, y, popt


def plot_fit(x, y, popt, graph):
    graph.plot(x - BIN_WIDTH / 2, y, mark=None, use_steps=True)
    fit_x = arange(min(x), max(x), 0.1)
    graph.plot(fit_x, gauss(fit_x, *popt), mark=None, linestyle='gray')


if __name__ == '__main__':

    dates = [(2013, 3, 19), (2013, 10, 28), (2014, 1, 1), (2014, 1, 2),
             (2014, 1, 3), (2014, 1, 4), (2014, 1, 10), (2014, 1, 20),
             (2014, 1, 30)]
    files = [date(y, m, d) for y, m, d in dates]
    for f in files:
        path = DATA_PATH + f.strftime('%Y/%-m/%Y_%-m_%-d.h5')
        with tables.open_file(path, 'r') as data:
            offsets = determine_offsets(data)

        graph = Plot()
        x, y, popt = fit_offsets(offsets)
        plot_fit(x, y, popt, graph)
        graph.set_label('$\mu$: %.2f, $\sigma$: %.2f' % (popt[1], popt[2]))
        graph.set_ylabel('Occurrence')
        graph.set_xlabel('$\Delta t$ [ns]')
        graph.set_ylimits(min=0)
        graph.save_as_pdf('detector_offset_distribution_' +
                          f.strftime('%Y%m%d'))
Exemple #31
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')
Exemple #32
0
def plot_traces(traces1, traces2, overlap=0, label=''):
    """Plot traces

    :param traces: list of lists of trace values.
    :param label: name (suffix) for the output pdf.

    """
    colors1 = ['black', 'red', 'black!40!green', 'blue']
    colors2 = ['gray', 'black!40!red', 'black!60!green', 'black!40!blue']
    plot = Plot(width=r'1.\textwidth', height=r'.3\textwidth')

    times1 = arange(0, len(traces1[0]) * 2.5, 2.5)
    times2 = arange((len(traces1[0]) - overlap) * 2.5,
                    (len(traces1[0]) + len(traces2[0]) - overlap) * 2.5, 2.5)

    for i, trace in enumerate(traces1):
        plot.plot(times1,
                  array(trace) + i * 20,
                  linestyle='%s, ultra thin' % colors1[i],
                  mark=None)
    plot.draw_vertical_line(1000, 'gray, very thin')
    plot.draw_vertical_line(2500, 'gray, very thin')
    plot.draw_vertical_line(6000, 'pink, dashed, very thin')
    plot.add_pin_at_xy(0,
                       450,
                       r'\tiny{pre-trigger}',
                       location='right',
                       use_arrow=False)
    plot.add_pin_at_xy(1000,
                       450,
                       r'\tiny{trigger}',
                       location='right',
                       use_arrow=False)
    plot.add_pin_at_xy(2500,
                       450,
                       r'\tiny{post-trigger}',
                       location='right',
                       use_arrow=False)
    plot.add_pin_at_xy(6000,
                       450,
                       r'\tiny{end of first event}',
                       location='left',
                       use_arrow=True)

    for i, trace in enumerate(traces2):
        plot.plot(times2,
                  array(trace) + i * 20,
                  linestyle='%s, ultra thin' % colors2[i],
                  mark=None)
    plot.draw_vertical_line(6000 - (overlap * 2.5), 'pink, very thin')
    plot.draw_vertical_line(7000 - (overlap * 2.5), 'gray, very thin')
    plot.draw_vertical_line(8500 - (overlap * 2.5), 'gray, very thin')
    plot.add_pin_at_xy(6000 - (overlap * 2.5),
                       400,
                       r'\tiny{pre-trigger}',
                       location='right',
                       use_arrow=False)
    plot.add_pin_at_xy(7000 - (overlap * 2.5),
                       400,
                       r'\tiny{trigger}',
                       location='right',
                       use_arrow=False)
    plot.add_pin_at_xy(8500 - (overlap * 2.5),
                       400,
                       r'\tiny{post-trigger}',
                       location='right',
                       use_arrow=False)

    plot.set_ylabel(r'Signal strength [ADCcounts]')
    plot.set_xlabel(r'Event time [\si{\ns}]')
    plot.set_ylimits(0, 500)
    plot.set_xlimits(0, times2[-1])
    plot.set_axis_options('line join=round')
    plot.save_as_pdf('trace_' + label)