Example #1
0
def angles_between_discrete(angles):
    theta, phi = zip(*angles)
    distances = angle_between(0., 0., np.array(theta), np.array(phi))
    counts, bins = np.histogram(distances, bins=np.linspace(0, np.pi, 721))
    plotd = Plot()
    plotd.histogram(counts, np.degrees(bins))
    # 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_Zenith_discrete')

    plotd = Plot()
    distances = []
    for t, p in angles:
        distances.extend(angle_between(t, p, np.array(theta), np.array(phi)))
    counts, bins = np.histogram(distances, bins=np.linspace(0, np.pi, 361))
    plotd.histogram(counts, np.degrees(bins))
    # 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_Zenith_discrete_all')
Example #2
0
    def test_azimuths(self):
        """Both directions at the horizon"""

        zenith = pi / 2
        azimuth = random.uniform(-pi, pi, 10000)
        angle = utils.angle_between(zenith, azimuth, zenith, 0)
        self.assertTrue(all(abs(angle - abs(azimuth)) < 1e-10))
        angle = utils.angle_between(zenith, 0, zenith, azimuth)
        self.assertTrue(all(abs(angle - abs(azimuth)) < 1e-10))
Example #3
0
    def test_zeniths(self):
        """One of the directions is the Zenith"""

        n = 10000
        zenith = random.uniform(0, pi / 2, n)
        azimuth1 = random.uniform(-pi, pi, n)
        azimuth2 = random.uniform(-pi, pi, n)
        angle = utils.angle_between(zenith, azimuth1, 0, azimuth2)
        self.assertTrue(all(abs(angle - zenith) < 1e-15))
        angle = utils.angle_between(0, azimuth1, zenith, azimuth2)
        self.assertTrue(all(abs(angle - zenith) < 1e-15))
Example #4
0
    def test_no_zenith(self):
        """Azimuths are irrelevant when from the Zenith"""

        azimuth1 = random.uniform(-pi, pi, 10000)
        azimuth2 = random.uniform(-pi, pi, 10000)
        angle = utils.angle_between(0, azimuth1, 0, azimuth2)
        self.assertTrue(all(angle == 0))
Example #5
0
    def test_single_values(self):
        """Other tests use arrays, check if single values also work"""

        zenith = random.uniform(0, pi / 2)
        azimuth = random.uniform(-pi, pi)
        angle = utils.angle_between(zenith, azimuth, zenith, azimuth)
        self.assertTrue(angle == 0)
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')
Example #7
0
def plot_reconstructions():
    print 'Plotting . . .'
    plot = Plot()
    bins = linspace(0, 90, 30)  # Degrees
    plot.set_ylimits(min=0)
    plot.set_xlimits(0, 90)
    plot.set_ylabel('counts')
    plot.set_xlabel(r'Angle between [\si{\degree}]')
    colors = ['black', 'red', 'green', 'blue']

    for i, c_group in enumerate([
            '/coincidences', '/coincidences_original',
            '/coincidences_501_original', '/coincidences_510_original'
    ]):
        cq = CoincidenceQuery(DATA, coincidence_group=c_group)
        coincidences = cq.all([501, 510], iterator=True)
        reconstructions = [cq._get_reconstructions(c) for c in coincidences]
        cq.finish()

        azi501 = []
        zen501 = []
        azi510 = []
        zen510 = []

        for rec1, rec2 in reconstructions:
            if rec1[0] == 501:
                azi501.append(rec1[1]['azimuth'])
                zen501.append(rec1[1]['zenith'])
                azi510.append(rec2[1]['azimuth'])
                zen510.append(rec2[1]['zenith'])
            else:
                azi501.append(rec2[1]['azimuth'])
                zen501.append(rec2[1]['zenith'])
                azi510.append(rec1[1]['azimuth'])
                zen510.append(rec1[1]['zenith'])

        azi501 = array(azi501)
        zen501 = array(zen501)
        azi510 = array(azi510)
        zen510 = array(zen510)

        # Compare angles between old and new
        d_angle = angle_between(zen501, azi501, zen510, azi510)
        print c_group, r'67\%% within %.1f degrees' % degrees(
            percentile(d_angle[isfinite(d_angle)], 67))
        plot.histogram(*histogram(degrees(d_angle), bins=bins),
                       linestyle=colors[i])
    plot.save_as_pdf('angle_between_501_510')
Example #8
0
def plot_results(data):
    rec_paths = ['recs_flat', 'recs_curved', 'recs_xy']
    linestyles = ['solid', 'dotted', 'dashed']
    plot = Plot()
    for i, rec_path in enumerate(rec_paths):
        recs = data.get_node('/coincidences/%s' % rec_path)
        angles = angle_between(recs.col('zenith'), recs.col('azimuth'),
                               recs.col('reference_zenith'),
                               recs.col('reference_azimuth'))
        dangles = np.degrees(angles)
        counts, bins = np.histogram(dangles, bins=np.arange(0, 25, .5))
        plot.histogram(counts, bins + (i / 10.), linestyle=linestyles[i])
    plot.set_xlimits(0, 25)
    plot.set_ylimits(0)
    plot.set_xlabel(r'Angle between [\si{\degree}]')
    plot.save_as_pdf('angle_between')
