def main():

    directions = np.genfromtxt('data/discrete-directions.txt',
                               names=['azimuth', 'zenith'])

    plot = PolarPlot(use_radians=True)
    plot.scatter(directions['azimuth'], directions['zenith'],
                 markstyle='mark size=.75pt')

    plot.set_xlabel('Azimuth [rad]')
    plot.set_ylabel('Zenith [rad]')

    plot.save('discrete_directions')
def analyse():
    """Plot results from reconstructions compared to the simulated input"""

    with tables.open_file(DATAPATH, 'r') as data:
        coincidences = data.get_node('/coincidences/coincidences')
        reconstructions = data.get_node(STATION_PATH)
        assert coincidences.nrows == reconstructions.nrows
        zenith_in = coincidences.col('zenith')
        azimuth_in = coincidences.col('azimuth')
        zenith_re = reconstructions.col('zenith')
        azimuth_re = reconstructions.col('azimuth')

    d_angle = angle_between(zenith_in, azimuth_in, zenith_re, azimuth_re)
    print sum(isnan(d_angle))

    plot = Plot()
    counts, bins = histogram(d_angle[invert(isnan(d_angle))], bins=50)
    plot.histogram(counts, bins)
    plot.set_ylimits(min=0)
    plot.set_xlabel(r'Angle between \si{\radian}')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('angle_between')

    plot = Plot()
    counts, bins = histogram(zenith_in, bins=50)
    plot.histogram(counts, bins, linestyle='red')
    counts, bins = histogram(zenith_re, bins=bins)
    plot.histogram(counts, bins)
    plot.set_ylimits(min=0)
    plot.set_xlimits(min=0)
    plot.set_xlabel(r'Zenith \si{\radian}')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('zenith')

    plot = Plot()
    counts, bins = histogram(azimuth_in, bins=50)
    plot.histogram(counts, bins, linestyle='red')
    counts, bins = histogram(azimuth_re, bins=bins)
    plot.histogram(counts, bins)
    plot.set_ylimits(min=0)
    plot.set_xlabel(r'Azimuth \si{\radian}')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('azimuth')

    unique_coordinates = list({(z, a) for z, a in zip(zenith_re, azimuth_re)})
    zenith_uni, azimuth_uni = zip(*unique_coordinates)
    plot = PolarPlot(use_radians=True)
    plot.scatter(array(azimuth_uni),
                 array(zenith_uni),
                 markstyle='mark size=.75pt')
    plot.set_xlabel(r'Azimuth \si{\radian}')
    plot.set_ylabel(r'Zenith \si{\radian}')
    plot.save_as_pdf('polar')
示例#3
0
def plot_results(data):
    plot = PolarPlot(use_radians=True)
    for rec_group, linestyle in [('recs', ''), ('recs_no_offset', 'red')]:
        recs = data.get_node('/coincidences', rec_group)
        azimuth = recs.col('azimuth')
        plot_azimuths(plot, azimuth, linestyle)
    plot.save_as_pdf('azimuths_alt')

    # Using subset of stations
    plot = PolarPlot(use_radians=True)
    for rec_group, linestyle in [('recs_sub_offset', ''), ('recs_sub_no_offset', 'red'), ('recs_sub_offset_alt', 'green')]:
        recs = data.get_node('/coincidences', rec_group)
        azimuth = recs.col('azimuth')
        plot_azimuths(plot, azimuth, linestyle)
    plot.save_as_pdf('azimuths_alt')
def main():
    plot = PolarPlot()

    # Full range histogram
    x = np.random.uniform(0, 360, 10000)
    n, bins = np.histogram(x, bins=np.linspace(0, 360, 181))
    plot.histogram(n, bins)

    # Offset range histogram
    x = np.random.normal(400, 130, 2500)
    n, bins = np.histogram(x, bins=np.linspace(270, 630, 91))
    plot.histogram(n, bins, linestyle='blue')

    # Part range histogram
    x = np.random.uniform(90, 300, 2000)
    n, bins = np.histogram(x, bins=np.linspace(90, 300, 22))
    plot.histogram(n, bins, linestyle='red')

    plot.save('polar_histogram')
示例#5
0
文件: master.py 项目: 153957/topaz
def scatter_n():
    r = 420
    with tables.open_file(RESULT_PATH, 'r') as data:
        cluster = data.root.coincidences._v_attrs.cluster
        coincidences = data.root.coincidences.coincidences
        graph = Plot()
        for n in range(0, len(cluster.stations) + 1):
            c = coincidences.read_where('N == n')
            if len(c) == 0:
                continue
            graph.plot(c['x'],
                       c['y'],
                       mark='*',
                       linestyle=None,
                       markstyle='mark size=.2pt,color=%s' %
                       COLORS[n % len(COLORS)])
            graph1 = Plot()
            graph1.plot(c['x'],
                        c['y'],
                        mark='*',
                        linestyle=None,
                        markstyle='mark size=.2pt')
            plot_cluster(graph1, cluster)
            graph1.set_axis_equal()
            graph1.set_ylimits(-r, r)
            graph1.set_xlimits(-r, r)
            graph1.set_ylabel('y [m]')
            graph1.set_xlabel('x [m]')
            graph1.set_title('Showers that caused triggers in %d stations' % n)
            graph1.save_as_pdf('N_%d' % n)

            graph_azi = PolarPlot(use_radians=True)
            plot_azimuth(graph_azi, c['azimuth'])
            graph_azi.set_label('N = %d' % n)
            graph_azi.save('azi_%d' % n)
            graph_azi.save_as_pdf('azi_%d' % n)

        plot_cluster(graph, cluster)
        graph.set_axis_equal()
        graph.set_ylimits(-r, r)
        graph.set_xlimits(-r, r)
        graph.set_ylabel('y [m]')
        graph.set_xlabel('x [m]')
        graph.set_title('Color indicates the number triggered stations by '
                        'a shower.')
        graph.save_as_pdf('N')
