Exemple #1
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))
Exemple #2
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 #3
0
def plot_raw(raw_traces):
    length = 2.5 * len(raw_traces[0])
    plot = Plot()
    max_signal = max(chain.from_iterable(raw_traces))
    plot.add_pin_at_xy(500,
                       max_signal,
                       'pre-trigger',
                       location='above',
                       use_arrow=False)
    plot.draw_vertical_line(1000, 'gray')
    plot.add_pin_at_xy(1750,
                       max_signal,
                       'trigger',
                       location='above',
                       use_arrow=False)
    plot.draw_vertical_line(2500, 'gray')
    plot.add_pin_at_xy(4250,
                       max_signal,
                       'post-trigger',
                       location='above',
                       use_arrow=False)

    for i, raw_trace in enumerate(raw_traces):
        plot.plot(arange(0, length, 2.5),
                  raw_trace,
                  mark=None,
                  linestyle=COLORS[i])

    plot.set_ylimits(min=0)
    plot.set_xlimits(min=0, max=length)
    plot.set_ylabel(r'Signal strength [ADC counts]')
    plot.set_xlabel(r'Sample [\si{\nano\second}]')
    plot.save_as_pdf('raw')
Exemple #4
0
def plot_interaction_altitude_distribution(cq):
    # altitudes = cq.sims.col('first_interaction_altitude') / 1e3
    altitudes = cq.simulations(energy=15,
                               zenith=22.5)['first_interaction_altitude'] / 1e3
    bins = arange(0, 100, 2)
    counts, bins = histogram(altitudes, bins, density=True)
    plot = Plot()
    plot.histogram(counts, bins)
    plot.draw_vertical_line(median(altitudes), linestyle='red')
    plot.set_xlabel(r'First interaction altitude [m]')
    plot.set_ylabel(r'Counts')
    plot.save_as_pdf('plots/interaction_altitude_distribution')
Exemple #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)
Exemple #6
0
def plot_coincidence_intervals(coincidences):
    plot = Plot(axis='semilogx')
    bins = logspace(7, 15, 150)
    minn, maxn = (2, 10)
    for n in range(minn, maxn + 1):
        dt = coincidence_interval(coincidences, n)
        counts, bins = histogram(dt, bins=bins)
        # The counts are multiplied by 3 ** n to make them more similar in size
        # Difference are cause by energy spectrum, station uptime and positions
        greyness = r'black!%d' % (n * 100 / maxn)
        plot.histogram(counts * (3**n), bins, linestyle=greyness)
        plot.draw_vertical_line(bins[counts.argmax()], linestyle=greyness)
    plot.set_xlabel(r'Time between consecutive coincidences')
    plot.set_ylabel(r'Counts')
    plot.set_ylimits(min=0)
    plot.set_xlimits(min=bins[0], max=bins[-1])
    plot.save_as_pdf('coincidence_intervals_501')
Exemple #7
0
 def plot_contribution_station(self, n, ref_n):
     plot = Plot('semilogy')
     colors = [
         'red', 'blue', 'green', 'purple', 'gray', 'brown', 'cyan',
         'magenta', 'orange', 'teal'
     ]
     padding = 0.25
     bins = linspace(0, 20, 150)
     plot.histogram(*histogram(n, bins=bins))
     plot.draw_vertical_line(1)
     for j, density in enumerate(range(1, 8) + [15] + [20]):
         n_slice = n.compress(abs(ref_n - density) < padding)
         counts, bins = histogram(n_slice, bins=bins)
         plot.histogram(counts,
                        bins + (j / 100.),
                        linestyle=colors[j % len(colors)])
     plot.set_ylimits(min=0.9, max=1e5)
     plot.set_xlimits(min=bins[0], max=bins[-1])
     plot.set_xlabel(r'HiSPARC detected density [\si{\per\meter\squared}]')
     plot.set_ylabel(r'Counts')
     return plot
Exemple #8
0
def determine_detector_timing_offsets(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()
    ids = range(1, 5)
    reference = 2
    for j in [1, 3, 4]:
        if j == reference:
            continue
        tref = events.col('t%d' % reference)
        tj = events.col('t%d' % j)
        dt = (tj - tref).compress((tref >= 0) & (tj >= 0))
        y, bins = histogram(dt, bins=bins)
        c = col.next()
        graph.histogram(y, bins, linestyle='%s' % c)
        x = (bins[:-1] + bins[1:]) / 2
        try:
            popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 10.))
            graph.draw_vertical_line(popt[1], linestyle='%s' % c)
            print '%d-%d: %f (%f)' % (j, reference, popt[1], popt[2])
        except (IndexError, RuntimeError):
            print '%d-%d: failed' % (j, reference)
    graph.set_title('Time difference, station %d' % (s))
    graph.set_xlimits(-100, 100)
    graph.set_ylimits(min=0)
    graph.set_xlabel('$\Delta t$')
    graph.set_ylabel('Counts')
    graph.save_as_pdf('detector_offsets_%s' % s)
