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)
def plot_n_azimuth(path='/'): with tables.open_file(RESULT_DATA, 'r') as data: coin = data.get_node(path + 'coincidences/coincidences') in_azi = coin.col('azimuth') ud_azi = coin.read_where('s0', field='azimuth') lr_azi = coin.read_where('s1', field='azimuth') sq_azi = coin.read_where('s2', field='azimuth') udlr_azi = coin.get_where_list('s0 & s1') print('Percentage detected in both %f ' % (float(len(udlr_azi)) / len(in_azi))) bins = np.linspace(-np.pi, np.pi, 30) in_counts = np.histogram(in_azi, bins)[0].astype(float) ud_counts = np.histogram(ud_azi, bins)[0].astype(float) lr_counts = np.histogram(lr_azi, bins)[0].astype(float) sq_counts = np.histogram(sq_azi, bins)[0].astype(float) print('Detected: UD %d | LR %d | SQ %d' % (sum(ud_counts), sum(lr_counts), sum(sq_counts))) plot = Plot() plot.histogram(ud_counts / in_counts, bins, linestyle='black') plot.histogram(lr_counts / in_counts, bins + 0.01, linestyle='red') plot.histogram(sq_counts / in_counts, bins + 0.01, linestyle='blue') plot.histogram((ud_counts - lr_counts) / in_counts, bins, linestyle='black') plot.set_xlabel(r'Shower azimuth [\si{\radian}]') plot.set_ylabel(r'Percentage detected') plot.set_xlimits(bins[0], bins[-1]) plot.draw_horizontal_line(0, linestyle='thin, gray') # plot.set_ylimits(0) plot.save_as_pdf('azimuth_percentage' + path.replace('/', '_'))
def plot_fit_residuals_station(self): plot = Plot() res = fit_function(self.slice_bins_c, *self.fit) - self.med_k plot.scatter(self.slice_bins_c, res, xerr=(self.slice_bins[1:] - self.slice_bins[:-1]) / 2., yerr=self.std_k, markstyle='red, mark size=1pt') plot.draw_horizontal_line(0, linestyle='gray') plot.set_ylimits(min=-30, max=30) plot.set_xlimits(min=0, max=max(self.slice_bins)) 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_station')
def zoom_pulse(raw_traces): plot = Plot() start, end = get_outer_limits(raw_traces, 253) for i, raw_trace in enumerate(raw_traces): plot.plot(arange(start * 2.5, end * 2.5, 2.5), raw_trace[start:end], mark=None, linestyle=COLORS[i]) hisparc_version = 2 if hisparc_version == 3: low = 81 high = 150 elif hisparc_version == 2: low = 253 high = 323 plot.draw_horizontal_line(low, 'gray') plot.add_pin_at_xy(start * 2.5, low, 'low', location='above right', use_arrow=False) plot.draw_horizontal_line(high, 'gray') plot.add_pin_at_xy(start * 2.5, high, 'high', location='above right', use_arrow=False) plot.set_ylimits(min=0) plot.set_xlimits(min=start * 2.5, max=end * 2.5 - 2.5) plot.set_ylabel(r'Signal strength [ADC counts]') plot.set_xlabel(r'Sample [\si{\nano\second}]') plot.save_as_pdf('pulse')
def plot_traces(event, station): s = Station(station) plot = Plot() traces = s.event_trace(event['timestamp'], event['nanoseconds'], raw=True) for j, trace in enumerate(traces): t = arange(0, (2.5 * len(traces[0])), 2.5) plot.plot(t, trace, mark=None, linestyle=COLORS[j]) n_peaks = event['n_peaks'] plot.set_title('%d - %d' % (station, event['ext_timestamp'])) plot.set_label('%d ' * 4 % tuple(n_peak for n_peak in n_peaks)) plot.set_xlabel('t [\si{n\second}]') plot.set_ylabel('Signal strength') plot.set_xlimits(min=0, max=2.5 * len(traces[0])) plot.set_ylimits(min=150, max=500) # max=2 ** 12 plot.draw_horizontal_line(253, linestyle='gray') plot.draw_horizontal_line(323, linestyle='gray') plot.draw_horizontal_line(event['baseline'][0] + 20, linestyle='thin,gray') plot.draw_horizontal_line(event['baseline'][1] + 20, linestyle='thin,red!40!black') plot.draw_horizontal_line(event['baseline'][2] + 20, linestyle='thin,green!40!black') plot.draw_horizontal_line(event['baseline'][3] + 20, linestyle='thin,blue!40!black') plot.save_as_pdf('traces_%d_%d' % (station, event['ext_timestamp']))
def plot_integral(trace, baseline): plot = Plot() time = arange(0, len(trace) * 2.5, 2.5) plot.plot(time, trace, mark=None, linestyle='const plot') integral_trace = where(trace > baseline + BASELINE_THRESHOLD, trace, baseline) plot.shade_region(time + 2.5, [baseline] * len(trace), integral_trace, color='lightgray, const plot') plot.draw_horizontal_line(baseline, linestyle='densely dashed, gray') plot.draw_horizontal_line(baseline + BASELINE_THRESHOLD, linestyle='densely dotted, gray') plot.draw_horizontal_line(max(trace), linestyle='densely dashed, gray') # plot.set_ylimits(0) plot.set_xlabel(r'Trace time [\si{\ns}]') plot.set_ylabel(r'Signal strength [ADC]') plot.save_as_pdf('integral')
def plot_pulseintegrals(): station_number = 501 in_bins = linspace(1, 15000, 200) ph_bins = linspace(10, 1500, 200) az_bins = linspace(-pi, pi, 40) ze_bins = linspace(0, pi / 2., 50) min_n = 1.5 max_zenith = radians(45) with tables.open_file(STATION_PATH, 'r') as data: sn = data.get_node('/s%d' % station_number) n_filter = set( sn.events.get_where_list( '(n1 >= min_n) & (n2 >= min_n) & (n4 >= min_n)')) z_filter = set( sn.reconstructions.get_where_list( '(zenith < max_zenith) & d1 & d2 & d4')) filter = list(n_filter & z_filter) integrals = sn.events.col('integrals')[filter] pulseheights = sn.events.col('pulseheights')[filter] azimuths = sn.reconstructions.col('azimuth')[filter] zeniths = sn.reconstructions.col('zenith')[filter] plot = Plot() counts, az_bins = histogram(azimuths, bins=az_bins) plot.histogram(counts, az_bins) # Smoothed version of azimuth histogram to counter discreteness at low zenith. smoothing = normal(scale=radians(8), size=len(azimuths)) counts, az_bins = histogram(norm_angle(azimuths + smoothing), bins=az_bins) plot.histogram(counts, az_bins, linestyle='gray') plot.draw_horizontal_line(mean(counts), linestyle='red') plot.draw_horizontal_line(mean(counts) + sqrt(mean(counts)), linestyle='dashed, red') plot.draw_horizontal_line(mean(counts) - sqrt(mean(counts)), linestyle='dashed, red') plot.set_ylimits(min=0) plot.set_xlimits(-pi, pi) plot.save_as_pdf('azimuth') plot = Plot() counts, ze_bins = histogram(zeniths, bins=ze_bins) plot.histogram(counts, ze_bins) plot.set_ylimits(min=0) plot.set_xlimits(0, pi / 2) plot.save_as_pdf('zeniths') for i in range(4): plot = Plot('semilogy') counts, in_bins = histogram(integrals[:, i], bins=in_bins) plot.histogram(counts, in_bins) counts, in_bins = histogram(integrals[:, i] * cos(zeniths), bins=in_bins) plot.histogram(counts, in_bins, linestyle='red') plot.set_ylimits(min=1) plot.save_as_pdf('integrals_%d' % i) plot = Plot('semilogy') counts, ph_bins = histogram(pulseheights[:, i], bins=ph_bins) plot.histogram(counts, ph_bins) counts, ph_bins = histogram(pulseheights[:, i] * cos(zeniths), bins=ph_bins) plot.histogram(counts, ph_bins, linestyle='red') plot.set_ylimits(min=1) plot.save_as_pdf('pulseheights_%d' % i)
def plot_thickness(seed): plot = Plot('semilogx') plot2 = Plot('loglog') data_path = os.path.join(LOCAL_STORE, seed, 'corsika.h5') with tables.open_file(data_path) as data: particles = data.get_node('/groundparticles') header = data.get_node_attr('/', 'event_header') end = data.get_node_attr('/', 'event_end') time_first_interaction = (header.first_interaction_altitude - header.observation_heights[0]) / .2998 core_distances = logspace(0, 4, 31) min_t = [] lower_t = [] low_t = [] median_t = [] high_t = [] higher_t = [] max_t = [] distances = [] density = [] xerr = [] yerr = [] for r_inner, r_outer in zip(core_distances[:-1], core_distances[1:]): t = particles.read_where('(r >= %f) & (r <= %f) & ' '(particle_id >= 2) & (particle_id <= 6)' % (r_inner, r_outer), field='t') if len(t) < 1: continue area = area_between(r_outer, r_inner) density.append(len(t) / area) distances.append((r_outer + r_inner) / 2) # distances.append(10**((log10(r_outer) + log10(r_inner)) / 2)) yerr.append(sqrt(len(t)) / area) xerr.append((r_outer - r_inner) / 2) percentiles_t = percentile(t, [0, 50]) ref_t, med_t = percentiles_t - time_first_interaction min_t.append(ref_t) # lower_t.append(lsig2_t) # low_t.append(lsig1_t) median_t.append(med_t) # high_t.append(hsig1_t) # higher_t.append(hsig2_t) # max_t.append(m_t) energy = log10(header.energy) shower_size = log10(end.n_electrons_levels + end.n_muons_levels) plot.set_label('E=$10^{%.1f}$eV, size=$10^{%.1f}$' % (energy, shower_size), location='upper left') plot.plot(distances, median_t, mark=None) plot.plot(distances, min_t, linestyle='dashed', mark=None) plot.draw_horizontal_line(1500) plot.set_xlimits(min=.5, max=1e4) plot.set_xlabel(r'core distance [m]') plot.set_ylabel(r'time after first [ns]') plot.set_ylimits(min=-10, max=1000) plot.save_as_pdf('plots/%.1f_%.1f_%s_front.pdf' % (energy, shower_size, seed)) plot2.set_xlimits(min=.5, max=1e5) plot2.set_xlabel(r'core distance') plot2.set_ylabel(r'particle density') plot2.plot(distances, density, xerr=xerr, yerr=yerr, mark=None, markstyle='transparent', linestyle=None) plot2.draw_horizontal_line(2.46) # plot2.draw_horizontal_line(0.6813) plot2.save_as_pdf('plots/%.1f_%.1f_%s_dens.pdf' % (energy, shower_size, seed))