示例#6
0
def reconstruct_for_detectors(station, ids, dirrec):
    graph = PolarPlot(use_radians=True)
    times = generate_discrete_times(station, detector_ids=ids)
    detectors = [station.detectors[id].get_coordinates() for id in ids]
    x, y, z = zip(*detectors)

    theta, phi = itertools.izip(*(dirrec.reconstruct_common((0, ) + t, x, y, z)
                                  for t in times))

    thetaa = [t for t in theta if not np.isnan(t)]
    phia = [p for p in phi if not np.isnan(p)]
    graph.scatter(phia, thetaa, markstyle='mark size=.5pt')

    graph.set_ylimits(0, np.pi / 2)
    graph.set_yticks([0, np.pi / 6, np.pi / 3, np.pi / 2])
    graph.set_ytick_labels([
        r'$0$', r'$\frac{1}{6}\pi$', r'$\frac{2}{6}\pi$', r'$\frac{1}{2}\pi$'
    ])
    graph.set_ylabel('Zenith [rad]')
    graph.set_xlabel('Azimuth [rad]')
    graph.save_as_pdf('discrete_directions_%d_%s' %
                      (station.number, '_'.join(str(i) for i in ids)))
示例#7
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)
示例#8
0
def plot_discrete(angles):
    theta, phi = zip(*angles)
    graph = PolarPlot(use_radians=True)
    graph.scatter(phi, theta, markstyle='mark size=.5pt')

    graph.set_ylimits(0, np.pi / 2)
    graph.set_yticks([0, np.pi / 6, np.pi / 3, np.pi / 2])
    graph.set_ytick_labels([
        r'$0$',
        r'$\frac{1}{6}\pi$',
        r'$\frac{2}{6}\pi$',
        r'$\frac{1}{2}\pi$',
    ])
    graph.set_ylabel('Zenith [rad]')
    graph.set_xlabel('Azimuth [rad]')
    graph.save_as_pdf('discrete_directions')
def reconstruct_for_detectors(ids):
    graph = PolarPlot(use_radians=True)
    times = generate_discrete_times(station, detector_ids=ids)
    detectors = [station.detectors[id].get_coordinates() for id in ids]
    x, y, z = zip(*detectors)

    theta, phi = itertools.izip(*(dirrec.reconstruct_common((0,) + t, x, y, z)
                                  for t in times))

    thetaa = [t for t in theta if not np.isnan(t)]
    phia = [p for p in phi if not np.isnan(p)]
    graph.scatter(phia, thetaa, markstyle='mark size=.5pt', mark='*')

    # Add curved lines where detector 0 and 2 have fixed but different times
    # and a straight line where detector 0 and 2 have equal times
    times = np.arange(-60, 60, TIME_RESOLUTION)

    for dt in (-2.5, 0, 2.5, 7.5, 15, 22.5, 30, 45):
        theta, phi = itertools.izip(*(dirrec.reconstruct_common((t, 0, dt), x, y, z)
                                      for t in times))
        thetaa = [t for t in theta if not np.isnan(t)]
        phia = [p for p in phi if not np.isnan(p)]
        graph.plot(phia, thetaa, mark=None, linestyle='solid,' + COLORS[ids[0]])
        theta, phi = itertools.izip(*(dirrec.reconstruct_common((0, t, dt), x, y, z)
                                      for t in times))
        thetaa = [t for t in theta if not np.isnan(t)]
        phia = [p for p in phi if not np.isnan(p)]
        graph.plot(phia, thetaa, mark=None, linestyle='solid,' + COLORS[ids[1]])
        theta, phi = itertools.izip(*(dirrec.reconstruct_common((0, dt, t), x, y, z)
                                      for t in times))
        thetaa = [t for t in theta if not np.isnan(t)]
        phia = [p for p in phi if not np.isnan(p)]
        graph.plot(phia, thetaa, mark=None, linestyle='solid,' + COLORS[ids[2]])

    graph.set_ylimits(0, np.pi / 2)
    graph.set_yticks([0, np.pi / 6, np.pi / 3, np.pi / 2])
    graph.set_ytick_labels([r'$0$', r'$\frac{1}{6}\pi$',
                            r'$\frac{2}{6}\pi$', r'$\frac{1}{2}\pi$', ])
    graph.set_ylabel('Zenith [rad]')
    graph.set_xlabel('Azimuth [rad]')
    graph.save_as_pdf('discrete_directions_%s' % '_'.join(str(i) for i in ids))
示例#10
0
def plot_azimuths(azimuth, name=''):

    plot = PolarPlot(use_radians=True)
    n, bins = histogram(azimuth, bins=linspace(-pi, pi, 21))
    plot.histogram(n, bins)
    plot.set_title('Azimuth distribution')
    plot.set_ylimits(min=0)
    plot.set_xlabel('Azimuth [rad]')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('azimuths_%s' % name)