Exemple #1
0
def determine_detector_timing_offsets(d, 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()
    for i, j in itertools.combinations(range(1, 5), 2):
        ti = events.col('t%d' % i)
        tj = events.col('t%d' % j)
        dt = (ti - tj).compress((ti >= 0) & (tj >= 0))
        y, bins = histogram(dt, bins=bins)
        graph.histogram(y, bins, linestyle='color=%s' % col.next())
        x = (bins[:-1] + bins[1:]) / 2
        try:
            popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 10.))
            print '%d-%d: %f (%f)' % (i, j, popt[1], popt[2])
        except (IndexError, RuntimeError):
            print '%d-%d: failed' % (i, j)
    graph.set_title('Time difference, station %d' % (s))
    graph.set_label('%s' % d.replace('_', ' '))
    graph.set_xlimits(-100, 100)
    graph.set_ylimits(min=0)
    graph.set_xlabel('$\Delta t$')
    graph.set_ylabel('Counts')
    graph.save_as_pdf('%s_%d' % (d, s))
Exemple #2
0
def plot_fit(x, data, slope, intercept, pair):
    plot = Plot()
    plot.scatter(x, log(c))
    plot.plot(x, x * slope + intercept, mark=None)
    plot.set_ylimits(min=0)
    plot.set_label(r'%.1e \si{\hertz}' % rate)
    plot.save_as_pdf('intervals/intervals_%d_%d_r' % pair)
Exemple #3
0
def plot_traces():

    with tables.open_file(DATA, 'r') as data:
        for i, pre, coin, post in TIME_WINDOWS:
            test_node = data.get_node('/t%d' % i)
            events = test_node.events.read()
            events.sort(order='ext_timestamp')
            blobs = test_node.blobs
            for e_idx in [0, 1]:
                t_idx = events[e_idx]['traces'][1]
                extts = events[e_idx]['ext_timestamp']
                try:
                    trace = zlib.decompress(blobs[t_idx]).split(',')
                except zlib.error:
                    trace = zlib.decompress(blobs[t_idx][1:-1]).split(',')
                if trace[-1] == '':
                    del trace[-1]
                trace = [int(x) for x in trace]
                plot = Plot()
                plot.plot(range(len(trace)), trace, mark=None)
                plot.set_label('%d' % extts)
                microsec_to_sample = 400
                plot.draw_vertical_line(pre * microsec_to_sample,
                                        linestyle='thick,red,semitransparent')
                plot.draw_vertical_line((pre + coin) * microsec_to_sample,
                                        linestyle='thick,blue,semitransparent')
                plot.set_ylabel('Signal strength [ADCcounts]')
                plot.set_xlabel('Sample [2.5ns]')
                plot.set_ylimits(min=150, max=1500)
                plot.set_xlimits(min=0, max=len(trace))
                plot.save_as_pdf('trace_%d_%d' % (i, e_idx))
Exemple #4
0
def plot_and_fit_offsets(x, y, popt, d, id):
    plot = Plot()
    plot_data_and_fit(x, y, popt, plot)
    plot.set_label('$\mu$: %.2f, $\sigma$: %.2f' % (popt[1], popt[2]))
    plot.set_ylabel('Occurrence')
    plot.set_xlabel('$\Delta t$ [ns]')
    plot.set_ylimits(min=0)
    plot.save_as_pdf('api_detector_offset_distribution_%s_' % id +
                     d.strftime('%Y%m%d'))
Exemple #5
0
def plot_distributions(distances, name=''):
    bins = arange(0, 10.001, 0.2)
    plot = Plot()
    plot.histogram(*histogram(distances, bins))
    plot.set_ylimits(min=0)
    plot.set_xlimits(min=0, max=10)
    plot.set_ylabel('Counts')
    plot.set_xlabel(r'Distance to center mass location [\si{\meter}]')
    plot.set_label('67\%% within %.1fm' % percentile(distances, 67))
    plot.save_as_pdf('gps_distance_cm' + name)
