示例#1
0
def plot_comparison(stats, field_name):
    plot = MultiPlot(len(STATIONS),
                     len(STATIONS),
                     width=r'.06\textwidth',
                     height=r'.06\textwidth')
    bins = arange(0, 1.2, .03)
    for i, ref_station in enumerate(STATIONS):
        ref_stat = stats[ref_station][field_name][0]
        ref_filter = ref_stat > 0
        for j, station in enumerate(STATIONS):
            if i == j:
                plot.set_empty(i, j)
                plot.set_label(r'%d' % station, location='center')
                continue
            splot = plot.get_subplot_at(i, j)
            stat = stats[station][field_name][0]

            tmp_stat = stat.compress(ref_filter & (stat > 0))
            tmp_ref_stat = ref_stat.compress(ref_filter & (stat > 0))
            counts, xbin, ybin = histogram2d(tmp_stat, tmp_ref_stat, bins=bins)
            splot.histogram2d(counts,
                              xbin,
                              ybin,
                              type='reverse_bw',
                              bitmap=True)
            splot.plot([0, 1.2], [0, 1.2],
                       mark=None,
                       linestyle='red, very thin')


#     plot.set_xlimits_for_all(None, min=bins[0], max=bins[-1])
#     plot.set_ylimits_for_all(None, min=bins[0], max=bins[-1])
#     plot.subplots[-1].set_xtick_labels(YEARS_LABELS)
#     plot.subplots[-1].show_xticklabels()
#
#     plot.show_yticklabels_for_all(None)
#     for row in range(0, len(plot.subplots), 2):
#         plot.set_yticklabels_position(row, 0, 'left')
#     for row in range(1, len(plot.subplots), 2):
#         plot.set_yticklabels_position(row, 0, 'right')
#     plot.set_ylimits_for_all(None, -1e-4)

    if field_name == 'event_rate':
        label = r'Event rate [\si{\hertz}]'
    elif field_name == 'mpv':
        label = r'MPV [ADC.ns]'
    else:
        label = (r'Fraction of bad %s data [\si{\percent}]' %
                 field_name.replace('_', ' '))
    plot.set_ylabel(label)
    plot.set_xlabel(label)

    if field_name in ['event_rate', 'mpv']:
        plot.save_as_pdf('plots/compare_%s' % field_name)
    else:
        plot.save_as_pdf('plots/compare_bad_fraction_%s' % field_name)
示例#2
0
def plot_coinc_window(windows,
                      counts,
                      group_name='',
                      n_events=0,
                      n_stations=0,
                      date=datetime.date.today()):
    counts = numpy.array(counts)
    plot = MultiPlot(2, 1)

    splot = plot.get_subplot_at(0, 0)
    splot.set_axis_options(r'ymode=log, xmode=log')
    splot.scatter(windows, counts)
    plot_background_v_window(splot, windows, n_stations)
    plot_chosen_coincidence_window(splot)
    splot = plot.get_subplot_at(1, 0)
    # dy
    #     splot.scatter(windows[:-1], counts[1:] - counts[:-1])
    # dy/dx
    #     splot.scatter(windows[:-1],
    #                   (counts[1:] - counts[:-1]) /
    #                   (windows[1:] - windows[:-1]))
    # dy/dlogx
    #     splot.scatter(windows[:-1],
    #                   (counts[1:] - counts[:-1]) /
    #                   (numpy.log10(windows[1:]) - numpy.log10(windows[:-1])))
    # dlogy/dlogx
    splot.scatter(windows[:-1],
                  (numpy.log10(counts[1:]) - numpy.log10(counts[:-1])) /
                  (numpy.log10(windows[1:]) - numpy.log10(windows[:-1])))
    splot.set_axis_options(r'height=0.2\textwidth, xmode=log, ymode=normal')
    #     splot.set_axis_options(r'height=0.2\textwidth, xmode=log, ymode=log')

    text = ('%s\nDate: %s\nTotal n events: %d' %
            (group_name, date.isoformat(), n_events))
    plot.set_label(0, 0, text, 'upper left')
    plot.set_xlimits_for_all(min=0.5, max=1e14)
    plot.set_ylimits(0, 0, min=1, max=1e8)
    plot.set_ylabel('Found coincidences')
    plot.set_xlabel(r'Coincidence window [\si{\ns}]')
    plot.show_xticklabels(1, 0)
    plot.show_yticklabels_for_all(None)
    plot.set_yticklabels_position(1, 0, 'right')

    plot.save_as_pdf('plots/coincidences_%s' % group_name)
