Exemplo n.º 1
0
def plot_coincidence_v_interval_rate(data):
    """Plot results

    :param distances: dictionary with occuring distances for different
                      combinations of number of detectors.
    :param coincidence_rates: dictionary of occuring coincidence rates for
                              different combinations of number of detectors.
    :param rate_errors: errors on the coincidence rates.

    """
    (distances, coincidence_rates, interval_rates, distance_errors,
     rate_errors, pairs) = data
    markers = {4: 'o', 6: 'triangle', 8: 'square'}
    colors = {4: 'red', 6: 'black!50!green', 8: 'black!20!blue'}
    plot = Plot('loglog')

    plot.plot([1e-7, 1e-1], [1e-7, 1e-1], mark=None)
    for n in distances.keys():
        plot.scatter(interval_rates[n],
                     coincidence_rates[n],
                     yerr=rate_errors[n],
                     mark=markers[n],
                     markstyle='%s, thin, mark size=.75pt' % colors[n])

    plot.set_xlabel(r'Rate based on coincidence intervals [\si{\hertz}]')
    plot.set_ylabel(r'Rate based on coincidences and exposure [\si{\hertz}]')
    plot.set_axis_options('log origin y=infty')
    plot.set_xlimits(min=1e-7, max=1e-1)
    plot.set_ylimits(min=1e-7, max=1e-1)
    plot.save_as_pdf('interval_v_coincidence_rate')
Exemplo n.º 2
0
def main(ts, ns):
    station = Station(501)
    traces = station.event_trace(ts, ns, True)

    dr = DataReduction()
    reduced_traces, o = dr.reduce_traces(array(traces).T, return_offset=True)
    reduced_traces = reduced_traces.T
    plot = Plot()

    t = arange(len(traces[0])) * 2.5
    for i, trace in enumerate(traces):
        plot.plot(t, trace, linestyle='%s, thin' % COLORS[i], mark=None)
    plot.draw_vertical_line(o * 2.5, 'gray')
    plot.draw_vertical_line((o + len(reduced_traces[0])) * 2.5, 'gray')

    plot.set_axis_options('line join=round')
    plot.set_xlabel(r'Event time [\si{\ns}]')
    plot.set_ylabel(r'Signal strength [ADCcounts]')
    plot.set_xlimits(t[0], t[-1])

    plot.save_as_pdf('raw_traces_%d_%d' % (ts, ns))

    t = arange(o, o + len(reduced_traces[0])) * 2.5
    for i, trace in enumerate(reduced_traces):
        plot.plot(t, trace, linestyle='%s, thin' % COLORS[i], mark=None)
    plot.set_axis_options('line join=round')
    plot.set_xlabel(r'Event time [\si{\ns}]')
    plot.set_ylabel(r'Signal strength [ADCcounts]')
    plot.set_xlimits(t[0], t[-1])

    plot.save_as_pdf('reduced_traces_%d_%d' % (ts, ns))
Exemplo n.º 3
0
def plot_coincidence_rate_distance(data, sim_data):
    """Plot results

    :param distances: dictionary with occuring distances for different
                      combinations of number of detectors.
    :param coincidence_rates: dictionary of occuring coincidence rates for
                              different combinations of number of detectors.
    :param rate_errors: errors on the coincidence rates.

    """
    (distances, coincidence_rates, interval_rates, distance_errors,
     rate_errors, pairs) = data
    sim_distances, sim_energies, sim_areas = sim_data
    markers = {4: 'o', 6: 'triangle', 8: 'square'}
    colors = {4: 'red', 6: 'black!50!green', 8: 'black!20!blue'}

    coincidence_window = 10e-6  # seconds
    freq_2 = 0.3
    freq_4 = 0.6
    background = {
        4: 2 * freq_2 * freq_2 * coincidence_window,
        6: 2 * freq_2 * freq_4 * coincidence_window,
        8: 2 * freq_4 * freq_4 * coincidence_window
    }

    for rates, name in [(coincidence_rates, 'coincidence'),
                        (interval_rates, 'interval')]:
        plot = Plot('loglog')
        for n in distances.keys():
            plot.draw_horizontal_line(background[n], 'dashed,' + colors[n])