Exemple #6
0
def plot_compared():
    popt, perr = fit_curve(senstech_m_ph, senstech_e_ph)
    fit = FIT % (popt[0], P1, popt[1])

    plot = Plot(width=r'.67\linewidth', height=r'.67\linewidth')
    plot.set_label(fit, location='upper left')
    plot.scatter(senstech_e_ph, senstech_m_ph, mark='*')
    plot.scatter(nikhef_e_ph, nikhef_m_ph, mark='o')
    inputs = linspace(min(senstech_m_ph), max(senstech_m_ph), 500)
    plot.plot(ice_cube_pmt_p1(inputs, *popt), inputs, mark=None)
    plot.plot([0, 6], [0, 6], mark=None, linestyle='gray')
    plot.set_xlimits(0, 6)
    plot.set_ylimits(0, 6)
    plot.set_axis_equal()
    plot.set_xlabel(r'Sum individual LED pulseheights [\si{\volt}]')
    plot.set_ylabel(r'Multiple-LED pulseheight [\si{\volt}]')
    plot.save_as_pdf('plots/linearity_compared')
Exemple #7
0
def plot_distribution():
    for e in arange(14, 18, 1):
        for core_distance in [1, 5, 10, 50, 100, 500, 1000]:
            path = ('/Users/arne/Datastore/first_particle/first_{e}_{r}.npy'.
                    format(e=e, r=core_distance))
            times = load(path)
            counts, bins = histogram(times, bins=20)
            plot = Plot()
            plot.histogram(counts, bins)
            plot.set_xlabel('arrival time [ns]')
            plot.set_ylabel('Counts')
            plot.set_ylimits(min=0)
            plot.set_xlimits(bins[0], bins[-1])
            plot.set_label('E=$10^{{{e}}}$eV, r={r}m'.format(e=e,
                                                             r=core_distance))
            plot.save_as_pdf('plots/first_particle_{e}_{r}_new'.format(
                e=e, r=core_distance))
Exemple #8
0
def plot_reconstruction_accuracy(data, d):

    station_path = '/cluster_simulations/station_%d'
    cluster = cluster_501_510()
    coincidences = data.root.coincidences.coincidences
    recs501 = data.root.hisparc.cluster_amsterdam.station_501.reconstructions
    recs510 = data.root.hisparc.cluster_amsterdam.station_510.reconstructions
    graph = Plot()
    ids = set(recs501.col('id')).intersection(recs510.col('id'))
    filtered_501 = [(row['zenith'], row['azimuth']) for row in recs501
                    if row['id'] in ids]
    filtered_510 = [(row['zenith'], row['azimuth']) for row in recs510
                    if row['id'] in ids]

    zen501, azi501 = zip(*filtered_501)
    zen510, azi510 = zip(*filtered_510)
    zen501 = array(zen501)
    azi501 = array(azi501)
    zen510 = array(zen510)
    azi510 = array(azi510)
    da = angle_between(zen501, azi501, zen510, azi510)

    n, bins = histogram(da, bins=arange(0, pi, .1))
    graph.histogram(n, bins)

    failed = coincidences.nrows - len(ids)
    graph.set_ylimits(min=0)
    graph.set_xlimits(min=0, max=pi)
    graph.set_ylabel('Count')
    graph.set_xlabel('Angle between 501 and 510 [rad]')
    graph.set_title('Coincidences between 501 and 510')
    graph.set_label('Failed to reconstruct %d events' % failed)
    graph.save_as_pdf('coincidences_%s' % d)

    graph_recs = PolarPlot()
    azimuth = degrees(recs501.col('azimuth'))
    zenith = degrees(recs501.col('zenith'))
    graph_recs.scatter(azimuth[:5000],
                       zenith[:5000],
                       mark='*',
                       markstyle='mark size=.2pt')
    graph_recs.set_ylimits(min=0, max=90)
    graph_recs.set_ylabel('Zenith [degrees]')
    graph_recs.set_xlabel('Azimuth [degrees]')
    graph_recs.set_title('Reconstructions by 501')
    graph_recs.save_as_pdf('reconstructions_%s' % d)