def boxplot_core_distances_for_mips(table):
    THETA = deg2rad(22.5)
    DTHETA = deg2rad(1.)
    DN = .5

    ENERGY = 1e15
    DENERGY = 2e14

    MAX_R = 80

    r25_list = []
    r50_list = []
    r75_list = []
    x = []
    for N in range(1, 5):
        sel = table.read_where('(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(k_energy - ENERGY) <= DENERGY) & (r <= MAX_R)')
        r = sel[:]['r']
        r25_list.append(scoreatpercentile(r, 25))
        r50_list.append(scoreatpercentile(r, 50))
        r75_list.append(scoreatpercentile(r, 75))
        x.append(N)
        print(len(r))

    sx, sr25, sr50, sr75 = loadtxt(os.path.join(DATADIR, 'DIR-save_for_kascade_boxplot_core_distances_for_mips.txt'))

    fig = figure()

    ax1 = subplot(131)
    fill_between(sx, sr25, sr75, color='0.75')
    plot(sx, sr50, 'o-', color='black', markerfacecolor='none')

    ax2 = subplot(132, sharex=ax1, sharey=ax1)
    fill_between(x, r25_list, r75_list, color='0.75')
    plot(x, r50_list, 'o-', color='black')

    ax3 = subplot(133, sharex=ax1, sharey=ax1)
    plot(x, sr50, 'o-', color='black', markerfacecolor='none')
    plot(x, r50_list, 'o-', color='black')

    ax2.xaxis.set_label_text("Minimum number of particles $\pm %.1f$" % DN)
    ax1.yaxis.set_label_text("Core distance [m]")
    fig.suptitle(r"$\theta = 22.5^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$" % (rad2deg(DTHETA), log10(ENERGY - DENERGY), log10(ENERGY + DENERGY)))

    ax1.xaxis.set_ticks([1, 2, 3, 4])
    fig.subplots_adjust(left=.1, right=.95)

    ylim(ymin=0)
    xlim(.8, 4.2)

    fig.set_size_inches(5, 2.67)
    utils.saveplot()

    graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth')

    graph.shade_region(0, 0, sx, sr25, sr75)
    graph.plot(0, 0, sx, sr50, linestyle=None)
    graph.plot(0, 2, sx, sr50)
    graph.set_label(0, 0, 'simulation')

    graph.shade_region(0, 1, x, r25_list, r75_list)
    graph.plot(0, 1, x, r50_list, linestyle=None, mark='*')
    graph.plot(0, 2, x, r50_list, mark='*')
    graph.set_label(0, 1, 'experiment')

    graph.set_label(0, 2, 'sim + exp')

    graph.set_ylimits(0, 50)
    graph.set_xlabel("Minimum number of particles $\pm %.1f$" % DN)
    graph.set_ylabel("Core distance [\si{\meter}]")
    graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)])
    graph.show_yticklabels(0, 0)

    artist.utils.save_graph(graph, dirname='plots')