#         for n in distances.keys():
        for n in [4, 8]:
            expected_rates = expected_rate(distances[n],
                                           rates[n],
                                           background[n],
                                           sim_distances,
                                           sim_energies,
                                           sim_areas[n],
                                           n=n)
            plot.plot(sim_distances,
                      expected_rates,
                      linestyle=colors[n],
                      mark=None,
                      markstyle='mark size=0.5pt')

        for n in distances.keys():
            plot.scatter(distances[n],
                         rates[n],
                         xerr=distance_errors[n],
                         yerr=rate_errors[n],
                         mark=markers[n],
                         markstyle='%s, mark size=.75pt' % colors[n])
        plot.set_xlabel(r'Distance between stations [\si{\meter}]')
        plot.set_ylabel(r'%s rate [\si{\hertz}]' % name.title())
        plot.set_axis_options('log origin y=infty')
        plot.set_xlimits(min=1, max=20e3)
        plot.set_ylimits(min=1e-7, max=5e-1)
        plot.save_as_pdf('distance_v_%s_rate' % name)
Exemplo n.º 4
0
def make_logo():
    size = '.02\linewidth'
    x = arange(0, 2*pi, .01)
    y = sin(x)
    plot = Plot(width=size, height=size)
    plot.set_ylimits(-1.3, 1.3)
    plot.set_yticks([-1, 0, 1])
    plot.set_ytick_labels(['', '', ''])
    plot.set_xticks([0, pi, 2*pi])
    plot.set_xtick_labels(['', '', ''])
    plot.plot(x, y, mark=None, linestyle='thick')
    plot.set_axis_options("axis line style=thick, major tick length=.04cm")
    plot.save_as_pdf('logo')
Exemplo n.º 5
0
def plot_traces(traces, label='', raw=False):
    """Plot traces

    Does not take different mV/ADC for HiSPARC II-III into account!

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

    """
    colors = ['black', 'red', 'black!40!green', 'blue']
    plot = Plot(width=r'.6\textwidth')
    times = arange(0, len(traces[0]) * 2.5, 2.5)
    for i, trace in enumerate(traces):
        if not raw:
            if max(trace) * 0.57 < 500:
                use_milli = True
                trace = [t * -0.57 for t in trace]
            else:
                use_milli = False
                trace = [t * -0.57 / 1e3 for t in trace]
        plot.plot(times, trace, linestyle='%s, thin' % colors[i], mark=None)
    if len(traces[0]) == 2400 and raw:
        plot.add_pin_at_xy(500,
                           10,
                           'pre-trigger',
                           location='below',
                           use_arrow=False)
        plot.add_pin_at_xy(1750,
                           10,
                           'trigger',
                           location='below',
                           use_arrow=False)
        plot.add_pin_at_xy(4250,
                           10,
                           'post-trigger',
                           location='below',
                           use_arrow=False)
        plot.draw_vertical_line(1000, 'gray')
        plot.draw_vertical_line(2500, 'gray')
    if raw:
        plot.set_ylabel(r'Signal strength [ADCcounts]')
    elif use_milli:
        plot.set_ylabel(r'Signal strength [\si{\milli\volt}]')
    else:
        plot.set_ylabel(r'Signal strength [\si{\volt}]')
    plot.set_xlabel(r'Event time [\si{\ns}]')
    plot.set_xlimits(0, times[-1])
    plot.set_axis_options('line join=round')
    plot.save_as_pdf('trace_' + label)