Exemple #9
0
def plot_delta_histogram(ids, **kwargs):
    """ Plot a histogram of the deltas

    """
    if type(ids) is int:
        ids = [ids]

    # Bin width
    bin_size = 1  # 2.5*n

    # Begin Figure
    plot = Plot()
    for id in ids:
        ext_timestamps, deltas = get(id)
        low = floor(min(deltas))
        high = ceil(max(deltas))
        bins = np.arange(low - .5 * bin_size, high + bin_size, bin_size)
        n, bins = np.histogram(deltas, bins)
        bin_centers = (bins[:-1] + bins[1:]) / 2
        popt, pcov = curve_fit(gauss,
                               bin_centers,
                               n,
                               p0=[.15, np.mean(deltas),
                                   np.std(deltas)])
        plot.histogram(n, bins)
        plot.plot(bin_centers,
                  gauss(bin_centers, *popt),
                  mark=None,
                  linestyle='gray')
    if kwargs.keys():
        plot.set_title('Tijdtest ' + kwargs[kwargs.keys()[0]])
    plot.set_label(r'$\mu={1:.1f}$, $\sigma={2:.1f}$'.format(*popt))
    plot.set_xlabel(r'Time difference [ns]')
    plot.set_ylabel(r'Counts')
    plot.set_xlimits(low, high)
    plot.set_ylimits(min=0.)

    # Save Figure
    if len(ids) == 1:
        name = 'delta_histogram/tt_delta_hist_%03d' % ids[0]
    elif kwargs.keys():
        name = 'delta_histogram/tt_delta_hist_' + kwargs[kwargs.keys()[0]]
    plot.save_as_pdf(PLOT_PATH + name)

    print 'tt_analyse: Plotted histogram'
def main():
    # Draw random numbers from the normal distribution
    np.random.seed(1)
    N = np.random.normal(size=2000)

    # define bin edges
    edge = 5
    bin_width = .1
    bins = np.arange(-edge, edge + .5 * bin_width, bin_width)

    # build histogram and x, y values at the center of the bins
    n, bins = np.histogram(N, bins=bins)
    x = (bins[:-1] + bins[1:]) / 2
    y = n

    # fit normal distribution pdf to data
    f = lambda x, N, mu, sigma: N * scipy.stats.norm.pdf(x, mu, sigma)
    popt, pcov = scipy.optimize.curve_fit(f, x, y)
    print("Parameters from fit (N, mu, sigma):", popt)

    # make graph
    graph = Plot()

    # graph histogram
    graph.histogram(n, bins)

    # graph model with fit parameters
    x = np.linspace(-edge, edge, 100)
    graph.plot(x, f(x, *popt), mark=None)

    # set labels and limits
    graph.set_xlabel("value")
    graph.set_ylabel("count")
    graph.set_label("Fit to data")
    graph.set_xlimits(-6, 6)

    # save graph to file
    graph.save('histogram-fit')
Exemple #11
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 #12
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 #13
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 #14
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 #15
0
def plot_reconstruction_accuracy():

    combinations = ['~d1 | ~d2 | ~d3 | ~d4', 'd1 & d2 & d3 & d4']
    station_path = '/cluster_simulations/station_%d'
    with tables.open_file(RESULT_PATH, 'r') as data:
        cluster = data.root.coincidences._v_attrs.cluster
        coincidences = data.root.coincidences.coincidences
        c_recs = data.root.coincidences.reconstructions
        graph = Plot()
        da = angle_between(c_recs.col('zenith'), c_recs.col('azimuth'),
                           c_recs.col('reference_zenith'),
                           c_recs.col('reference_azimuth'))
        ids = c_recs.col('id')
        N = coincidences.read_coordinates(ids, field='N')
        for k, filter in enumerate([N == 3, N > 3]):
            n, bins = histogram(da.compress(filter), bins=arange(0, pi, .1))
            graph.histogram(n, bins, linestyle=GRAYS[k % len(GRAYS)])

        failed = len(coincidences.get_where_list('N >= 3')) - c_recs.nrows
        graph.set_ylimits(min=0)
        graph.set_xlimits(min=0, max=pi)
        graph.set_ylabel('Count')
        graph.set_xlabel('Angle between input and reconstruction [rad]')
        graph.set_title('Coincidences')
        graph.set_label('Failed to reconstruct %d events' % failed)
        graph.save_as_pdf('coincidences_alt')

        for station in cluster.stations:
            station_group = data.get_node(station_path % station.number)
            recs = station_group.reconstructions
            rows = coincidences.get_where_list('s%d == True' % station.number)
            reference_azimuth = coincidences.read_coordinates(rows,
                                                              field='azimuth')
            reference_zenith = coincidences.read_coordinates(rows,
                                                             field='zenith')
            graph = Plot()
            for k, combo in enumerate(combinations):
                selected_reconstructions = recs.read_where(combo)
                filtered_azimuth = array([
                    reference_azimuth[i]
                    for i in selected_reconstructions['id']
                ])
                filtered_zenith = array([
                    reference_zenith[i] for i in selected_reconstructions['id']
                ])
                azimuth = selected_reconstructions['azimuth']
                zenith = selected_reconstructions['zenith']

                da = angle_between(zenith, azimuth, filtered_zenith,
                                   filtered_azimuth)
                n, bins = histogram(da, bins=arange(0, pi, .1))
                graph.histogram(n, bins, linestyle=GRAYS[k % len(GRAYS)])
            failed = station_group.events.nrows - recs.nrows

            graph.set_ylimits(min=0)
            graph.set_xlimits(min=0, max=pi)
            graph.set_ylabel('Count')
            graph.set_xlabel('Angle between input and reconstruction [rad]')
            graph.set_title('Station: %d' % station.number)
            graph.set_label('Failed to reconstruct %d events' % failed)
            graph.save_as_pdf('s_%d' % station.number)