def boxplot_arrival_times(table, N):
    THETA = deg2rad(0)
    DTHETA = deg2rad(10.)

    LOGENERGY = 15
    DLOGENERGY = .5

    bin_edges = linspace(0, 80, 5)
    x = []
    t25, t50, t75 = [], [], []
    for low, high in zip(bin_edges[:-1], bin_edges[1:]):
        query = '(min_n134 >= N) & (low <= r) & (r < high) & (abs(reference_theta - THETA) <= DTHETA) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)'
        sel = table.read_where(query)
        t2 = sel[:]['t2']
        t1 = sel[:]['t1']
        ct1 = t1.compress((t1 > -999) & (t2 > -999))
        ct2 = t2.compress((t1 > -999) & (t2 > -999))
        print(len(t1), len(t2), len(ct1), len(ct2))
        t25.append(scoreatpercentile(abs(ct2 - ct1), 25))
        t50.append(scoreatpercentile(abs(ct2 - ct1), 50))
        t75.append(scoreatpercentile(abs(ct2 - ct1), 75))
        x.append((low + high) / 2)

    sx, st25, st50, st75 = loadtxt(os.path.join(DATADIR, 'DIR-boxplot_arrival_times-1.txt'))

    fig = figure()

    ax1 = subplot(131)
    fill_between(sx, st25, st75, color='0.75')
    plot(sx, st50, 'o-', color='black', markerfacecolor='none')

    ax2 = subplot(132, sharex=ax1, sharey=ax1)
    fill_between(x, t25, t75, color='0.75')
    plot(x, t50, 'o-', color='black')

    ax3 = subplot(133, sharex=ax1, sharey=ax1)
    plot(sx, st50, 'o-', color='black', markerfacecolor='none')
    plot(x, t50, 'o-', color='black')

    ax2.xaxis.set_label_text("Core distance [m]")
    ax1.yaxis.set_label_text("Arrival time difference $|t_2 - t_1|$ [ns]")
    fig.suptitle(r"$N_{MIP} \geq %d, \quad \theta = 0^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$" % (N, rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY))

    ylim(ymax=15)
    xlim(xmax=80)
    locator_params(tight=True, nbins=4)

    fig.subplots_adjust(left=.1, right=.95)

    fig.set_size_inches(5, 2.67)
    utils.saveplot(N)

    sx = sx.compress(sx < 80)
    st25 = st25[:len(sx)]
    st50 = st50[:len(sx)]
    st75 = st75[:len(sx)]

    graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth')

    graph.shade_region(0, 0, sx, st25, st75)
    graph.plot(0, 0, sx, st50, linestyle=None)
    graph.plot(0, 2, sx, st50)
    graph.set_label(0, 0, 'simulation', 'upper left')

    graph.shade_region(0, 1, x, t25, t75)
    graph.plot(0, 1, x, t50, linestyle=None, mark='*')
    graph.plot(0, 2, x, t50, mark='*')
    graph.set_label(0, 1, 'experiment', 'upper left')

    graph.set_label(0, 2, 'sim + exp', 'upper left')

    graph.set_ylimits(0, 15)
    graph.set_xlimits(0, 80)
    graph.set_xlabel("Core distance [\si{\meter}]")
    graph.set_ylabel(r"Arrival time difference $|t_2 - t_1|$ [\si{\nano\second}]")
    graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)])
    graph.set_xticklabels_position(0, 1, 'right')
    graph.show_yticklabels(0, 0)

    artist.utils.save_graph(graph, suffix=N, dirname='plots')
示例#5
0
def boxplot_core_distances_for_mips(table):
    THETA = deg2rad(22.5)
    DTHETA = deg2rad(1.)
    DN = .5

    ENERGY = 1e15
    DENERGY = 2e14

    MAX_R = 80

    r25_list = []
    r50_list = []
    r75_list = []
    x = []
    for N in range(1, 5):
        sel = table.readWhere(
            '(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(k_energy - ENERGY) <= DENERGY) & (r <= MAX_R)'
        )
        r = sel[:]['r']
        r25_list.append(scoreatpercentile(r, 25))
        r50_list.append(scoreatpercentile(r, 50))
        r75_list.append(scoreatpercentile(r, 75))
        x.append(N)
        print len(r)

    sx, sr25, sr50, sr75 = loadtxt(
        os.path.join(
            DATADIR,
            'DIR-save_for_kascade_boxplot_core_distances_for_mips.txt'))

    fig = figure()

    ax1 = subplot(131)
    fill_between(sx, sr25, sr75, color='0.75')
    plot(sx, sr50, 'o-', color='black', markerfacecolor='none')

    ax2 = subplot(132, sharex=ax1, sharey=ax1)
    fill_between(x, r25_list, r75_list, color='0.75')
    plot(x, r50_list, 'o-', color='black')

    ax3 = subplot(133, sharex=ax1, sharey=ax1)
    plot(x, sr50, 'o-', color='black', markerfacecolor='none')
    plot(x, r50_list, 'o-', color='black')

    ax2.xaxis.set_label_text("Minimum number of particles $\pm %.1f$" % DN)
    ax1.yaxis.set_label_text("Core distance [m]")
    fig.suptitle(
        r"$\theta = 22.5^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$"
        % (rad2deg(DTHETA), log10(ENERGY - DENERGY), log10(ENERGY + DENERGY)))

    ax1.xaxis.set_ticks([1, 2, 3, 4])
    fig.subplots_adjust(left=.1, right=.95)

    ylim(ymin=0)
    xlim(.8, 4.2)

    fig.set_size_inches(5, 2.67)
    utils.saveplot()

    graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth')

    graph.shade_region(0, 0, sx, sr25, sr75)
    graph.plot(0, 0, sx, sr50, linestyle=None)
    graph.plot(0, 2, sx, sr50)
    graph.set_label(0, 0, 'simulation')

    graph.shade_region(0, 1, x, r25_list, r75_list)
    graph.plot(0, 1, x, r50_list, linestyle=None, mark='*')
    graph.plot(0, 2, x, r50_list, mark='*')
    graph.set_label(0, 1, 'experiment')

    graph.set_label(0, 2, 'sim + exp')

    graph.set_ylimits(0, 50)
    graph.set_xlabel("Minimum number of particles $\pm %.1f$" % DN)
    graph.set_ylabel("Core distance [\si{\meter}]")
    graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)])
    graph.show_yticklabels(0, 0)

    artist.utils.save_graph(graph, dirname='plots')