Exemplo n.º 6
0
def plot_delta_time(ids, **kwargs):
    """ Plot delta versus the timestamps

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

    # Begin Figure
    plot = Plot()
    for index, id in enumerate(ids):
        ext_timestamps, deltas = get(id)
        # daystamps = (np.array(ext_timestamps) - min(ext_timestamps)) / 864e11
        daystamps = (np.array(ext_timestamps) -
                     min(ext_timestamps)) / 864e11 * 24 * 60
        end = min(len(daystamps), 6000)
        skip = 3
        plot.plot(daystamps[:end:skip],
                  deltas[:end:skip],
                  mark=None,
                  linestyle='very thin')

    if kwargs.keys():
        plot.set_title('Tijdtest delta time' + kwargs[kwargs.keys()[0]])
    # plot.set_xlabel(r'Time in test [days]')
    plot.set_xlabel(r'Time in test [minutes]')
    plot.set_ylabel(r'$\Delta$ t (swap - reference) [\si{\ns}]')
    plot.set_xlimits(0, daystamps[:end][-1])
    plot.set_ylimits(-50, 50)
    # plot.set_ylimits(-175, 175)

    plot.set_axis_options('line join=round')

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

    print 'tt_analyse: Plotted delta vs time'
Exemplo n.º 7
0
def stopover(offsets):
    """Compare direct to via offsets for stations far appart

    :param offsets: Dictionary of dictionaries with offset functions.

    """
    aoffsets = get_aligned_offsets(offsets, START, STOP, STEP)
    timestamps = range(START, STOP, STEP)

    stations = offsets.keys()
    for from_station, to_station in combinations(stations, 2):
        plot = Plot()
        all_offs = []

        for i, via_station in enumerate(stations):
            if via_station in [from_station, to_station]:
                continue
            offs = (aoffsets[from_station][via_station] +
                    aoffsets[via_station][to_station])

            all_offs.append(offs)

            plot.plot(timestamps,
                      offs,
                      linestyle='very thin, black!%d' % (i * 5 + 30),
                      mark=None)

        offs = aoffsets[from_station][to_station]
        plot.plot(timestamps, offs, linestyle='red', mark=None)
        # all_offs.append(offs)

        mean_offs = nanmean(all_offs, axis=0)
        plot.plot(timestamps, mean_offs, linestyle='blue', mark=None)

        plot.set_xlimits(START, STOP)
        plot.set_ylimits(-100, 100)
        plot.set_ylabel(r'Station offset residual [\si{\ns}]')
        plot.set_xlabel('Timestamp')
        plot.set_axis_options('line join=round')
        plot.save_as_pdf('plots/stop_over_%d_%d' % (from_station, to_station))
Exemplo n.º 8
0
def main():
    x = np.arange(10)
    y = (x / 2.0) - 3.0
    colors = ["black", "red", "blue", "yellow", "purple"]
    plot = Plot()

    for i in range(5):
        plot.plot(x, y - i, mark="", linestyle=colors[i])

    plot.set_axis_options(
        "yticklabel pos=right,\n"
        "grid=major,\n"
        "legend entries={$a$,[red]$b$,[green]$c$,$d$,$a^2$},\n"
        "legend pos=north west"
    )

    plot.set_xlabel("Something important")
    plot.set_ylabel("A related thing")
    plot.save("any_option")

    x = np.linspace(0.6 * np.pi, 10 * np.pi, 150)
    y = np.sin(x) / x
    plot = MultiPlot(1, 2, width=r".4\linewidth", height=r".25\linewidth")

    subplot = plot.get_subplot_at(0, 0)
    subplot.plot(x, y, mark=None)

    subplot = plot.get_subplot_at(0, 1)
    subplot.plot(x, y, mark=None)

    plot.show_xticklabels_for_all([(0, 0), (0, 1)])
    plot.show_yticklabels(0, 1)
    plot.set_axis_options(0, 1, "yticklabel pos=right, grid=major")

    plot.set_axis_options_for_all(None, r"enlargelimits=false")

    plot.set_xlabel("Something important")
    plot.set_ylabel("A related thing")
    plot.save("multi_any_option")
Exemplo n.º 9
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')
Exemplo n.º 10
0
def plot_traces(traces1, traces2, overlap=0, label=''):
    """Plot traces

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

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

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

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

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

    plot.set_ylabel(r'Signal strength [ADCcounts]')
    plot.set_xlabel(r'Event time [\si{\ns}]')
    plot.set_ylimits(0, 500)
    plot.set_xlimits(0, times2[-1])
    plot.set_axis_options('line join=round')
    plot.save_as_pdf('trace_' + label)
Exemplo n.º 11
0
def plot_active_stations(timestamps, stations, aligned_data, data, i):

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

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

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

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

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

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

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