Exemple #16
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 #17
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 #18
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'))
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)
Exemple #20
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 #21
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 #22
0
def plot_thickness(seed):
    plot = Plot('semilogx')
    plot2 = Plot('loglog')
    data_path = os.path.join(LOCAL_STORE, seed, 'corsika.h5')
    with tables.open_file(data_path) as data:
        particles = data.get_node('/groundparticles')
        header = data.get_node_attr('/', 'event_header')
        end = data.get_node_attr('/', 'event_end')
        time_first_interaction = (header.first_interaction_altitude -
                                  header.observation_heights[0]) / .2998
        core_distances = logspace(0, 4, 31)
        min_t = []
        lower_t = []
        low_t = []
        median_t = []
        high_t = []
        higher_t = []
        max_t = []
        distances = []
        density = []
        xerr = []
        yerr = []
        for r_inner, r_outer in zip(core_distances[:-1], core_distances[1:]):
            t = particles.read_where('(r >= %f) & (r <= %f) & '
                                     '(particle_id >= 2) & (particle_id <= 6)' %
                                     (r_inner, r_outer), field='t')

            if len(t) < 1:
                continue

            area = area_between(r_outer, r_inner)
            density.append(len(t) / area)
            distances.append((r_outer + r_inner) / 2)
            # distances.append(10**((log10(r_outer) + log10(r_inner)) / 2))
            yerr.append(sqrt(len(t)) / area)
            xerr.append((r_outer - r_inner) / 2)
            percentiles_t = percentile(t, [0, 50])
            ref_t, med_t = percentiles_t - time_first_interaction
            min_t.append(ref_t)
            # lower_t.append(lsig2_t)
            # low_t.append(lsig1_t)
            median_t.append(med_t)
            # high_t.append(hsig1_t)
            # higher_t.append(hsig2_t)
            # max_t.append(m_t)

        energy = log10(header.energy)
        shower_size = log10(end.n_electrons_levels + end.n_muons_levels)
    plot.set_label('E=$10^{%.1f}$eV, size=$10^{%.1f}$' % (energy, shower_size),
                   location='upper left')

    plot.plot(distances, median_t, mark=None)
    plot.plot(distances, min_t, linestyle='dashed', mark=None)
    plot.draw_horizontal_line(1500)
    plot.set_xlimits(min=.5, max=1e4)
    plot.set_xlabel(r'core distance [m]')
    plot.set_ylabel(r'time after first [ns]')
    plot.set_ylimits(min=-10, max=1000)
    plot.save_as_pdf('plots/%.1f_%.1f_%s_front.pdf' % (energy, shower_size, seed))

    plot2.set_xlimits(min=.5, max=1e5)
    plot2.set_xlabel(r'core distance')
    plot2.set_ylabel(r'particle density')
    plot2.plot(distances, density, xerr=xerr, yerr=yerr, mark=None, markstyle='transparent', linestyle=None)
    plot2.draw_horizontal_line(2.46)
    # plot2.draw_horizontal_line(0.6813)
    plot2.save_as_pdf('plots/%.1f_%.1f_%s_dens.pdf' % (energy, shower_size, seed))