示例#6
0
def boxplot_arrival_times(table, N):
    THETA = deg2rad(0)
    DTHETA = deg2rad(10.)

    LOGENERGY = 15
    DLOGENERGY = .5

    bin_edges = linspace(0, 80, 5)
    x = []
    t25, t50, t75 = [], [], []
    for low, high in zip(bin_edges[:-1], bin_edges[1:]):
        query = '(min_n134 >= N) & (low <= r) & (r < high) & (abs(reference_theta - THETA) <= DTHETA) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)'
        sel = table.readWhere(query)
        t2 = sel[:]['t2']
        t1 = sel[:]['t1']
        ct1 = t1.compress((t1 > -999) & (t2 > -999))
        ct2 = t2.compress((t1 > -999) & (t2 > -999))
        print len(t1), len(t2), len(ct1), len(ct2)
        t25.append(scoreatpercentile(abs(ct2 - ct1), 25))
        t50.append(scoreatpercentile(abs(ct2 - ct1), 50))
        t75.append(scoreatpercentile(abs(ct2 - ct1), 75))
        x.append((low + high) / 2)

    sx, st25, st50, st75 = loadtxt(
        os.path.join(DATADIR, 'DIR-boxplot_arrival_times-1.txt'))

    fig = figure()

    ax1 = subplot(131)
    fill_between(sx, st25, st75, color='0.75')
    plot(sx, st50, 'o-', color='black', markerfacecolor='none')

    ax2 = subplot(132, sharex=ax1, sharey=ax1)
    fill_between(x, t25, t75, color='0.75')
    plot(x, t50, 'o-', color='black')

    ax3 = subplot(133, sharex=ax1, sharey=ax1)
    plot(sx, st50, 'o-', color='black', markerfacecolor='none')
    plot(x, t50, 'o-', color='black')

    ax2.xaxis.set_label_text("Core distance [m]")
    ax1.yaxis.set_label_text("Arrival time difference $|t_2 - t_1|$ [ns]")
    fig.suptitle(
        r"$N_{MIP} \geq %d, \quad \theta = 0^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$"
        % (N, rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY))

    ylim(ymax=15)
    xlim(xmax=80)
    locator_params(tight=True, nbins=4)

    fig.subplots_adjust(left=.1, right=.95)

    fig.set_size_inches(5, 2.67)
    utils.saveplot(N)

    sx = sx.compress(sx < 80)
    st25 = st25[:len(sx)]
    st50 = st50[:len(sx)]
    st75 = st75[:len(sx)]

    graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth')

    graph.shade_region(0, 0, sx, st25, st75)
    graph.plot(0, 0, sx, st50, linestyle=None)
    graph.plot(0, 2, sx, st50)
    graph.set_label(0, 0, 'simulation', 'upper left')

    graph.shade_region(0, 1, x, t25, t75)
    graph.plot(0, 1, x, t50, linestyle=None, mark='*')
    graph.plot(0, 2, x, t50, mark='*')
    graph.set_label(0, 1, 'experiment', 'upper left')

    graph.set_label(0, 2, 'sim + exp', 'upper left')

    graph.set_ylimits(0, 15)
    graph.set_xlimits(0, 80)
    graph.set_xlabel("Core distance [\si{\meter}]")
    graph.set_ylabel(
        r"Arrival time difference $|t_2 - t_1|$ [\si{\nano\second}]")
    graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)])
    graph.set_xticklabels_position(0, 1, 'right')
    graph.show_yticklabels(0, 0)

    artist.utils.save_graph(graph, suffix=N, dirname='plots')