Exemple #9
0
def plot_times():
    plot = Plot('semilogx')
    data = read_times()
    walltimes = data['walltime'] / 60. / 60.  # To hours
    print 'Total time: %d years.' % (sum(walltimes) / 24. / 365.)
    print 'Longest job: %d hours.' % max(walltimes)
    print 'Shortest job: %d seconds.' % (min(walltimes) * 60. * 60.)
    counts, bins = histogram(log10(walltimes), bins=300)
    plot.histogram(counts, 10**bins, linestyle='fill=black')
    plot.add_pin_at_xy(4,
                       max(counts),
                       'short',
                       location='above left',
                       use_arrow=False)
    plot.draw_vertical_line(4, 'gray')
    plot.add_pin_at_xy(24,
                       max(counts),
                       'generic',
                       location='above left',
                       use_arrow=False)
    plot.draw_vertical_line(24, 'gray')
    plot.add_pin_at_xy(96,
                       max(counts),
                       'long',
                       location='above left',
                       use_arrow=False)
    plot.draw_vertical_line(96, 'gray')
    plot.add_pin_at_xy(2000,
                       max(counts),
                       'extra-long',
                       location='above left',
                       use_arrow=False)
    plot.draw_vertical_line(2000, 'gray')
    plot.set_ylabel(r'Count')
    plot.set_xlabel(r'Walltime [\si{\hour}]')
    plot.set_ylimits(min=0)
    plot.set_xlimits(min=3e-3, max=3e3)
    plot.save_as_pdf('shower_walltime')
Exemple #10
0
def determine_station_timing_offsets(data):
    """Determine the offsets between the stations."""

    c = .3

    ref_station_number = 501
    ref_d_off = DETECTOR_OFFSETS[ref_station_number]
    ref_events = data.root.hisparc.cluster_amsterdam.station_501.events
    ref_t = array([
        where(
            ref_events.col('t1') == -999, 9000,
            ref_events.col('t1') - ref_d_off[0]),
        where(
            ref_events.col('t2') == -999, 9000,
            ref_events.col('t2') - ref_d_off[1]),
        where(
            ref_events.col('t3') == -999, 9000,
            ref_events.col('t3') - ref_d_off[2]),
        where(
            ref_events.col('t4') == -999, 9000,
            ref_events.col('t4') - ref_d_off[3])
    ])
    ref_min_t = ref_t.min(axis=0)

    station_number = 510
    d_off = DETECTOR_OFFSETS[station_number]
    events = data.root.hisparc.cluster_amsterdam.station_510.events
    t = array([
        where(events.col('t1') == -999, 90000,
              events.col('t1') - d_off[0]),
        where(events.col('t2') == -999, 90000,
              events.col('t2') - d_off[1]),
        where(events.col('t3') == -999, 90000,
              events.col('t3') - d_off[2]),
        where(events.col('t4') == -999, 90000,
              events.col('t4') - d_off[3])
    ])
    min_t = t.min(axis=0)

    dt = []
    for event, ref_event in itertools.izip(events, ref_events):
        if (ref_event['t_trigger'] in ERR or event['t_trigger'] in ERR):
            dt.append(nan)
            continue
        dt.append((int(event['ext_timestamp']) -
                   int(ref_event['ext_timestamp'])) -
                  (event['t_trigger'] - ref_event['t_trigger']))

    dt = array(dt)
    dt = dt + (min_t - ref_min_t)

    plot = Plot()
    bins = linspace(-50, 50, 100)
    y, bins = histogram(dt, bins=bins)
    plot.histogram(y, bins)

    x = (bins[:-1] + bins[1:]) / 2
    try:
        popt, pcov = curve_fit(gauss, x, y, p0=(len(dt), 0., 10))
        station_offset = popt[1]
        plot.draw_vertical_line(station_offset)
        bins = linspace(-50, 50, 1000)
        plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray')
    except RuntimeError:
        station_offset = 0.
    print station_offset

    plot.set_title('Time difference, station 510-501')
    plot.set_xlimits(-50, 50)
    plot.set_ylimits(min=0)
    plot.set_xlabel('$\Delta t$ [ns]')
    plot.set_ylabel('Counts')
    plot.save_as_pdf('station_offsets')
Exemple #11
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)