def energy_results(dl2_data, points_outfile=None, plot_outfile=None): """ Plot energy resolution, energy bias and energy migration matrix in the same figure Parameters ---------- dl2_data: `pandas.DataFrame` dl2 MC gamma data - must include the columns `mc_energy` and `reco_energy` points_outfile: None or str if specified, save the resolution and bias in hdf5 format plot_outfile: None or str if specified, save the figure Returns ------- fig, axes: `matplotlib.pyplot.figure`, `matplotlib.pyplot.axes` """ fig, axes = plt.subplots(2, 2, figsize=(12, 8)) ctaplot.plot_energy_resolution(dl2_data.mc_energy.values * u.TeV, dl2_data.reco_energy.values * u.TeV, ax=axes[0, 0], bias_correction=False) ctaplot.plot_energy_resolution_cta_requirement('north', ax=axes[0, 0], color='black') ctaplot.plot_energy_bias(dl2_data.mc_energy.values * u.TeV, dl2_data.reco_energy.values * u.TeV, ax=axes[1, 0]) ctaplot.plot_migration_matrix(dl2_data.mc_energy.apply(np.log10), dl2_data.reco_energy.apply(np.log10), ax=axes[0, 1], colorbar=True, xy_line=True, hist2d_args=dict(norm=matplotlib.colors.LogNorm()), line_args=dict(color='black'), ) axes[0, 0].legend() axes[0, 1].set_xlabel('log(mc energy/[TeV])') axes[0, 1].set_ylabel('log(reco energy/[TeV])') axes[0, 0].set_title("") axes[0, 0].label_outer() axes[1, 0].set_title("") axes[1, 0].set_ylabel("Energy bias") for ax in axes.ravel(): ax.grid(True, which='both') axes[1, 1].remove() fig.tight_layout() if points_outfile: e_bins, e_res = ctaplot.energy_resolution_per_energy(dl2_data.mc_energy.values * u.TeV, dl2_data.reco_energy.values * u.TeV) e_bins, e_bias = ctaplot.energy_bias(dl2_data.mc_energy.values * u.TeV, dl2_data.reco_energy.values * u.TeV) write_energy_resolutions(points_outfile, e_bins, e_res, e_bias) if plot_outfile: fig.savefig(plot_outfile) return fig, axes
def plot_impact_y_matrix(self, ax=None, colorbar=True): """ Plot the diffusion matrix (reco vs simu) for the log of the energies of the experiment Args ax (`matplotlib.pyplot.Axes`) Returns `matplotlib.pyplot.Axes` """ ax = plt.gca() if ax is None else ax if self.get_loaded(): mc = self.gamma_data.mc_impact_y reco = self.gamma_data.reco_impact_y ax = ctaplot.plot_migration_matrix(mc, reco, ax=ax, colorbar=colorbar, hist2d_args={ 'bins': 100, 'cmap': self.cm, 'cmin': 1 }) ax.plot(mc, mc, color='teal') ax.axis('equal') ax.set_xlim(mc.min(), mc.max()) ax.set_ylim(mc.min(), mc.max()) ax.set_xlabel('True impact Y') ax.set_ylabel('Reco impact Y') ax.set_title(self.name) return ax
np.pi*(simu_info.max_scatter_range.to(u.m)**2-simu_info.min_scatter_range.to(u.m)**2).value, label = 'lstchain specific selection' ) print(simu_info.spectral_index) ctaplot.plot_effective_area_cta_performance('north', color='black') plt.legend(fontsize=18) plt.grid() plt.tight_layout() pp.savefig() plt.close() fig, axes = plt.subplots(1, 2, figsize=(15,6)) fig.suptitle(p) ctaplot.plot_migration_matrix(hipe.log_mc_energy, hipe.log_reco_energy, ax=axes[0]) ctaplot.plot_migration_matrix(lst.log_mc_energy, lst.log_reco_energy, ax=axes[1]) for ax in axes: ax.set_xlabel('log_mc_energy') ax.set_ylabel('log_reco_energy') axes[0].set_title('hipecta') axes[1].set_title('lstchain') plt.tight_layout() pp.savefig() plt.close() for feature in ['alt', 'az']: fig, axes = plt.subplots(1, 2, figsize=(15,6)) fig.suptitle(p) ctaplot.plot_migration_matrix(hipe[f'mc_{feature}'], hipe[f'reco_{feature}'], ax=axes[0]) ctaplot.plot_migration_matrix(lst[f'mc_{feature}'], lst[f'reco_{feature}'], ax=axes[1])
def direction_results(dl2_data, points_outfile=None, plot_outfile=None): """ Parameters ---------- dl2_data: `pandas.DataFrame` points_outfile: None or str filename to save angular resolution data points plot_outfile: None or str filename to save the figure Returns ------- fig, axes: `matplotlib.pyplot.figure`, `matplotlib.pyplot.axes` """ fig, axes = plt.subplots(2, 2, figsize=(15, 12)) ax = ctaplot.plot_theta2( dl2_data.reco_alt, dl2_data.reco_az, dl2_data.mc_alt, dl2_data.mc_az, ax=axes[0, 0], bins=100, range=(0, 1), ) ax.grid() ctaplot.plot_angular_resolution_per_energy( dl2_data.reco_alt, dl2_data.reco_az, dl2_data.mc_alt, dl2_data.mc_az, dl2_data.reco_energy, ax=axes[0, 1], ) ctaplot.plot_angular_resolution_cta_requirement('north', ax=axes[0, 1], color='black') axes[0, 1].grid() axes[0, 1].legend() ctaplot.plot_migration_matrix( dl2_data.mc_alt, dl2_data.reco_alt, ax=axes[1, 0], colorbar=True, xy_line=True, hist2d_args=dict(norm=matplotlib.colors.LogNorm()), line_args=dict(color='black'), ) axes[1, 0].set_xlabel('simu alt [rad]') axes[1, 0].set_ylabel('reco alt [rad]') ctaplot.plot_migration_matrix( dl2_data.mc_az, dl2_data.reco_az, ax=axes[1, 1], colorbar=True, xy_line=True, hist2d_args=dict(norm=matplotlib.colors.LogNorm()), line_args=dict(color='black'), ) axes[1, 1].set_xlabel('simu az [rad]') axes[1, 1].set_ylabel('reco az [rad]') fig.tight_layout() if points_outfile: e_bins, ang_res = ctaplot.angular_resolution_per_energy( dl2_data.reco_alt, dl2_data.reco_az, dl2_data.mc_alt, dl2_data.mc_az, dl2_data.reco_energy, ) write_angular_resolutions(points_outfile, e_bins * u.TeV, ang_res * u.rad) if plot_outfile: fig.savefig(plot_outfile) return fig, axes