Example #9
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')
Example #10
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)
Example #11
0
def analyse_reconstructions(data):
    cq = CoincidenceQuery(data)
    c_ids = data.root.coincidences.coincidences.read_where('s501', field='id')
    c_recs = cq.reconstructions.read_coordinates(c_ids)

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

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

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

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

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

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

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

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

        distances = angle_between(zens.compress(filter), azis.compress(filter),
                                  zenc.compress(filter), azic.compress(filter))
        counts, bins = np.histogram(distances, bins=np.linspace(0, np.pi, 91))
        plotd = Plot()
        plotd.histogram(counts, np.degrees(bins))
        sigma = np.degrees(np.percentile(distances[np.isfinite(distances)],
                                         67))
        plotd.set_label(r'67\%% within \SI{%.1f}{\degree}' % sigma)
        # plotd.set_title('Distance between reconstructed angles for station and cluster')
        plotd.set_xlabel('Angle between reconstructions [\si{\degree}]')
        plotd.set_ylabel('Counts')
        plotd.set_xlimits(min=0, max=90)
        plotd.set_ylimits(min=0)
        plotd.save_as_pdf('angle_between_501_spa_minn%d' % minn)
Example #12
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)
Example #13
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()
def oldvsnew_diagram():
    """
    Visual accuracy comparisons of old and new transformations.
    Compares the correlations between the transformations:
    equatorial_to_horizontal and equatorial_to_zenith_azimuth_astropy
    horizontal_to_equatorial and horizontal_to_zenith_azimuth_astropy
    Makes a histogram of the error differences
    between these two functions as well.
    The errors seem to be in the order of 1000 arcsec
    :return: None

    Ethan van Woerkom is responsible for the benchmarking functions;
    refer to him for when something is unclear
    """
    # make random frames, in correct angle range and from utc time 2000-2020
    frames = []
    # boxes for the four different transformation results
    etoha = []
    etoh = []
    htoe = []
    htoea = []
    straight = lambda x : x # straight trendline function

    # Create the data sets for eq to az
    for i in range(100):
        frames.append((r.uniform(-90, 90),
                       r.uniform(-180,180),
                       r.randint(946684800,1577836800),
                       r.uniform(0, 2 * np.pi),
                       r.uniform(-0.5 * np.pi, 0.5 * np.pi)))
    for i in frames:
        etoha.append(celestial.equatorial_to_zenithazimuth_astropy(i[0], i[1], i[2], [(i[3], i[4])])[0])
        etoh.append(celestial.equatorial_to_zenithazimuth(i[0], i[1], clock.utc_to_gps(i[2]), i[3], i[4]))
    # Data sets for hor to eq
    for i in frames:
        htoe.append(celestial.horizontal_to_equatorial(i[0],
        clock.utc_to_lst(datetime.datetime.utcfromtimestamp(i[2]), i[1]), i[4], i[3]))
        htoea.extend(celestial.horizontal_to_equatorial_astropy(i[0], i[1], i[2], [(i[3], i[4])]))

    # Make figs eq -> zenaz
    plt.figure(1)
    plt.suptitle('Zen/Az correlation in rads (equatorial_to_zenithazimuth)')

    zenrange = [0, np.pi]
    plt.subplot(211)
    plt.title('Zenith')
    plt.axis(zenrange*2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')

    # Make figure and add 1:1 trendline

    plt.plot([co[0] for co in etoha], [co[0] for co in etoh], 'r.', zenrange, straight(zenrange), '-')

    plt.subplot(212)
    plt.title('Azimuth')
    azrange = [-np.pi, np.pi]
    plt.axis(azrange*2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in etoha], [co[1] for co in etoh], 'b.', azrange, straight(azrange), '-')
    plt.tight_layout() # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(2)
    # Take diff. and convert to arcsec
    nieuw = (np.array(etoh) - np.array(etoha))
    nieuw *= 360 * 3600 / (2 * np.pi)

    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Zenith Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(3)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Azimuth Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(7)
    nieuw = np.array([angle_between(etoh[i][0], etoh[i][1], etoha[i][0], etoha[i][1])
                      for i in range(len(etoh))])
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist(nieuw, bins=20)
    plt.title('ZEN+AZ Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make figs hor - > eq

    plt.figure(4)
    plt.suptitle('RA/DEC  correlation in rads (horizontal_to_equatorial)')
    altrange = [-0.5 * np.pi, 0.5 * np.pi]
    plt.subplot(211)
    plt.title('Declination')
    plt.axis(altrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in htoea], [co[1] for co in htoe], 'r.', altrange, straight(altrange), '-')

    plt.subplot(212)
    plt.title('Right Ascension')
    azrange = [0, 2 * np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[0] for co in htoea], [co[0] for co in htoe], 'b.', azrange, straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(5)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Declination Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(6)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Right Ascension Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(8)
    nieuw = np.array([angle_between_horizontal(htoe[i][0], htoe[i][1], htoea[i][0], htoea[i][1])
                      for i in range(len(htoe))])
    # Take diff. and convert to arcsec
    nieuw /= 2 / np.pi * 360 * 3600
    plt.hist(nieuw, bins=20)
    plt.title('RA+DEC Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.show()
    return
def oldvsnew_diagram():
    """
    Visual accuracy comparisons of old and new transformations.
    Compares the correlations between the transformations:
    equatorial_to_horizontal and equatorial_to_zenith_azimuth_astropy
    horizontal_to_equatorial and horizontal_to_zenith_azimuth_astropy
    Makes a histogram of the error differences
    between these two functions as well.
    The errors seem to be in the order of 1000 arcsec
    :return: None

    Ethan van Woerkom is responsible for the benchmarking functions;
    refer to him for when something is unclear
    """
    # make random frames, in correct angle range and from utc time 2000-2020
    frames = []
    # boxes for the four different transformation results
    etoha = []
    etoh = []
    htoe = []
    htoea = []
    straight = lambda x: x  # straight trendline function

    # Create the data sets for eq to az
    for i in range(100):
        frames.append(
            (r.uniform(-90,
                       90), r.uniform(-180,
                                      180), r.randint(946684800, 1577836800),
             r.uniform(0, 2 * np.pi), r.uniform(-0.5 * np.pi, 0.5 * np.pi)))
    for i in frames:
        etoha.append(
            celestial.equatorial_to_zenithazimuth_astropy(
                i[0], i[1], i[2], [(i[3], i[4])])[0])
        etoh.append(
            celestial.equatorial_to_zenithazimuth(i[0], i[1],
                                                  clock.utc_to_gps(i[2]), i[3],
                                                  i[4]))
    # Data sets for hor to eq
    for i in frames:
        htoe.append(
            celestial.horizontal_to_equatorial(
                i[0],
                clock.utc_to_lst(datetime.datetime.utcfromtimestamp(i[2]),
                                 i[1]), i[4], i[3]))
        htoea.extend(
            celestial.horizontal_to_equatorial_astropy(i[0], i[1], i[2],
                                                       [(i[3], i[4])]))

    # Make figs eq -> zenaz
    plt.figure(1)
    plt.suptitle('Zen/Az correlation in rads (equatorial_to_zenithazimuth)')

    zenrange = [0, np.pi]
    plt.subplot(211)
    plt.title('Zenith')
    plt.axis(zenrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')

    # Make figure and add 1:1 trendline

    plt.plot([co[0] for co in etoha], [co[0] for co in etoh], 'r.', zenrange,
             straight(zenrange), '-')

    plt.subplot(212)
    plt.title('Azimuth')
    azrange = [-np.pi, np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in etoha], [co[1] for co in etoh], 'b.', azrange,
             straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(2)
    # Take diff. and convert to arcsec
    nieuw = (np.array(etoh) - np.array(etoha))
    nieuw *= 360 * 3600 / (2 * np.pi)

    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Zenith Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(3)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Azimuth Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(7)
    nieuw = np.array([
        angle_between(etoh[i][0], etoh[i][1], etoha[i][0], etoha[i][1])
        for i in range(len(etoh))
    ])
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist(nieuw, bins=20)
    plt.title('ZEN+AZ Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make figs hor - > eq

    plt.figure(4)
    plt.suptitle('RA/DEC  correlation in rads (horizontal_to_equatorial)')
    altrange = [-0.5 * np.pi, 0.5 * np.pi]
    plt.subplot(211)
    plt.title('Declination')
    plt.axis(altrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in htoea], [co[1] for co in htoe], 'r.', altrange,
             straight(altrange), '-')

    plt.subplot(212)
    plt.title('Right Ascension')
    azrange = [0, 2 * np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[0] for co in htoea], [co[0] for co in htoe], 'b.', azrange,
             straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(5)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Declination Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(6)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Right Ascension Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(8)
    nieuw = np.array([
        angle_between_horizontal(htoe[i][0], htoe[i][1], htoea[i][0],
                                 htoea[i][1]) for i in range(len(htoe))
    ])
    # Take diff. and convert to arcsec
    nieuw = nieuw / 2 / np.pi * 360 * 3600
    plt.hist(nieuw, bins=20)
    plt.title('RA+DEC Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.show()
    return
Example #16
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')
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)