def plot_fit_residuals_detector(self): plot = MultiPlot(2, 2, width=r'.3\linewidth', height=r'.3\linewidth') for i in range(4): splot = plot.get_subplot_at(i / 2, i % 2) res = fit_function(self.slice_bins_c, * self.fit_i[i]) - self.med_ki[:, i] splot.scatter(self.slice_bins_c, res, xerr=(self.slice_bins[1:] - self.slice_bins[:-1]) / 2., yerr=self.std_ki[:, i], markstyle='red, mark size=1pt') splot.draw_horizontal_line(0, linestyle='gray') # splot.plot(self.lin_bins, fit_function(self.lin_bins, self.fit_i[i]) plot.set_ylimits_for_all(min=-30, max=30) plot.set_xlimits_for_all(min=0, max=max(self.slice_bins)) plot.show_xticklabels_for_all([(1, 0), (0, 1)]) plot.show_yticklabels_for_all([(1, 0), (0, 1)]) plot.set_xlabel(r'HiSPARC detected density [\si{\per\meter\squared}]') plot.set_ylabel( r'Residuals (Predicted - Fit) [\si{\per\meter\squared}]') plot.save_as_pdf('plots/fit_residuals_detector')
def plot_pi(expected, measured, name, expected_err=[], measured_err=[]): """ :param expected: expected pulseintegral from sum individual measurements. :param measured: measured pulseintegral. :param name: name for output """ plot = MultiPlot(2, 1, height=r".67\linewidth") splot = plot.get_subplot_at(0, 0) splot.scatter(measured, expected, xerr=measured_err, yerr=expected_err, markstyle='mark size=1pt') splot.plot([0, 120], [0, 120], mark=None, linestyle='gray') plot_fit(plot, expected, measured, measured_err) splot.set_ylabel( r'Sum individual LED pulseintegrals [\si{\nano\volt\second}]') splot.set_ylimits(0, 60) splot.set_axis_equal() splot = plot.get_subplot_at(1, 0) splot.set_xlabel(r'Multiple-LED pulseintegrals [\si{\nano\volt\second}]') plot.set_xlimits_for_all(None, 0, 60) plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all(None) plot.save_as_pdf('plots/data_pi_' + name)
def plot_contribution_detector(self, ni, ref_ni): plot = MultiPlot(2, 2, 'semilogy', width=r'.3\linewidth', height=r'.3\linewidth') colors = [ 'red', 'blue', 'green', 'purple', 'gray', 'brown', 'cyan', 'magenta', 'orange', 'teal' ] padding = 0.2 bins = linspace(0, 20, 100) for i in range(4): splot = plot.get_subplot_at(i / 2, i % 2) splot.histogram(*histogram(ni[:, i], bins=bins)) splot.draw_vertical_line(1) for j, density in enumerate(range(1, 8) + [15] + [20]): ni_slice = ni[:, i].compress( abs(ref_ni[:, i] - density) < padding) counts, bins = histogram(ni_slice, bins=bins) splot.histogram(counts, bins + (j / 100.), linestyle=colors[j % len(colors)]) plot.set_ylimits_for_all(min=0.9, max=1e5) plot.set_xlimits_for_all(min=bins[0], max=bins[-1]) plot.show_xticklabels_for_all([(1, 0), (0, 1)]) plot.show_yticklabels_for_all([(1, 0), (0, 1)]) plot.set_xlabel(r'HiSPARC detected density [\si{\per\meter\squared}]') plot.set_ylabel(r'Counts') return plot
def plot_coinc_window(windows, counts, n_events=0): plot = MultiPlot(2, 1, axis='semilogx', width=r'.8\linewidth', height=r'.5\linewidth') plot.set_title(0, 0, 'Number of coincidences as function of coincidence window') plot.set_xlabel('Coincidence window (ns)') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all() plot.set_xlimits_for_all(min=1e1, max=1e8) plot.set_ylimits(1, 0, min=0) counts = numpy.array(counts) subplot = plot.get_subplot_at(0, 0) subplot.set_ylabel('Found coincidences') subplot.plot(windows, counts, mark=None) subplot = plot.get_subplot_at(1, 0) subplot.set_ylabel('Delta found coincidences') subplot.plot(windows[:-1], counts[1:] - counts[:-1], mark=None) plot.save_as_pdf('coincidence_window')
def plot_pi_ph(measured_pi, measured_ph, name, ratio, pi_err=[], ph_err=[]): """ :param measured_pi: measured pulseintegral. :param measured_ph: measured pulseheight. :param name: name for output :param ratio: pi / ph ratio (from individual fibers, before saturation) """ plot = MultiPlot(2, 1, height=r".67\linewidth") splot = plot.get_subplot_at(0, 0) splot.scatter(measured_ph, measured_pi / ratio, xerr=ph_err, yerr=pi_err / ratio, markstyle='mark size=1pt') splot.plot([0, 6], [0, 6], mark=None, linestyle='gray') plot_fit(plot, measured_pi / ratio, measured_ph, pi_err) splot.set_ylabel(r'Multiple-LED pulseintegrals [\si{\nano\volt\second}]') splot.set_ylimits(0, 5.5) splot = plot.get_subplot_at(1, 0) splot.set_xlabel(r'Multiple-LED pulseheights [\si{\volt}]') plot.set_xlimits_for_all(None, 0, 5.5) plot.show_yticklabels_for_all(None) plot.show_xticklabels(1, 0) plot.save_as_pdf('plots/data_piph_' + name)
def plot_timeline(stats, field_name): step = 0.2 * BIN_WIDTH plot = MultiPlot(len(STATIONS), 1, width=r'.67\textwidth', height=r'.075\paperheight') # if field_name in ['event_rate', 'mpv']: # plot = MultiPlot(len(STATIONS), 1, # width=r'.67\textwidth', height=r'.05\paperheight') # else: # plot = MultiPlot(len(STATIONS), 1, 'semilogy', # width=r'.67\textwidth', height=r'.05\paperheight') for splot, station in zip(plot.subplots, STATIONS): stat = stats[station][field_name] if len(stat.shape) == 2: for i, s in enumerate(stat): splot.histogram(s, BINS + (step * i), linestyle='thin,' + COLORS[i]) else: splot.histogram(stat, BINS, linestyle='thin') splot.set_ylabel(r'%d' % station) plot.set_xlimits_for_all(None, min=BINS[0], max=BINS[-1]) plot.set_xticks_for_all(None, YEARS_TICKS) 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 not in ['event_rate', 'mpv']: # plot.set_ylimits_for_all(None, 1e-4, 100) plot.set_xlabel(r'Timestamp') if field_name == 'event_rate': ylabel = r'Event rate [\si{\hertz}]' elif field_name == 'mpv': ylabel = r'MPV [ADC.ns]' else: ylabel = (r'Fraction of bad %s data [\si{\percent}]' % field_name.replace('_', ' ')) plot.set_ylabel(ylabel) if field_name in ['event_rate', 'mpv']: plot.save_as_pdf('plots/%s' % field_name) else: plot.save_as_pdf('plots/bad_fraction_%s' % field_name)
def plot_shower_profile(seeds): with tables.open_file(PATH % seeds) as data: gp = data.root.groundparticles min_t = gp.col('t').min() print 'Making plots for %s' % seeds gamma = gp.read_where('particle_id == 1') electrons = gp.read_where('(particle_id == 3) | (particle_id == 4)') muons = gp.read_where('(particle_id == 5) | (particle_id == 6)') for correction in ['none', 'median_self']: plot = MultiPlot(3, 1, 'semilogx', height=r'.4\linewidth') splot = plot.get_subplot_at(0, 0) splot.set_ylabel('Gamma') plot_statistics(seeds, splot, gamma['r'], gamma['t'] - min_t, 'solid', correction=correction) splot = plot.get_subplot_at(1, 0) splot.set_ylabel('Electrons') plot_statistics(seeds, splot, electrons['r'], electrons['t'] - min_t, 'solid', correction=correction) splot = plot.get_subplot_at(2, 0) splot.set_ylabel('Muon') plot_statistics(seeds, splot, muons['r'], muons['t'] - min_t, 'solid', correction=correction) plot.set_xlimits_for_all(None, 1e0, 1e3) if correction is 'median_self': plot.set_ylimits_for_all(None, -120, 120) else: plot.set_ylimits_for_all(None, 0, 120) plot.show_xticklabels(2, 0) plot.show_yticklabels_for_all() plot.set_ylabel(r'Arrival time [\si{\ns}]') plot.set_xlabel(r'Core distance [\si{\meter}]') plot.set_title(0, 0, get_info_string_tex(seeds)) plot.save_as_pdf('plots/time_profile/%s_%s.pdf' % (get_info_string(seeds), correction))
def plot_detected_zenith_distribution(): plot = MultiPlot(2, 2, width=r'.3\textwidth', height=r'.3\textwidth') for i, e in enumerate([16, 16.5, 17, 17.5]): splot = plot.get_subplot_at(int(i / 2), int(i % 2)) c, b = histogram(zenith.compress(energy_in == e), bins=arange(0, 65, 1)) splot.histogram(c, b) plot.set_title('Reconstructed zeniths per shower energy') plot.set_xlimits_for_all(None, 0, 65) plot.set_ylimits_for_all(None, 0) plot.save_as_pdf('zenith_reconstructed')
def plot_station_offset_matrix(): n = len(STATIONS) stations = { station: Station(station, force_stale=True) for station in STATIONS } for type in ['offset', 'error']: plot = MultiPlot(n, n, width=r'.08\textwidth', height=r'.08\textwidth') for i, station in enumerate(STATIONS): for j, ref_station in enumerate(STATIONS): splot = plot.get_subplot_at(i, j) if i == n: splot.show_xticklabels() if station == ref_station: splot.set_empty() splot.set_label(r'%d' % station, location='center') continue offsets = stations[station].station_timing_offsets(ref_station) bins = list(offsets['timestamp']) bins += [bins[-1] + 86400] splot.histogram(offsets[type], bins, linestyle='very thin') splot.set_axis_options('line join=round') plot_cuts_vertically(splot, stations, station, ref_station) # Even/row rows/columns for row in range(0, n, 2): plot.set_yticklabels_position(row, n - 1, 'right') plot.set_xticklabels_position(n - 1, row, 'bottom') plot.show_yticklabels(row, n - 1) #plot.show_xticklabels(n - 1, row) for row in range(1, n, 2): plot.set_yticklabels_position(row, 0, 'left') plot.set_xticklabels_position(0, row, 'top') plot.show_yticklabels(row, 0) #plot.show_xticklabels(0, row) if type == 'offset': plot.set_ylimits_for_all(None, min=-70, max=70) else: plot.set_ylimits_for_all(None, min=0, max=10) plot.set_xlimits_for_all(None, min=datetime_to_gps(date(2011, 1, 1)), max=datetime_to_gps(date.today())) plot.set_xticks_for_all(None, YEARS_TICKS) # plot.set_xtick_labels_for_all(YEARS_LABELS) plot.set_xlabel(r'Date') plot.set_ylabel(r'Station offset [\si{\ns}]') plot.save_as_pdf('station_offsets_%s' % type)
def plot_layouts(path='/'): with tables.open_file(RESULT_DATA, 'r') as data: cluster = data.get_node_attr(path + 'coincidences', 'cluster') plot = MultiPlot(3, 1, width=r'0.67\textwidth', height=r'.2\textwidth') for splot, station in zip(plot.subplots, cluster.stations): for detector in station.detectors: x, y = zip(*detector.get_corners()) splot.plot(x + x[:1], y + y[:1], mark=None) splot.set_axis_equal() plot.show_xticklabels_for_all([(2, 0)]) plot.show_yticklabels_for_all() plot.set_ylabel(r'North [\si{\meter}]') plot.set_xlabel(r'East [\si{\meter}]') plot.set_xlimits_for_all(None, -6, 6) plot.set_ylimits_for_all(None, -1.2, 1.2) plot.save_as_pdf('layouts' + path.replace('/', '_'))
def plot_spectrum_componenten(): """Plot voor componenten pulshoogte spectrum""" multiplot = MultiPlot(3, 1, axis='semilogy', width=r'0.5\linewidth') pylab.clf() subplot0 = multiplot.get_subplot_at(0, 0) subplot1 = multiplot.get_subplot_at(1, 0) subplot2 = multiplot.get_subplot_at(2, 0) x = pylab.linspace(1e-10, 11, 200) th_signal = [] signal = pylab.zeros(x.shape) for N in range(1, 15): scale = 100. / N ** 3 pdf = 80 * scale * pylab.normpdf(x, N, pylab.sqrt(N) * 0.35) # pylab.plot(x, pdf) subplot1.plot(x, pdf, mark=None) # subplot1.add_pin('%d MIP' % N, 'above right', x=N, use_arrow=True, # style='lightgray') subplot2.plot(x, pdf, mark=None, linestyle='lightgray') signal += pdf th_signal.extend(int(100 * scale) * [N]) gammas = 1e2 * x ** -3 subplot1.plot(x, gammas, mark=None) subplot2.plot(x, gammas, mark=None, linestyle='lightgray') signal += gammas pylab.plot(x, signal) pylab.plot(x, gammas) subplot2.plot(x, signal, mark=None) pylab.yscale('log') pylab.ylim(ymin=1) n, bins = pylab.histogram(th_signal, bins=pylab.linspace(0, 11, 100)) n = pylab.where(n == 0, 1e-10, n) subplot0.histogram(n, bins) multiplot.show_xticklabels_for_all([(0, 0), (2, 0)]) multiplot.set_xticks_for_all([(0, 0), (2, 0)], range(20)) # multiplot.show_yticklabels_for_all([(0, 0), (1, 0), (2, 0)]) multiplot.set_xlabel('Aantal deeltjes') multiplot.set_ylabel('Aantal events') multiplot.set_ylimits_for_all(min=1, max=1e5) multiplot.set_xlimits_for_all(min=0, max=10.5) multiplot.save('spectrum_componenten')
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 plot_time_profile_for_bin(seeds, gamma_t, electrons_t, muons_t): plot = MultiPlot(3, 1, 'semilogx', height=r'.4\linewidth') bins = logspace( log10(min(gamma_t.min(), electrons_t.min(), muons_t.min())), log10(max(gamma_t.max(), electrons_t.max(), muons_t.max())), 25) for splot, data, particle_name in zip(plot.subplots, [gamma_t, electrons_t, muons_t], ['Gamma', 'Electrons', 'Muons']): splot.set_ylabel(particle_name) splot.histogram(*histogram(data, bins=bins)) plot.set_xlimits_for_all(None, bins[0], bins[-1]) # plot.set_ylimits_for_all(None, 0, 120) plot.show_xticklabels(2, 0) plot.show_yticklabels_for_all() plot.set_ylabel(r'Number of particles') plot.set_xlabel(r'Arrival time [\si{\ns}]') plot.save_as_pdf('plots/time_profile_bin/%s.pdf' % get_info_string(seeds))
def plot_afstelling_pmt(): """Plot voor afstellen spanning""" multiplot = MultiPlot(1, 3, width=r'0.4\linewidth') x = pylab.linspace(1e-10, 11, 200) signal = pylab.zeros(x.shape) for N in range(1, 15): scale = 100. / N ** 3 pdf = 80 * scale * pylab.normpdf(x, N, pylab.sqrt(N) * 0.35) signal += pdf gammas = 1e2 * x ** -3 signal += gammas p = multiplot.get_subplot_at(0, 0) v = x * 35 p.plot(v, pylab.where(v >= 30, signal, 1), mark=None) p.draw_vertical_line(200, linestyle='gray') p.set_label(r"$V_\mathrm{PMT}$ te laag") p = multiplot.get_subplot_at(0, 1) v = x * 200 p.plot(v, pylab.where(v >= 30, signal, 1), mark=None) p.draw_vertical_line(200, linestyle='gray') p.set_label(r"$V_\mathrm{PMT}$ correct") p = multiplot.get_subplot_at(0, 2) v = x * 400 p.plot(v, pylab.where(v >= 30, signal, 1), mark=None) p.draw_vertical_line(200, linestyle='gray') p.set_label(r"$V_\mathrm{PMT}$ te hoog") multiplot.set_xlabel(r"Pulseheight [\si{\milli\volt}]") multiplot.set_ylabel("Counts") multiplot.set_xlimits_for_all(min=0, max=1000) multiplot.set_ylimits_for_all(min=1) multiplot.show_xticklabels_for_all() multiplot.set_xticklabels_position(0, 1, 'top') multiplot.set_yticks_for_all(ticks=None) multiplot.save('afstelling_pmt')
def compare_integrals(before, after): if len(before) > 5000: plot = MultiPlot(4, 1, width=r'.6\textwidth', height=r'.3\textwidth') bins = [linspace(100, 6000, 20), linspace(-150, 150, 20)] for i, splot in enumerate(plot.subplots): c, x, y = histogram2d(before[:, i], after[:, i] - before[:, i], bins=bins) # splot.histogram2d(c, x, y, bitmap=True, type='color', colormap='viridis') splot.histogram2d(c, x, y, type='area') plot.show_yticklabels_for_all(None) plot.show_xticklabels(3, 0) plot.save_as_pdf('hist2d') else: plot = MultiPlot(4, 1, 'semilogx', width=r'.6\textwidth', height=r'.3\textwidth') for i, splot in enumerate(plot.subplots): splot.scatter(before[:, i], after[:, i] - before[:, i], mark='o', markstyle='mark size=0.6pt, very thin, ' 'semitransparent, %s' % COLORS[i]) plot.show_yticklabels_for_all(None) plot.show_xticklabels(3, 0) plot.set_xlimits_for_all(None, 100, 100000) plot.set_ylimits_for_all(None, -150, 150) plot.save_as_pdf('scatter') plot = MultiPlot(4, 1, width=r'.6\textwidth', height=r'.3\textwidth') for i, splot in enumerate(plot.subplots): filter = before[:, i] > 0 # Ignore detectors/events with no signal c, bins = histogram(after[:, i][filter] - before[:, i][filter], linspace(-150, 150, 100)) splot.histogram(c, bins, linestyle='%s' % COLORS[i]) plot.show_yticklabels_for_all(None) plot.show_xticklabels(3, 0) plot.set_xlimits_for_all(None, -150, 150) plot.set_ylimits_for_all(None, 0) plot.save_as_pdf('histogram')
def plot_densities(data): """Make particle count plots for each detector to compare densities/responses""" n_min = 0.5 # remove gamma peak n_max = 50 bins = np.linspace(np.log10(n_min), np.log10(n_max), 60) for station_number in [501, 510]: events = data.get_node('/s%d' % station_number, 'events') average_n = (events.col('n1') + events.col('n2') + events.col('n3') + events.col('n4')) / 4. n = [events.col('n1'), events.col('n2'), events.col('n3'), events.col('n4')] for minn in [0, 1, 2, 4, 8, 16]: filter = (average_n > minn) & (n[0] > 0) & (n[1] > 0) & (n[2] > 0) & (n[3] > 0) plot = MultiPlot(4, 4, width=r'.25\linewidth', height=r'.25\linewidth') for i in range(4): for j in range(4): if i < j: continue elif i == j: ncounts, x, y = np.histogram2d(np.log10(average_n.compress(filter)), np.log10(n[i].compress(filter)), bins=bins) else: ncounts, x, y = np.histogram2d(np.log10(n[i].compress(filter)), np.log10(n[j].compress(filter)), bins=bins) subplot = plot.get_subplot_at(i, j) subplot.histogram2d(ncounts, x, y, type='reverse_bw', bitmap=True) plot.set_xlimits_for_all(min=0, max=np.log10(n_max)) plot.set_ylimits_for_all(min=0, max=np.log10(n_max)) plot.show_xticklabels_for_all([(3, 0), (3, 1), (3, 2), (3, 3)]) plot.show_yticklabels_for_all([(0, 3), (1, 3), (2, 3), (3, 3)]) # plot.set_title(0, 1, 'Particle counts for station 501 and 510') for i in range(4): plot.set_subplot_xlabel(0, i, 'detector %d' % (i + 1)) plot.set_subplot_ylabel(i, 0, 'detector %d' % (i + 1)) plot.set_xlabel('Number of particles') plot.set_ylabel('Number of particles') plot.save_as_pdf('plots/n_minn%d_%d' % (minn, station_number))
def plot_configs_timeline(stats, field, field_name): step = 86400 # one day plot = MultiPlot(len(STATIONS), 1, width=r'.67\textwidth', height=r'.05\paperheight') for splot, station in zip(plot.subplots, STATIONS): config = stats[station][field] for i in range(4): timestamps = list(config['timestamp'] + (i * step)) timestamps.append(END_TS) splot.histogram(config[field_name % (i + 1)], timestamps, linestyle=COLORS[i]) splot.set_ylabel(r'%d' % station) plot.set_xlimits_for_all(None, min=START_TS, max=END_TS) plot.set_xticks_for_all(None, YEARS_TICKS) 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') if field == 'voltages': plot.set_ylimits_for_all(None, 300) plot.set_ylabel(r'PMT voltage \si{\volt}') elif field == 'currents': plot.set_ylimits_for_all(None, 0) plot.set_ylabel(r'PMT current \si{\milli\volt}') elif field == 'detector_timing_offsets': plot.set_ylabel(r'Detector timing offsets \si{\ns}') plot.set_xlabel(r'Timestamp') plot.save_as_pdf('plots/config_%s' % field)
def plot_energy_profile_for_bin(seeds, gamma_e, electrons_e, muons_e): plot = MultiPlot(3, 1, 'semilogx', height=r'.4\linewidth') print('Min gamma/electron energy: %d MeV, %d MeV' % (gamma_e.min() * 1e-6, electrons_e.min() * 1e-6)) print 'Min muon energy: %d MeV' % (muons_e.min() * 1e-6, ) bins = logspace(6, 12, 40) for splot, data, particle_name in zip(plot.subplots, [gamma_e, electrons_e, muons_e], ['Gamma', 'Electrons', 'Muons']): splot.set_ylabel(particle_name) splot.draw_vertical_line(300e6 if particle_name is 'Muons' else 3e6, 'red') splot.histogram(*histogram(data, bins=bins)) plot.set_xlimits_for_all(None, bins[0], bins[-1]) # plot.set_ylimits_for_all(None, 0, 120) plot.show_xticklabels(2, 0) plot.show_yticklabels_for_all() plot.set_ylabel(r'Number of particles') plot.set_xlabel(r'Particle energy [\si{\MeV}]') plot.save_as_pdf('plots/energy_profile_bin/%s.pdf' % get_info_string(seeds))
plot(x, gammas) subplot2.plot(x, signal, mark=None) yscale('log') ylim(ymin=1) n, bins = histogram(th_signal, bins=linspace(0, 11, 100)) n = where(n == 0, 1e-10, n) subplot0.histogram(n, bins) multiplot.show_xticklabels_for_all([(0, 0), (2, 0)]) multiplot.set_xticks_for_all([(0, 0), (2, 0)], range(20)) #multiplot.show_yticklabels_for_all([(0, 0), (1, 0), (2, 0)]) multiplot.set_xlabel('Aantal deeltjes') multiplot.set_ylabel('Aantal events') multiplot.set_ylimits_for_all(min=1, max=1e5) multiplot.set_xlimits_for_all(min=0, max=10.5) multiplot.save('spectrum_componenten') # Plot voor afstellen spanning multiplot = MultiPlot(1, 3, width=r'.4\linewidth') p = multiplot.get_subplot_at(0, 1) V = x * 200 p.plot(V, where(V >= 30, signal, 1), mark=None) p.draw_vertical_line(200, linestyle='gray') p.set_label(r"$V_\mathrm{PMT}$ correct") p = multiplot.get_subplot_at(0, 2) V = x * 400
def plot_distance_width(): distances = [] widths = [] sim_widths = [] with tables.open_file(SIM_PATH, 'r') as sim_data: for ref_station, station in itertools.combinations(SPA_STAT, 2): if ref_station == 501 and station == 509: continue if ref_station == 501 and station == 510: continue if ref_station == 505 and station == 509: continue distances.append( CLUSTER.calc_rphiz_for_stations(SPA_STAT.index(ref_station), SPA_STAT.index(station))[0]) with tables.open_file( DATA_PATH + 'dt_ref%d_%d.h5' % (ref_station, station), 'r') as data: table = get_station_dt(data, station) ts1 = table[-1]['timestamp'] - WEEK ts0 = ts1 - HALFYEAR # * max(1, (distance / 100)) dt = table.read_where('(timestamp > ts0) & (timestamp < ts1)', field='delta') sim_ref_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % ref_station, 'events') sim_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % station, 'events') sim_dt = (sim_ref_events.col('ext_timestamp').astype(int) - sim_events.col('ext_timestamp').astype(int)) bins = arange(-2000, 2000.1, 30) # bins = linspace(-max_dt, max_dt, 150) # bins = linspace(-1.8 * std(dt), 1.8 * std(dt), 100) x = (bins[:-1] + bins[1:]) / 2 sim_counts, bins = histogram(sim_dt, bins=bins, density=True) counts, bins = histogram(dt, bins=bins, density=True) # width = curve_fit(norm.pdf, x, counts, p0=(0., distances[-1]))[0][1] # widths.append(width) # sim_width = curve_fit(norm.pdf, x, sim_counts, p0=(0., distances[-1]))[0][1] # sim_widths.append(sim_width) window_width = distances[-1] * 3.5 width = std(dt.compress(abs(dt) < window_width)) widths.append(width) sim_width = std(sim_dt.compress(abs(sim_dt) < window_width)) sim_widths.append(sim_width) widths = array(widths) sim_widths = array(sim_widths) popt, pcov = curve_fit(lin, distances, widths, p0=(1.1, 1), sigma=array(distances)**0.3) popt, pcov = curve_fit(lin_origin, distances, widths, p0=(1.1), sigma=array(distances)**0.3) print popt, pcov plot = MultiPlot(2, 1) splot = plot.get_subplot_at(0, 0) splot.scatter(distances, widths, markstyle='black') splot.scatter(distances, sim_widths, markstyle='black', mark='+') splot.plot([0, 600], [0, 600 / 0.3], mark=None, linestyle='gray') splot.plot( [0, 600], [lin_origin(0, *popt), lin_origin(600, *popt)], mark=None) splot.set_ylimits(min=0, max=700) splot.set_ylabel(r'$\sigma_{\Delta t}$ [\si{\ns}]') splot = plot.get_subplot_at(1, 0) splot.scatter(distances, widths - sim_widths, markstyle='mark size=1pt') splot.draw_horizontal_line(0, linestyle='gray') splot.set_axis_options(r'height=0.2\textwidth') splot.set_ylabel( r'$\sigma_{\mathrm{data}} - \sigma_{\mathrm{sim}}$ [\si{\ns}]') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all(None) plot.set_xlimits_for_all(None, min=0, max=600) plot.set_xlabel(r'Distance [\si{\meter}]') plot.save_as_pdf('plots/distance_v_width_sim')
def combine_delta_data(): delta_data = genfromtxt('data/time_delta.tsv', delimiter='\t', dtype=None, names=['ext_timestamp', 'time_delta']) delta_data = {ets: td for ets, td in delta_data} tm = [] ts = [] td = [] te = [] with tables.open_file('data/data.h5', 'r') as data: for row in data.root.s99.events: ets = row['ext_timestamp'] try: dt = delta_data[ets] except KeyError: continue tm.append(row['t1']) ts.append(row['t3']) td.append(dt) te.append(ets) tm = array(tm) ts = array(ts) td = array(td) te = array(te) filter = (tm >= 0) & (ts >= 0) tm = tm.compress(filter) ts = ts.compress(filter) td = td.compress(filter) te = te.compress(filter) bins = arange(-10.25, 10.26, .5) mplot = MultiPlot(3, 2, width=r'.4\linewidth', height=r'.3\linewidth') mplot.show_xticklabels_for_all([(2, 0), (2, 1)]) mplot.show_yticklabels_for_all([(0, 0), (1, 1), (2, 0)]) mplot.set_xlimits_for_all(min=-11, max=11) mplot.set_ylimits_for_all(min=0, max=1500) mplot.set_ylabel('Counts') mplot.set_xlabel(r'Time difference [\si{\nano\second}]') plot = mplot.get_subplot_at(0, 0) counts, bins = histogram(tm - ts, bins=bins) popt = fit_timing_offset(counts / 3., bins) plot.set_label(r'$t_{M} - t_{S}$, $%.1f\pm%.1f$\si{\nano\second}, scaled' % (popt[1], popt[2])) plot.histogram(counts / 3., bins) plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray') plot = mplot.get_subplot_at(1, 0) plot.set_label(r'$t_{\delta}$') plot.histogram(*histogram(td, bins=bins)) plot = mplot.get_subplot_at(2, 0) counts, bins = histogram(tm - (ts + td), bins=bins) popt = fit_timing_offset(counts, bins) plot.set_label( r'$t_{M} - (t_{S} + t_{\delta})$, $%.1f\pm%.1f$\si{\nano\second}' % (popt[1], popt[2])) plot.histogram(counts, bins) plot.plot(bins, gauss(bins, *popt), mark=None, linestyle='gray') plot = mplot.get_subplot_at(0, 1) plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == -5$') plot.draw_vertical_line(-5, linestyle='gray') plot.histogram(*histogram(td.compress(tm - ts == -5), bins=bins)) plot = mplot.get_subplot_at(1, 1) plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == -2.5$') plot.draw_vertical_line(-2.5, linestyle='gray') plot.histogram(*histogram(td.compress(tm - ts == -2.5), bins=bins)) plot = mplot.get_subplot_at(2, 1) plot.set_label(r'$t_{\delta}$ where $t_{M} - t_{S} == 0$') plot.draw_vertical_line(0, linestyle='gray') plot.histogram(*histogram(td.compress(tm - ts == 0), bins=bins)) mplot.save_as_pdf('dt_time_delta') plot = Plot() counts, xbins, ybins = histogram2d(tm - ts, td, bins=bins) plot.histogram2d(counts, xbins, ybins, bitmap=True, type='reverse_bw') plot.set_xlabel(r'$t_{M} - t_{S}$ [\si{\nano\second}]') plot.set_ylabel(r'$t_{\delta}$ [\si{\nano\second}]') plot.save_as_pdf('dt_vs_time_delta')
def plot_distance_width(): distances = [] widths = [] sim_widths = [] with tables.open_file(SIM_PATH, 'r') as sim_data: for ref_station, station in itertools.combinations(SPA_STAT, 2): if ref_station == 501 and station == 509: continue if ref_station == 501 and station == 510: continue if ref_station == 505 and station == 509: continue distances.append( CLUSTER.calc_rphiz_for_stations(SPA_STAT.index(ref_station), SPA_STAT.index(station))[0]) with tables.open_file( DATA_PATH + 'dt_ref%d_%d.h5' % (ref_station, station), 'r') as data: table = get_station_dt(data, station) ts1 = table[-1]['timestamp'] - WEEK ts0 = ts1 - HALFYEAR # * max(1, (distance / 100)) dt = table.read_where('(timestamp > ts0) & (timestamp < ts1)', field='delta') sim_ref_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % ref_station, 'events') sim_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % station, 'events') sim_dt = (sim_ref_events.col('ext_timestamp').astype(int) - sim_events.col('ext_timestamp').astype(int)) high = 94 low = 6 width = percentile(sorted(dt), high) - percentile( sorted(dt), low) widths.append(width) sim_width = percentile(sim_dt, high) - percentile(sim_dt, low) sim_widths.append(sim_width) widths = array(widths) sim_widths = array(sim_widths) popt, pcov = curve_fit(lin, distances, widths, p0=(1.1, 1), sigma=array(distances)**0.3) print popt, pcov plot = MultiPlot(2, 1) splot = plot.get_subplot_at(0, 0) splot.scatter(distances, widths) splot.scatter(distances, sim_widths, markstyle='green') splot.plot([0, 600], [0, 600 / 0.3], mark=None, linestyle='gray') splot.plot([0, 600], [lin(0, *popt), lin(600, *popt)], mark=None) splot.set_ylimits(min=0, max=700 / 0.3) splot = plot.get_subplot_at(1, 0) splot.scatter(distances, widths - sim_widths, markstyle='mark size=1pt') splot.draw_horizontal_line(0, linestyle='gray') splot.set_axis_options(r'height=0.2\textwidth') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all(None) plot.set_xlimits_for_all(None, min=0, max=600) plot.set_xlabel(r'Distance [\si{\meter}]') plot.set_ylabel(r'Width of $\Delta t$ distribution [\si{\ns}]') plot.save_as_pdf('plots/distance_v_maxdt_sim')
def plot_distance_vs_delay(data): colors = { 501: 'black', 502: 'red!80!black', 503: 'blue!80!black', 504: 'green!80!black', 505: 'orange!80!black', 506: 'pink!80!black', 508: 'blue!40!black', 509: 'red!40!black', 510: 'green!40!black', 511: 'orange!40!black' } cq = CoincidenceQuery(data) cq.reconstructions = cq.data.get_node('/coincidences', 'recs_curved') cq.reconstructed = True cluster = data.root.coincidences._v_attrs['cluster'] offsets = { s.number: [d.offset + s.gps_offset for d in s.detectors] for s in cluster.stations } front = CorsikaStationFront() front_r = np.arange(500) front_t = front.delay_at_r(front_r) for i, coincidence in enumerate(cq.coincidences.read_where('N > 6')): if i > 50: break coincidence_events = next(cq.all_events([coincidence])) reconstruction = cq._get_reconstruction(coincidence) core_x = coincidence['x'] core_y = coincidence['y'] plot = MultiPlot(2, 1) splot = plot.get_subplot_at(0, 0) rplot = plot.get_subplot_at(1, 0) splot.plot(front_r, front_t, mark=None) ref_extts = coincidence_events[0][1]['ext_timestamp'] front_detect_r = [] front_detect_t = [] for station_number, event in coincidence_events: station = cluster.get_station(station_number) t = event_utils.relative_detector_arrival_times( event, ref_extts, offsets=offsets[station_number], detector_ids=DETECTOR_IDS) core_distances = [] for i, d in enumerate(station.detectors): x, y, z = d.get_coordinates() core_distances.append(distance_between(core_x, core_y, x, y)) t += d.get_coordinates()[-1] / c splot.scatter(core_distances, t, mark='o', markstyle=colors[station_number]) splot.scatter([np.mean(core_distances)], [np.nanmin(t)], mark='*', markstyle=colors[station_number]) rplot.scatter( [np.mean(core_distances)], [np.nanmin(t) - front.delay_at_r(np.mean(core_distances))], mark='*', markstyle=colors[station_number]) splot.set_ylabel('Relative arrival time [ns]') rplot.set_ylabel(r'Residuals') rplot.set_axis_options(r'height=0.25\textwidth') splot.set_ylimits(-10, 150) plot.set_xlimits_for_all(None, 0, 400) plot.set_xlabel('Distance from core [m]') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all() plot.save_as_pdf('front_shape/distance_v_time_%d_core' % coincidence['id'])
def plot_arrival_time_distribution_v_distance(data, seeds): results = [] cor_t = None for group in data.walk_groups('/'): if (seeds not in group._v_pathname or group._v_name != 'coincidences'): continue coincidences = group.coincidences events = data.get_node(group.s_index[0]).events r = next( int(y[1:]) for y in group._v_pathname.split('/') if y.startswith('r')) seeds = next(y[1:] for y in group._v_pathname.split('/') if y.startswith('s')) if cor_t is None: with tables.open_file(CORSIKA_DATA % seeds) as data: gp = data.root.groundparticles query = '(x < 10) & (x > -10) & (r < 10)' cor_t = gp.read_where(query, field='t').min() # i = get_info(seeds)['first_interaction_altitude'] # cor_t = i / 0.299792458 # Round ts to seconds because it is the ts for first event, not the shower t = [ station_arrival_time( event, int(cets['ext_timestamp'] / int(1e9)) * int(1e9), detector_ids=[0, 1, 2, 3]) - cor_t for event, cets in zip( events[:], coincidences.read_where('N == 1')) ] if not len(t) or len(t) < 10: continue quantiles = [25, 50, 75] qt = percentile(t, q=quantiles) results.append([r] + list(qt) + [100 * events.nrows / float(coincidences.nrows)]) if not len(results): return results = sorted(results) (core_distances, arrival_times_low, arrival_times, arrival_times_high, efficiency) = zip(*results) causal = causal_front(i, core_distances) plot = MultiPlot(2, 1) splot = plot.get_subplot_at(0, 0) plot_shower_profile(seeds, splot, core_distances, cor_t) splot.plot(core_distances, causal, mark=None, linestyle='purple, dashed') splot.plot(core_distances, arrival_times, mark='*') splot.shade_region(core_distances, arrival_times_low, arrival_times_high, color='blue, semitransparent') splot.set_ylabel(r'Arrival time [\si{\ns}]') splot = plot.get_subplot_at(1, 0) splot.plot(core_distances, efficiency) splot.set_ylabel(r'Detection efficiency [\si{\percent}]') splot.set_axis_options(r'height=0.25\textwidth') plot.set_ylimits(0, 0, min=-10, max=210) plot.set_ylimits(1, 0, min=-5, max=105) plot.set_xlimits_for_all(None, 0, 550) plot.set_xlabel(r'Core distance [\si{\meter}]') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all() plot.save_as_document( '/data/hisparc/adelaat/corsika_accuracy/plots/%s.tex' % get_info_string(seeds))
def plot_offset_distributions(): with tables.open_file(SIM_PATH, 'r') as sim_data: for ref_station, station in itertools.combinations(SPA_STAT, 2): # [(504, 509)]: if ref_station == 501 and station == 510: continue with tables.open_file( DATA_PATH + 'dt_ref%d_%d.h5' % (ref_station, station), 'r') as data: distance = horizontal_distance_between_stations( ref_station, station) max_dt = max(distance / .3, 100) * 1.5 table = get_station_dt(data, station) ts1 = table[-1]['timestamp'] - WEEK ts0 = ts1 - YEAR # * max(1, (distance / 100)) dt = table.read_where('(timestamp > ts0) & (timestamp < ts1)', field='delta') sim_ref_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % ref_station, 'events') sim_events = sim_data.get_node( '/flat/cluster_simulations/station_%d' % station, 'events') sim_dt = (sim_ref_events.col('ext_timestamp').astype(int) - sim_events.col('ext_timestamp').astype(int)) bins = arange(-2000, 2000.1, 30) # linspace(-max_dt, max_dt, 150) x = (bins[:-1] + bins[1:]) / 2 sim_counts, bins = histogram(sim_dt, bins=bins, density=True) counts, bins = histogram(dt, bins=bins, density=True) sim_offset = curve_fit(norm.pdf, x, sim_counts, p0=(0., 30.))[0][0] offset = curve_fit(norm.pdf, x, counts, p0=(0., 30.))[0][0] sim_counts, bins = histogram(sim_dt - sim_offset, bins=bins, density=True) counts, bins = histogram(dt - offset, bins=bins, density=True) plot = MultiPlot(2, 1) splot = plot.get_subplot_at(0, 0) splot.histogram(counts, bins) splot.histogram(sim_counts, bins, linestyle='green') # plot_fits(splot, counts, bins) splot.draw_vertical_line(distance * 3.5, linestyle='dashed') splot.draw_vertical_line(-distance * 3.5, linestyle='dashed') splot.set_ylabel('Counts') splot.set_ylimits(min=0) splot = plot.get_subplot_at(1, 0) splot.scatter(x, counts - sim_counts, markstyle='mark size=1pt') splot.draw_horizontal_line(0, linestyle='gray') splot.set_axis_options(r'height=0.2\textwidth') plot.show_xticklabels(1, 0) plot.show_yticklabels_for_all(None) plot.set_xlabel(r'$\Delta t$ [\si{\ns}]') plot.set_xlimits_for_all(None, -2000, 2000) plot.save_as_pdf('plots/distribution/dt_ref%d_%d_dist_width' % (ref_station, station))
from artist import MultiPlot from sapphire import api sns = api.Network(force_stale=True).station_numbers() original_base = api.LOCAL_BASE for i in range(8): plot = MultiPlot(16, 1, width=r'0.67\linewidth', height=r'0.05\linewidth') for splot, sn in zip(plot.subplots, sns[i * 16:(i + 1) * 16]): for path, color in [(original_base, 'black'), (original_base + '_old', 'red')]: api.LOCAL_BASE = path try: s = api.Station(sn, force_stale=True) if not len(s.detector_timing_offsets): splot.set_empty() continue except: splot.set_empty() continue splot.plot(s.detector_timing_offsets['timestamp'], s.detector_timing_offsets['offset1'], mark=None, linestyle='ultra thin, ' + color) splot.set_axis_options('line join=round') splot.set_ylabel(str(sn)) plot.set_ylimits_for_all(None, -20, 20) plot.set_xlimits_for_all(None, 1224201600, 1465344000) plot.save_as_pdf('detector_offset_set_%d' % i)