def plot_energy_resolution_hdf(gamma_filename, ax=None, **kwargs): """ Plot angular resolution from an IRF file Parameters ---------- irf_filename ax kwargs Returns ------- """ data = pd.read_hdf(gamma_filename) ax = ctaplot.plot_angular_resolution_cta_performance('north', color='black', label='CTA North', ax=ax) ax = ctaplot.plot_energy_resolution(data.mc_energy, data.reco_energy, ax=ax, **kwargs) ax.grid(which='both') ax.set_title('Energy resoluton', fontsize=18) ax.legend() return ax
def plot_angular_resolution(irf_filename, ax=None, **kwargs): """ Plot angular resolution from an IRF file Parameters ---------- irf_filename ax kwargs Returns ------- """ ax = ctaplot.plot_angular_resolution_cta_performance('north', color='black', ax=ax) with fits.open(irf_filename) as irf: psf_hdu = irf['POINT SPREAD FUNCTION'] e_lo = psf_hdu.data['ENERG_LO'] e_hi = psf_hdu.data['ENERG_HI'] energy = (e_lo + e_hi) / 2. psf = psf_hdu.data['PSF68'] if 'fmt' not in kwargs: kwargs['fmt'] = 'o' ax.errorbar(energy, psf, xerr=(e_hi - e_lo) / 2., **kwargs, ) ax.legend(fontsize=17) ax.grid(which='both') return ax
def plot_comparison(filelist, outfile=None, cta_north=False): """ Create a 2x2 plot comparing different sensitivity curves Parameters ---------- filelist: list File list with sensitivity curves to be compared. outfile: str or Path or None path to the output file to be saved. if None, the figure is not saved cta_north: Bool Flag to superpose/add (True) or not (False - Default) the CTA North. Imported from ctaplot """ logging.basicConfig(level=logging.INFO) log = logging.getLogger("lstchain MC DL2 to IRF - sensitivity curves") log.info("Starting lstmcpipe compare irfs script") fig, axes = plt.subplots(2, 2, figsize=(15, 10)) for file in filelist: log.info(f"Plotting IRFs from file {file}") label = os.path.basename(file) plot_summary_from_file(file, axes=axes, label=label) if cta_north: ctaplot.plot_sensitivity_cta_performance('north', ax=axes.ravel()[0]) ctaplot.plot_angular_resolution_cta_performance('north', ax=axes.ravel()[1]) ctaplot.plot_energy_resolution_cta_performance('north', ax=axes.ravel()[2]) ctaplot.plot_effective_area_cta_performance('north', ax=axes.ravel()[3]) fig.tight_layout() if outfile is not None: fig.savefig(outfile, dpi=200, bbox_inches='tight') else: fig.show() return axes
def create_resolution_fig(site='south', ref=None): """ Create the figure holding the resolution plots for the dashboard axes = [[ax_ang_res, ax_ene_res],[ax_imp_res, None]] Args site (string) Returns fig, axes """ fig, axes = plt.subplots(3, 2, figsize=(12, 12)) ax_ang_res = axes[0][0] ax_ene_res = axes[0][1] ax_imp_res = axes[1][0] ax_eff_area = axes[1][1] ax_roc = axes[2][0] ax_legend = axes[2][1] if ref == 'performances': ctaplot.plot_angular_resolution_cta_performance(site, ax=ax_ang_res, color='black') ctaplot.plot_energy_resolution_cta_performance(site, ax=ax_ene_res, color='black') ctaplot.plot_effective_area_cta_performance(site, ax=ax_eff_area, color='black') elif ref == 'requirements': ctaplot.plot_angular_resolution_cta_requirement(site, ax=ax_ang_res, color='black') ctaplot.plot_energy_resolution_cta_requirement(site, ax=ax_ene_res, color='black') ctaplot.plot_effective_area_cta_requirement(site, ax=ax_eff_area, color='black') else: ax_eff_area.set_xscale('log') ax_eff_area.set_yscale('log') ax_eff_area.set_xlabel('Energy [TeV]') if ref is not None: ax_ang_res.legend() ax_ene_res.legend() ax_eff_area.legend() ax_roc.plot([0, 1], [0, 1], linestyle='--', color='r', alpha=.5) ax_roc.set_xlim([-0.05, 1.05]) ax_roc.set_ylim([-0.05, 1.05]) ax_roc.set_xlabel('False Positive Rate') ax_roc.set_ylabel('True Positive Rate') ax_roc.set_title('Receiver Operating Characteristic') # ax_roc.axis('equal') ax_legend.set_axis_off() fig.tight_layout() for ax in fig.get_axes(): for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()): item.set_fontsize(10) return fig, axes
gamma = pd.read_hdf(args.gamma_file, key=dl2_params_lstcam_key) selection = (gamma.intensity > 200) & (gamma.leakage < 0.2) & (gamma.gammaness > 0.5) selected_gamma = gamma[selection] plot_histograms(gamma, save_dir=os.path.join(args.outdir, 'hist'), bins=100) fig = plot_binned_stat_grid(gamma, 'log_mc_energy', errorbar=True) fig.savefig(os.path.join(args.outdir, f'means_per_energy.png')) fig, ax = plt.subplots(figsize=(10, 7)) ax = ctaplot.plot_angular_resolution_cta_performance('north', color='black', ax=ax) ax = ctaplot.plot_angular_resolution_per_energy( gamma.reco_alt, gamma.reco_az, gamma.mc_alt, gamma.mc_az, gamma.reco_energy, ax=ax, label='all gammas', ) ax = ctaplot.plot_angular_resolution_per_energy(selected_gamma.reco_alt, selected_gamma.reco_az, selected_gamma.mc_alt, selected_gamma.mc_az, selected_gamma.reco_energy,
if __name__ == "__main__": gamma = pd.read_hdf(args.gamma_file, key=dl2_params_lstcam_key) selection = ( (gamma.intensity > 200) & (gamma.leakage < 0.2) & (gamma.gammaness > 0.5) ) selected_gamma = gamma[selection] plot_histograms(gamma, save_dir=os.path.join(args.outdir, "hist"), bins=100) fig = plot_binned_stat_grid(gamma, "log_mc_energy", errorbar=True) fig.savefig(os.path.join(args.outdir, "means_per_energy.png")) fig, ax = plt.subplots(figsize=(10, 7)) ax = ctaplot.plot_angular_resolution_cta_performance("north", color="black", ax=ax) ax = ctaplot.plot_angular_resolution_per_energy( gamma.reco_alt, gamma.reco_az, gamma.mc_alt, gamma.mc_az, gamma.reco_energy, ax=ax, label="all gammas", ) ax = ctaplot.plot_angular_resolution_per_energy( selected_gamma.reco_alt, selected_gamma.reco_az, selected_gamma.mc_alt, selected_gamma.mc_az, selected_gamma.reco_energy,