Modules
plots.py
Functions to make IRF and other reconstruction quality-check plots
- ctaplot.plots.plots.plot_angular_resolution_cta_performance(cta_site, ax=None, **kwargs)[source]
Plot the official CTA performances (June 2018) for the angular resolution
- Parameters:
cta_site (string) – see ana.cta_performance
ax (matplotlib.pyplot.axes) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_angular_resolution_cta_requirement(cta_site, ax=None, **kwargs)[source]
Plot the CTA requirement for the angular resolution :param cta_site: see ctaplot.ana.cta_requirement :type cta_site: string :param ax: :type ax: matplotlib.pyplot.axes :param kwargs: :type kwargs: args for matplotlib.pyplot.plot
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_angular_resolution_per_energy(true_alt, reco_alt, true_az, reco_az, true_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, ax=None, bins=None, **kwargs)[source]
Plot the angular resolution as a function of the reconstructed true_energy
- Parameters:
reco_alt (astropy.Quantity) – array of reconstructed altitudes in radians
reco_az (astropy.Quantity) – array of reconstructed azimuths in radians
true_alt (astropy.Quantity) – array of true altitudes in radians
true_az (astropy.Quantity) – array of true azimuths in radians
reco_energy (astropy.Quantity) – array of energy in TeV
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_angular_resolution_per_off_pointing_angle(true_alt, reco_alt, true_az, reco_az, alt_pointing, az_pointing, res_unit=Unit('deg'), bins=10, ax=None, **kwargs)[source]
Plot the angular resolution as a function of the angular separation between events true position and the pointing direction. Angles must be given in radians.
- Parameters:
true_alt (numpy.ndarray) –
true_az (numpy.ndarray) –
reco_alt (numpy.ndarray) –
reco_az (numpy.ndarray) –
alt_pointing (numpy.ndarray) –
az_pointing (numpy.ndarray) –
res_degree (bool) – if True, the angular resolution is computed in degrees.
bins (int or numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_background_rate(e_min, e_max, background_rate, background_rate_err=None, ax=None, **kwargs)[source]
Plot the background rate [Hz] as a function of the true_energy [TeV]
- Parameters:
e_min (numpy.ndarray) – Reconstructed true_energy in TeV
e_max (numpy.ndarray) – Reconstructed true_energy in TeV
background_rate (astropy.Quantity) – Background rate in Hz
background_rate_err (astropy.Quantity) – error bar on the rate, either either 1D (symmetrical) or 2D
ax (matplotlib.pyplot.axis) –
kwargs (kwargs for matplotlib.pyplot.errobar) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_background_rate_magic(ax=None, **kwargs)[source]
Plot the MAGIC background rate from Aleksić, Jelena, et al. 2016, DOI: 10.1016/j.astropartphys.2015.02.005
- Parameters:
ax (matplotlib.pyplot.axis or None) –
kwargs (kwargs for ctaplot.plots.plot_background_rate) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_bias_per_energy(simu, reco, energy, relative_scaling_method=None, ax=None, bins=None, **kwargs)[source]
Plot the bias per bins of true_energy
- Parameters:
simu (numpy.ndarray) –
reco (numpy.ndarray) –
energy (astropy.Quantity) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
ax (matplotlib.pyplot.axis) –
bins (astropy.Quantity) –
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_binned_bias(simu, reco, x, relative_scaling_method=None, ax=None, bins=10, log=False, **kwargs)[source]
Plot the bias between true and reco as a function of bins of x
- Parameters:
simu (numpy.ndarray) –
reco (numpy.ndarray) –
x (numpy.ndarray) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
ax (matplotlib.pyplot.axis) –
bins (bins for numpy.histogram) –
log (bool) – if True, logscale is applied to the x axis
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_binned_stat(x, y, statistic='mean', bins=20, errorbar=False, percentile=68.27, line=True, ax=None, **kwargs)[source]
Plot statistics on the quantity y binned following the quantity x. The statistic can be given by a string (‘mean’, ‘sum’, ‘max’…) or a function. See scipy.stats.binned_statistic. Errorbars may be added and represents the dispersion (given by the percentile option) of the y distribution around the measured value in a bin. These error bars might not make sense for some statistics, it is left to the user to use the function responsibly.
- Parameters:
x (numpy.ndarray) –
y (numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
errorbar (bool) –
statistic (string or callable - see scipy.stats.binned_statistic) –
bins (bins for scipy.stats.binned_statistic) –
kwargs (if errorbar: kwargs for matplotlib.pyplot.hlines else: kwargs for matplotlib.pyplot.plot) –
- Return type:
matplotlib.pyplot.axes
Examples
>>> from ctaplot.plots import plot_binned_stat >>> import numpy as np >>> x = np.random.rand(1000) >>> y = x**2 >>> plot_binned_stat(x, y, statistic='median', bins=40, percentile=95, line=False, color='red', errorbar=True, s=0)
- ctaplot.plots.plots.plot_dispersion(true_x, reco_x, x_log=False, ax=None, **kwargs)[source]
Plot the dispersion around an expected value X_true: (true_x-reco_x) as a function of true_x
- Parameters:
true_x (numpy.ndarray) – true value of a variable x
reco_x (numpy.ndarray) – reconstructed value of a variable x
x_log (bool) – if True, the dispersion is plotted as a function of log10(true_x)
ax (matplotlib.pyplot.axes) –
kwargs (args for matplotlib.pyplot.hist2d) –
- Returns:
ax
- Return type:
maptlotlib.pyplot.axes
- ctaplot.plots.plots.plot_effective_area_cta_performance(cta_site, ax=None, **kwargs)[source]
Plot the CTA performances for the effective area as a function of the true true_energy
- Parameters:
cta_site (string) – see ctaplot.ana.cta_requirement
ax (matplotlib.pyplot.axes) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_effective_area_cta_requirement(cta_site, ax=None, **kwargs)[source]
Plot the CTA requirement for the effective area as a function of the true true_energy
- Parameters:
cta_site (string) – see ctaplot.ana.cta_requirement
ax (matplotlib.pyplot.axes) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_effective_area_per_energy(true_energy, reco_energy, simulated_area, ax=None, bins=None, **kwargs)[source]
Plot the effective area as a function of the true true_energy
- Parameters:
true_energy (astropy.Quantity) – all simulated event energy
reco_energy (astropy.Quantity) – all reconstructed event energy
simulated_area (astropy.Quantity) –
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (options for maplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
Example
>>> import numpy as np >>> import ctaplot >>> irf = ctaplot.ana.irf_cta() >>> true_e = 10**(-2 + 4*np.random.rand(1000)) * u.TeV >>> reco_e = 10**(-2 + 4*np.random.rand(100)) * u.TeV >>> ax = ctaplot.plots.plot_effective_area_per_energy(true_e, reco_e, irf.LaPalmaArea_prod3)
- ctaplot.plots.plots.plot_effective_area_per_energy_power_law(emin, emax, total_number_events, spectral_index, true_energy, simu_area, ax=None, bins=None, **kwargs)[source]
Plot the effective area as a function of the true true_energy. The effective area is computed using the ctaplot.ana.effective_area_per_energy_power_law.
- Parameters:
emin (astropy.Quantity) – min simulated true_energy
emax (astropy.Quantity) – max simulated true_energy
total_number_events (int) – total number of simulated events
spectral_index (float) – spectral index of the simulated power-law
true_energy (astropy.Quantity) – array of reconstructed events’ true energy
simu_area (astropy.Quantity) – simulated core area
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_energy_bias(true_energy, reco_energy, ax=None, bins=None, **kwargs)[source]
Plot the true_energy bias
- Parameters:
true_energy (astropy.Quantity) –
reco_energy (astropy.Quantity) –
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_energy_distribution(true_energy, reco_energy, bins=10, ax=None, outfile=None, mask_mc_detected=True)[source]
Plot the true_energy distribution of the simulated particles, detected particles and reconstructed particles The plot might be saved automatically if outfile is provided.
- Parameters:
true_energy (astropy.Quantity) – array of simulated energy
reco_energy (astropy.Quantity) – array of reconstructed energy
bins (int or numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
outfile (string) – output file path
mask_mc_detected (numpy.ndarray) – mask of detected particles for the SimuE array if True (default), no mask is applied
- ctaplot.plots.plots.plot_energy_resolution(true_energy, reco_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, ax=None, bins=None, **kwargs)[source]
Plot the enregy resolution as a function of the true_energy
- Parameters:
true_energy (astropy.Quantity) –
reco_energy (astropy.Quantity) –
ax (matplotlib.pyplot.axes) –
bias_correction (bool) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_energy_resolution_cta_performance(cta_site, ax=None, **kwargs)[source]
Plot the cta performances (June 2018) for the true_energy resolution
- Parameters:
cta_site (string) – see ctaplot.ana.cta_performance
ax (matplotlib.pyplot.axes) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_energy_resolution_cta_requirement(cta_site, ax=None, **kwargs)[source]
Plot the cta requirement for the true_energy resolution
- Parameters:
cta_site (string) – see ana.cta_requirement
ax (matplotlib.pyplot.axes) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_feature_importance(feature_keys, feature_importances, ax=None, **kwargs)[source]
Plot features importance after model training (typically from scikit-learn)
- Parameters:
feature_keys (list of string) –
feature_importances (numpy.ndarray or list) –
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for matplotlib.pyplot.bar) –
- Return type:
ax
- ctaplot.plots.plots.plot_gamma_rate(e_min, e_max, gamma_rate, gamma_rate_err=None, ax=None, **kwargs)[source]
Plot the gamma rate [Hz] as a function of the true_energy [TeV]
- Parameters:
e_min (numpy.ndarray) – Reconstructed true_energy in TeV
e_max (numpy.ndarray) – Reconstructed true_energy in TeV
gamma_rate (astropy.Quantity) – gamma rate in Hz
gamma_rate_err (astropy.Quantity) – error bar on the rate, either either 1D (symmetrical) or 2D
ax (matplotlib.pyplot.axis) –
kwargs (kwargs for matplotlib.pyplot.errobar) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_gamma_rate_magic(ax=None, **kwargs)[source]
Plot the MAGIC gamma rate from Aleksić, Jelena, et al. 2016, DOI: 10.1016/j.astropartphys.2015.02.005
- Parameters:
ax (matplotlib.pyplot.axis or None) –
kwargs (kwargs for ctaplot.plots.plot_gamma_rate) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_gammaness_distribution(mc_type, gammaness, ax=None, **kwargs)[source]
Plot the distribution of gammaness based on mc_type
- Parameters:
mc_type (numpy.ndarray) – true labeling
gammaness (numpy.ndarray) – reconstructed gammaness
ax (matplotlib.pyplot.axes) –
kwargs (args for matplotlib.pyplot.hist) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_gammaness_threshold_efficiency(gammaness, efficiency, ax=None, **kwargs)[source]
Plot the cumulative histogram of the gammaness with the threshold to obtain a give efficiency. See also ctaplot.ana.gammaness_threshold_efficiency.
- Parameters:
gammaness (numpy.ndarray) – gammaness of true events (e.g. gammas)
efficiency (float) – between 0 and 1
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for matplotlib.pyplot.hist) –
- Returns:
ax: matplotlib.pyplot.axes threshold: float
- Return type:
ax, threshold
- ctaplot.plots.plots.plot_impact_map(impact_x, impact_y, tel_x, tel_y, tel_types=None, ax=None, outfile=None, hist_kwargs=None, scatter_kwargs=None)[source]
Map of the site with telescopes positions and impact points heatmap
- Parameters:
impact_x (astropy.Quantity) –
impact_y (astropy.Quantity) –
tel_x (astropy.Quantity) –
tel_y (astropy.Quantity) –
tel_types (numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
hist_kwargs (kwargs for matplotlib.pyplot.hist) –
scatter_kwargs (kwargs for matplotlib.pyplot.scatter) –
(optional) (outfile) –
- ctaplot.plots.plots.plot_impact_parameter_error_site_center(true_x, reco_x, true_y, reco_y, ax=None, **kwargs)[source]
Plot the impact parameter error as a function of the distance to the site center.
- Parameters:
reco_x (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_x (astropy.Quantity) –
true_y (astropy.Quantity) –
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for matplotlib.pyplot.hist2d) –
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_impact_parameter_resolution_per_bin(x, true_x, reco_x, true_y, reco_y, bins=10, ax=None, **kwargs)[source]
Plot the impact parameter error per bin
- Parameters:
x (numpy.ndarray) –
reco_x (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_x (astropy.Quantity) –
true_y (astropy.Quantity) –
bins (arg for np.histogram) –
ax (matplotlib.pyplot.axes) –
kwargs (args for plot_resolution) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_impact_parameter_resolution_per_energy(true_x, reco_x, true_y, reco_y, true_energy, ax=None, bins=None, **kwargs)[source]
- Parameters:
true_x (astropy.Quantity) –
reco_x (astropy.Quantity) –
true_y (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_energy (astropy.Quantity) –
ax (matplotlib.pyplot.axes) –
bins (astropy.Quantity) –
kwargs (args for ctaplot.plots.plot_resolution) –
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_impact_point_heatmap(reco_x, reco_y, ax=None, outfile=None, **kwargs)[source]
Plot the heatmap of the impact points on the site ground and save it under outfile
- Parameters:
reco_x (astropy.Quantity) – reconstructed x positions
reco_y (astropy.Quantity) – reconstructed y positions
ax (matplotlib.pyplot.axes) –
outfile (string) – path to the output file. If None, the figure is not saved.
- ctaplot.plots.plots.plot_impact_resolution_per_energy(true_x, reco_x, true_y, reco_y, true_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, ax=None, bins=None, **kwargs)[source]
Plot the impact resolution as a function of the true_energy
- Parameters:
reco_x (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_x (astropy.Quantity) –
true_y (astropy.Quantity) –
true_energy (numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_layout_map(tel_x, tel_y, tel_type=None, ax=None, **kwargs)[source]
Plot the layout map of telescopes positions
- Parameters:
tel_x (astropy.Quantity) – telescopes x positions
tel_y (astropy.Quantity) – telescopes y positions
tel_type (numpy.ndarray) – telescopes types
ax (matplotlib.pyplot.axes) – optional
kwargs – options for matplotlib.pyplot.scatter
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_migration_matrix(x, y, ax=None, colorbar=False, xy_line=False, hist2d_args=None, line_args=None)[source]
Make a simple plot of a migration matrix
- Parameters:
x (list or numpy.ndarray) –
y (list or numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
colorbar (bool) –
hist2d_args (dict, args for matplotlib.pyplot.hist2d) –
line_args (dict, args for matplotlib.pyplot.plot) –
- Return type:
matplotlib.pyplot.axes
Examples
>>> from ctaplot.plots import plot_migration_matrix >>> import matplotlib >>> x = np.random.rand(10000) >>> y = x**2 >>> plot_migration_matrix(x, y, colorbar=True, hist2d_args=dict(norm=matplotlib.colors.LogNorm())) In this example, the colorbar will be log normed
- ctaplot.plots.plots.plot_multiplicity_hist(multiplicity, ax=None, outfile=None, quartils=False, **kwargs)[source]
Histogram of the telescopes multiplicity
- Parameters:
multiplicity (numpy.ndarray) –
ax (matplotlib.pyplot.axes) –
outfile (string) –
**kwargs (args for matplotlib.pyplot.bar) –
- ctaplot.plots.plots.plot_multiplicity_per_energy(energy, multiplicity, bins=10, ax=None, outfile=None, **kwargs)[source]
Plot the telescope multiplicity as a function of the true_energy The plot might be saved automatically if outfile is provided.
- Parameters:
multiplicity (numpy.ndarray) – telescope multiplcity
energy (numpy.ndarray) – event energies
ax (matplotlib.pyplot.axes) –
outfile (string) – path to the output file to save the figure
- ctaplot.plots.plots.plot_precision_recall(y_true, proba_pred, pos_label=0, sample_weigth=None, threshold=None, ax=None, **kwargs)[source]
Precision as a function of recall.
- Parameters:
y_true (ndarray of shape (n_samples,)) – True binary labels. If labels are not either {-1, 1} or {0, 1}, then pos_label should be explicitly given.
proba_pred (ndarray of shape (n_samples,)) – Estimated probabilities or output of a decision function.
pos_label (int or str, default=0) – The label of the positive class. The default is 0 for gammas’. When
pos_label=None
, if y_true is in {-1, 1} or {0, 1},pos_label
is set to 1, otherwise an error will be raised.sample_weigth (array-like of shape (n_samples,), default=None) – Sample weights.
threshold (float) – between 0 and 1. Add a point on the curve corresponding to the given threshold.
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for sklearn.metrics.PrecisionRecallDisplay) –
- Returns:
display
- Return type:
sklearn.metrics.PrecisionRecallDisplay
- ctaplot.plots.plots.plot_rate(e_min, e_max, rate, rate_err=None, ax=None, **kwargs)[source]
Plot the background rate [Hz] as a function of the true_energy [TeV]
- Parameters:
e_min (astropy.Quantity) – Reconstructed true_energy in TeV
e_max (astropy.Quantity) – Reconstructed true_energy in TeV
rate (astropy.Quantity) – rate in Hz
rate_err (astropy.Quantity) – error bar on the rate, either 1D (symmetrical) or 2D
ax (matplotlib.pyplot.axis) –
kwargs (kwargs for matplotlib.pyplot.errobar) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_resolution(bins, res, log=False, ax=None, **kwargs)[source]
Plot the passed resolution.
- Parameters:
bins (1D numpy.ndarray) –
res (2D numpy.ndarray - output from ctpalot.ana.resolution) – res[:,0]: resolution res[:,1]: lower confidence limit res[:,2]: upper confidence limit
log (bool) – if true, x is logscaled
ax (matplotlib.pyplot.axes) –
kwargs (kwargs for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_resolution_difference(bins, reference_resolution, new_resolution, ax=None, **kwargs)[source]
Plot the algebric difference between a new resolution and reference resolution.
- Parameters:
bins (numpy.ndarray) –
reference_resolution (numpy.ndarray) – output from ctaplot.ana.resolution
new_resolution (numpy.ndarray) – output from ctaplot.ana.resolution
ax (matplotlib.pyplot.axis) –
kwargs (args for ctaplot.plots.plot_resolution) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_resolution_per_energy(true, reco, energy, ax=None, bins=None, **kwargs)[source]
Plot a variable resolution as a function of the true_energy
- Parameters:
reco (numpy.ndarray) – reconstructed values of a variable
true (numpy.ndarray) – true values of the variable
energy (astropy.Quantity) – event energy in TeV
ax (matplotlib.pyplot.axes) –
bins (numpy.ndarray) –
kwargs (args for matplotlib.pyplot.errorbar) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_roc_auc_per_energy(energy_bins, auc_scores, ax=None, **kwargs)[source]
Plot AUC scores as a function of the energy. These can be computed thanks to ctaplot.ana.auc_per_energy
- Parameters:
energy_bins (numpy.ndarray) –
auc_scores (numpy.ndarray) –
ax (matplotlib.pyplot.axes or None) –
kwargs (options for matplotlib.pyplot.errorbar) –
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_roc_curve(true_type, reco_proba, pos_label=None, sample_weight=None, drop_intermediate=True, ax=None, **kwargs)[source]
- Parameters:
true_type (numpy.ndarray) – true labels: must contain only two labels of type int, float or str
reco_proba (numpy.ndarray) – reconstruction probability, values must be between 0 and 1
pos_label (int or str, default=None) – The label of the positive class. When
pos_label=None
, if y_true is in {-1, 1} or {0, 1},pos_label
is set to 1, otherwise an error will be raised.sample_weight (array-like of shape = [n_samples], optional) – Sample weights.
drop_intermediate (boolean, optional (default=True)) – Whether to drop some suboptimal thresholds which would not appear on a plotted ROC curve. This is useful in order to create lighter ROC curves.
ax (matplotlib.pyplot.axis) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_roc_curve_gammaness(true_type, gammaness, gamma_label=0, sample_weight=None, drop_intermediate=True, ax=None, **kwargs)[source]
- Parameters:
true_type (numpy.ndarray) – true labels: int, float or str
gammaness (numpy.ndarray) – probability of each event to be a gamma, values must be between 0 and 1
gamma_label (the label of the gamma class in true_type.) –
sample_weight (array-like of shape = [n_samples], optional) – Sample weights.
drop_intermediate (boolean, optional (default=True)) – Whether to drop some suboptimal thresholds which would not appear on a plotted ROC curve. This is useful in order to create lighter ROC curves.
ax (matplotlib.pyplot.axis) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_roc_curve_gammaness_per_energy(true_type, gammaness, true_energy, gamma_label=0, energy_bins=None, ax=None, **kwargs)[source]
Plot a gamma ROC curve per gamma true_energy bin.
- Parameters:
true_type (numpy.ndarray) – true labels: int, float or str
gammaness (numpy.ndarray) – probability of each event to be a gamma, values must be between 0 and 1
true_energy (astropy.Quantity) – true_energy of the gamma events in TeV true_energy.shape == true_type.shape (but energy for events that are not gammas are not considered)
gamma_label (the label of the gamma class in true_type.) –
energy_bins (None or int or numpy.ndarray) – bins in true_energy. If energy_bins is None, the default binning given by ctaplot.ana.irf_cta().energy_bin if used. If energy_bins is an int, it defines the number of equal-width energy_bins in the given range. If energy_bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths.
sample_weight (array-like of shape = [n_samples], optional) – Sample weights.
drop_intermediate (boolean, optional (default=True)) – Whether to drop some suboptimal thresholds which would not appear on a plotted ROC curve. This is useful in order to create lighter ROC curves.
ax (matplotlib.pyplot.axis) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_roc_curve_multiclass(true_type, reco_proba, pos_label=None, sample_weight=None, drop_intermediate=True, ax=None, **kwargs)[source]
Plot a ROC curve for a multiclass classification.
- Parameters:
true_type (numpy.ndarray) – true labels: int, float or str
reco_proba (dict of numpy.ndarray of shape (len(true_type), len(set(true_type))) – reconstruction probability for each class in true_type, values must be between 0 and 1
pos_label (int or str, default=None) – The label of the positive class. When
pos_label=None
, the ROC curve of each class is ploted. If pos_label is not None, only the ROC curve of this class is ploted.sample_weight (array-like of shape = [n_samples], optional) – Sample weights.
drop_intermediate (boolean, optional (default=True)) – Whether to drop some suboptimal thresholds which would not appear on a plotted ROC curve. This is useful in order to create lighter ROC curves.
ax (matplotlib.pyplot.axis) –
kwargs (args for matplotlib.pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_sensitivity_cta_performance(cta_site, ax=None, **kwargs)[source]
Plot the CTA performances for the sensitivity
- Parameters:
cta_site (string) – see ctaplot.ana.cta_requirement
ax (matplotlib.pyplot.axes) – optional
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_sensitivity_cta_requirement(cta_site, ax=None, **kwargs)[source]
Plot the CTA requirement for the sensitivity :param cta_site: see ctaplot.ana.cta_requirement :type cta_site: string :param ax: optional :type ax: matplotlib.pyplot.axes
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.plot_sensitivity_magic_performance(key='lima_5off', ax=None, **kwargs)[source]
Plot the MAGIC sensitivity from Aleksić, Jelena, et al. 2016, DOI: 10.1016/j.astropartphys.2015.02.005
- Parameters:
key (string) – ‘lima_1off’: LiMa 1 off position ‘lima_3off’: LiMa 3 off positions ‘lima_5off’: LiMa 5 off positions ‘snr’: Nex/sqrt(Nbkg)
ax (matplotlib.pyplot.axis) –
kwargs (kwargs for matplotlib.pyplot.errorbar) –
- Return type:
matplotlib.pyplot.axis
- ctaplot.plots.plots.plot_theta2(true_alt, reco_alt, true_az, reco_az, bias_correction=False, ax=None, **kwargs)[source]
Plot the theta2 distribution and display the corresponding angular resolution in degrees. The input must be given in radians.
- Parameters:
reco_alt (astropy.Quantity) – reconstructed altitude angle in radians
reco_az (astropy.Quantity) – reconstructed azimuth angle in radians
true_alt (astropy.Quantity) – true altitude angle in radians
true_az (astropy.Quantity) – true azimuth angle in radians
ax (matplotlib.pyplot.axes) –
**kwargs – options for matplotlib.pyplot.hist
- Returns:
ax
- Return type:
matplotlib.pyplot.axes
- ctaplot.plots.plots.scatter_events_field_of_view(reco_alt, reco_az, source_alt, source_az, color_scale=None, ax=None)[source]
Plot a map in angles [in degrees] of the photons seen by the telescope (after reconstruction)
- Parameters:
reco_alt (astropy.Quantity) – array of reconstructed altitudes
reco_az (astropy.Quantity) – array of reconstructed azimuths
source_alt (astropy.Quantity) – single altitude of the source
source_az (astropy.Quantity) – single azimuth of the source
color_scale (numpy.ndarray) – if given, set the colorbar
ax (matplotlib.pyplot.axes) –
outfile (string) – path to the output figure file. if None, the plot is not saved
- Returns:
ax
- Return type:
matplitlib.pyplot.axes
- ctaplot.plots.calib.plot_photoelectron_true_reco(true_pe, reco_pe, bins=200, stat='median', errorbar=True, percentile=68.27, ax=None, hist_args={}, stat_args={}, xy_args={})[source]
Plot the number of reconstructed photo-electrons as a function of the number of true photo-electron
- Parameters:
true_pe (numpy.ndarray) – shape: (n_pixels, )
reco_pe (numpy.ndarray) – shape: (n_pixels, )
bins (int or numpy.ndarray) –
stat (str or None) – ‘mean’, ‘median’, ‘min’, ‘max’. if None, not plotted.
errorbar (bool) – plot the errorbar corresponding to the percentile as colored area around the stat line
percentile (float) – between 0 and 100 percentile for the errorbars
ax (matplotlib.pyplot.axis or None) –
hist_args (args for pyplot.hist2d) –
stat_args (args for ctaplot.plots.plot_binned_stat) –
xy_args (args for pyplot.plot) –
- Returns:
ax
- Return type:
matplotlib.pyplot.axis
Gridded plots
- ctaplot.plots.grid.plot_binned_stat_grid(data, x_col, n_cols=4, **binned_stat_args)[source]
Make a figure with a grid of binned stat plots. All variable in data are plotted versus the x_col variable.
- Parameters:
data (pandas.dataframe) –
x_col (str) – name of the column in the data to consider as X variable.
n_col (int) – number of columns in the plot grid. The number of rows in determined automatically.
binned_stat_args (args for ctaplot.plot.plot_binned_stat) –
- Return type:
matplotlib.figure.Figure
ana.py
Contain mathematical functions to make results analysis (compute angular resolution, effective surface, true_energy resolution… )
- ctaplot.ana.ana.angular_resolution(true_alt, reco_alt, true_az, reco_az, percentile=68.27, confidence_level=0.95, bias_correction=False)[source]
Compute the angular resolution as the Qth (standard being 68) containment radius of theta2 with lower and upper limits on this value corresponding to the confidence value required (1.645 for 95% confidence)
- Parameters:
reco_alt (astropy.Quantity) – reconstructed altitude angle in radians
reco_az (astropy.Quantity) – reconstructed azimuth angle in radians
true_alt (astropy.Quantity) – true altitude angle in radians
true_az (astropy.Quantity) – true azimuth angle in radians
percentile (float - percentile, 68 corresponds to one sigma) –
confidence_level (float) –
- Return type:
numpy.array [angular_resolution, lower limit, upper limit]
- ctaplot.ana.ana.angular_resolution_per_bin(true_alt, reco_alt, true_az, reco_az, x, percentile=68.27, confidence_level=0.95, bias_correction=False, bins=10)[source]
Compute the angular resolution per binning of x
- Parameters:
true_alt (astropy.Quantity) –
true_az (astropy.Quantity) –
reco_alt (astropy.Quantity) –
reco_az (astropy.Quantity) –
x (numpy.ndarray) –
percentile (float) – 0 < percentile < 100
confidence_level (float) – 0 < confidence_level < 1
bias_correction (bool) –
bins (int or numpy.ndarray) –
- Returns:
bins, ang_res
- Return type:
(numpy.ndarray, numpy.ndarray)
- ctaplot.ana.ana.angular_resolution_per_energy(true_alt, reco_alt, true_az, reco_az, energy, percentile=68.27, confidence_level=0.95, bias_correction=False, bins=None)[source]
Plot the angular resolution as a function of the event simulated true_energy
- Parameters:
reco_alt (astropy.Quantity) –
reco_az (astropy.Quantity) –
true_alt (astropy.Quantity) –
true_az (astropy.Quantity) –
energy (astropy.Quantity) –
bins (astropy.Quantity) –
**kwargs (args for angular_resolution) –
- Returns:
(energy, RES)
- Return type:
(astropy.Quantity, numpy.array)
- ctaplot.ana.ana.angular_resolution_per_off_pointing_angle(true_alt, reco_alt, true_az, reco_az, alt_pointing, az_pointing, bins=10)[source]
Compute the angular resolution as a function of separation angle for the pointing direction
- Parameters:
true_alt (astropy.Quantity) –
true_az (astropy.Quantity) –
reco_alt (astropy.Quantity) –
reco_az (astropy.Quantity) –
alt_pointing (astropy.Quantity) –
az_pointing (astropy.Quantity) –
bins (int or astropy.Quantity) –
- Returns:
bins: 1D astropy.Quantity res: 2D numpy.ndarray - resolutions with confidence intervals (output from ctaplot.ana.resolution)
- Return type:
(bins, res)
- ctaplot.ana.ana.angular_separation_altaz(alt1, az1, alt2, az2)[source]
Compute the angular separation in radians or degrees between two pointing direction given with alt-az
- Parameters:
alt1 (1d astropy.Quantity, altitude of the first pointing direction) –
az1 (1d astropy.Quantity azimuth of the first pointing direction) –
alt2 (1d astropy.Quantity, altitude of the second pointing direction) –
az2 (1d astropy.Quantity, azimuth of the second pointing direction) –
- Return type:
1d numpy.ndarray or float, angular separation
- ctaplot.ana.ana.bias(true, reco)[source]
Compute the bias of a reconstructed variable as median(reco-true)
- Parameters:
true (numpy.ndarray) –
reco (numpy.ndarray) –
- Return type:
float
- ctaplot.ana.ana.bias_per_bin(true, reco, x, relative_scaling_method=None, bins=10)[source]
Bias between true and reco per bin of x.
- Parameters:
true (numpy.ndarray) –
reco (numpy.ndarray) –
x (: numpy.ndarray) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
bins (bins for numpy.histogram) –
- Returns:
bins, bias
- Return type:
numpy.ndarray, numpy.ndarray
- ctaplot.ana.ana.bias_per_energy(true, reco, energy, relative_scaling_method=None, energy_bins=None)[source]
Bias between true and reco per bins of true_energy
- Parameters:
true (numpy.ndarray) –
reco (numpy.ndarray) –
energy (: astropy.Quantity) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
bins (astropy.Quantity) –
- Returns:
bins, bias
- Return type:
astropy.Quantity, numpy.ndarray
- class ctaplot.ana.ana.cta_performance(site)[source]
Bases:
object
- get_effective_area(observation_time=<Quantity 50. h>)[source]
Return the effective area at the given observation time in hours. NB: Only 50h supported Returns the true_energy array and the effective area array :param observation_time: :type observation_time: optional
- Return type:
numpy.ndarray, numpy.ndarray
- class ctaplot.ana.ana.cta_requirement(site)[source]
Bases:
object
- get_effective_area(observation_time=<Quantity 50. h>)[source]
Return the effective area at the given observation time in hours. NB: Only 0.5h supported Returns the true_energy array and the effective area array :param observation_time: :type observation_time: optional
- Return type:
numpy.ndarray, numpy.ndarray
- ctaplot.ana.ana.distance2d_resolution(true_x, reco_x, true_y, reco_y, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method=None)[source]
Compute the 2D distance resolution as the Qth (standard being 68) containment radius of the relative distance with lower and upper limits on this value corresponding to the confidence value required (1.645 for 95% confidence)
- Parameters:
true_x (numpy.ndarray or astropy.units.Quantity) –
reco_x (numpy.ndarray or astropy.units.Quantity) –
true_y (numpy.ndarray or astropy.units.Quantity) –
reco_y (numpy.ndarray`or `astropy.units.Quantity) –
percentile (float - percentile, 68.27 corresponds to one sigma) –
confidence_level (float) –
bias_correction (bool) –
relative_scaling_method (str) –
see ctaplot.ana.relative_scaling
- Return type:
numpy.array [resolution, lower limit, upper limit]
- ctaplot.ana.ana.distance2d_resolution_per_bin(x, true_x, reco_x, true_y, reco_y, bins=10, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method=None)[source]
Compute the 2D distance per bin of x
- Parameters:
x (numpy.ndarray) –
reco_x (numpy.ndarray) –
reco_y (numpy.ndarray) –
true_x (numpy.ndarray) –
true_y (numpy.ndarray) –
bins (bins args of np.histogram) –
percentile (float - percentile, 68.27 corresponds to one sigma) –
confidence_level (float) –
bias_correction (bool) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
- Return type:
x_bins, distance_res
- ctaplot.ana.ana.effective_area(true_energy, reco_energy, simu_area)[source]
Compute the effective area from a list of simulated energy and reconstructed energy :param true_energy: :type true_energy: 1d numpy array :param reco_energy: :type reco_energy: 1d numpy array :param simu_area: :type simu_area: float - area on which events are simulated
- Return type:
float = effective area
- ctaplot.ana.ana.effective_area_per_energy(true_energy, reco_energy, simu_area, bins=None)[source]
Compute the effective area per true_energy bins from a list of simulated energy and reconstructed energy
- Parameters:
true_energy (astropy.Quantity) –
reco_energy (astropy.Quantity) –
simu_area (astropy.Quantity) – area on which events are simulated
bins (astropy.Quantity) –
- Returns:
(energy, Seff)
- Return type:
(1d numpy array, 1d numpy array)
- ctaplot.ana.ana.effective_area_per_energy_power_law(emin, emax, total_number_events, spectral_index, true_energy, simu_area, bins=None)[source]
Compute the effective area per true_energy bins from a list of simulated energy and reconstructed energy
- Parameters:
emin (astropy.Quantity) –
emax (astropy.Quantity) –
total_number_events (int) –
spectral_index (float) –
true_energy (1d astropy.Quantity) –
simu_area (astropy.Quantity) – area on which events are simulated
bins (astropy.Quantity) –
- Returns:
(true_energy bins, effective_area)
- Return type:
(astropy.Quantity array, 1d numpy array)
- ctaplot.ana.ana.energy_bias(true_energy, reco_energy, bins=None)[source]
Compute the true_energy relative bias per true_energy bin.
- Parameters:
true_energy (astropy.Quantity (1d array)) – simulated energies
reco_energy (astropy.Quantity (1d array)) – reconstructed energies
bins (astropy.Quantity (1d array)) – energy bins - if None, standard CTA binning is used
- Returns:
(energy_bins, bias) – true_energy, true_energy bias
- Return type:
(astropy.Quantity, numpy.array)
- ctaplot.ana.ana.energy_resolution(true_energy, reco_energy, percentile=68.27, confidence_level=0.95, bias_correction=False)[source]
Compute the true_energy resolution of true_energy as the percentile (68 as standard) containment radius of true_energy-true_energy)/true_energy with the lower and upper confidence limits defined by the given confidence level
- Parameters:
true_energy (1d numpy array of simulated energy) –
reco_energy (1d numpy array of reconstructed energy) –
percentile (float) – <= 100
- Return type:
numpy.array - [energy_resolution, lower_confidence_limit, upper_confidence_limit]
- ctaplot.ana.ana.energy_resolution_per_energy(true_energy, reco_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, bins=None)[source]
The true_energy resolution ΔE / energy is obtained from the distribution of (ER – ET) / ET, where R and T refer to the reconstructed and true energy of gamma-ray events. ΔE/energy is the half-width of the interval around 0 which contains given percentile of the distribution.
- Parameters:
true_energy (astropy.Quantity) – 1d array of simulated energy
reco_energy (astropy.Quantity) – 1d array of reconstructed energy
percentile (float) – between 0 and 100
confidence_level (float) – between 0 and 1
bias_correction (bool) –
bins (int | astropy.Quantity) –
- Returns:
(e, e_res) – true_energy, resolution in true_energy
- Return type:
(astropy.Quantity, numpy.array)
- ctaplot.ana.ana.get_magic_sensitivity()[source]
Load MAGIC differential sensitivity data from file magic_sensitivity_2014.ecsv. Extracted from table A.7 in Aleksić, Jelena, et al. “The major upgrade of the MAGIC telescopes, Part II: A performance study using observations of the Crab Nebula.” Astroparticle Physics 72 (2016): 76-94., DOI: 10.1016/j.astropartphys.2015.02.005’
- Return type:
astropy.table.table.QTable
- ctaplot.ana.ana.impact_parameter_error(true_x, reco_x, true_y, reco_y)[source]
compute the error distance between true and reconstructed impact parameters :param reco_x: :type reco_x: astropy.Quantity :param reco_y: :type reco_y: astropy.Quantity :param true_x: :type true_x: astropy.Quantity :param true_y: :type true_y: astropy.Quantity
- Returns:
1d numpy array
- Return type:
distances
- ctaplot.ana.ana.impact_resolution(true_x, reco_x, true_y, reco_y, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method=None)[source]
Compute the shower impact parameter resolution as the Qth (68 as standard) containment radius of the square distance to the simulated one with the lower and upper limits corresponding to the required confidence level
- Parameters:
reco_x (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_x (astropy.Quantity) –
true_y (astropy.Quantity) –
percentile (float) – see ctaplot.ana.resolution
confidence_level (float) – see ctaplot.ana.resolution
bias_correction (bool) – see ctaplot.ana.resolution
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
- Returns:
(impact_resolution, lower_confidence_level, upper_confidence_level)
- Return type:
(numpy.array, numpy.array, numpy.array)
- ctaplot.ana.ana.impact_resolution_per_energy(true_x, reco_x, true_y, reco_y, true_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method=None, bins=None)[source]
Plot the angular resolution as a function of the event simulated true_energy
- Parameters:
reco_x (astropy.Quantity) –
reco_y (astropy.Quantity) –
true_x (astropy.Quantity) –
true_y (astropy.Quantity) –
true_energy (astropy.Quantity) –
percentile (float) – see ctaplot.ana.resolution
confidence_level (float) – see ctaplot.ana.resolution
bias_correction (bool) – see ctaplot.ana.resolution
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
bins (astropy.Quantity) –
- Returns:
(true_energy, resolution)
- Return type:
(astropy.Quantity, 1d numpy array)
- class ctaplot.ana.ana.irf_cta[source]
Bases:
object
Class to handle Instrument Response Function data
- ctaplot.ana.ana.logbin_mean(x_bin)[source]
Function that gives back the mean of each bin in logscale
- Parameters:
x_bin (numpy.ndarray) –
- Return type:
numpy.ndarray
- ctaplot.ana.ana.logspace_decades_nbin(x_min, x_max, n=5)[source]
return an array with logspace and n bins / decade
- Parameters:
x_min (float) –
x_max (float) –
n (int - number of bins per decade) –
- Returns:
bins
- Return type:
1D Numpy array
- ctaplot.ana.ana.percentile_confidence_interval(x, percentile=68, confidence_level=0.95)[source]
Return the confidence interval for the qth percentile of x for a given confidence level
REF: http://people.stat.sfu.ca/~cschwarz/Stat-650/Notes/PDF/ChapterPercentiles.pdf S. Chakraborti and J. Li, Confidence Interval Estimation of a Normal Percentile, doi:10.1198/000313007X244457
- Parameters:
x (numpy.ndarray) –
percentile (float) – 0 < percentile < 100
confidence_level (float) – 0 < confidence level (by default 95%) < 1
- ctaplot.ana.ana.power_law_integrated_distribution(xmin, xmax, total_number_events, spectral_index, bins)[source]
For each bin, return the expected number of events for a power-law distribution. bins: numpy.ndarray, e.g. np.logspace(np.log10(emin), np.logspace(xmax))
- Parameters:
xmin (float, min of the simulated power-law) –
xmax (float, max of the simulated power-law) –
total_number_events (int) –
spectral_index (float) –
bins (numpy.ndarray) –
- Returns:
y
- Return type:
numpy.ndarray, len(y) = len(bins) - 1
- ctaplot.ana.ana.relative_bias(true, reco, relative_scaling_method='s1')[source]
Compute the relative bias of a reconstructed variable as median(reco-true)/relative_scaling(true, reco)
- Parameters:
true (numpy.ndarray) –
reco (numpy.ndarray) –
relative_scaling_method (str) – see ctaplot.ana.relative_scaling
- ctaplot.ana.ana.relative_scaling(true, reco, method='s0')[source]
Define the relative scaling for the relative error calculation. There are different ways to calculate this scaling factor. The easiest and most spread one is simply np.abs(true). However this is possible only when true != 0. Possible methods: - None or ‘s0’: scale = 1 - ‘s1’: scale = np.abs(true) - ‘s2’: scale = np.abs(reco) - ‘s3’: scale = (np.abs(true) + np.abs(reco))/2. - ‘s4’: scale = np.max([np.abs(reco), np.abs(true)], axis=0)
This method is not exposed but kept for tests and future reference. The s1 method is used in all ctaplot functions.
- Parameters:
true (numpy.ndarray) –
reco (numpy.ndarray) –
- Return type:
numpy.ndarray
- ctaplot.ana.ana.resolution(true, reco, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method='s1')[source]
Compute the resolution of reco as the Qth (68.27 as standard = 1 sigma) containment radius of (true-reco)/relative_scaling with the lower and upper confidence limits defined the values inside the error_percentile
- Parameters:
true (numpy.ndarray (1d)) – simulated quantity
reco (numpy.ndarray (1d)) – reconstructed quantity
percentile (float) – percentile for the resolution containment radius
error_percentile (float) – percentile for the confidence limits
bias_correction (bool) – if True, the resolution is corrected with the bias computed on true and reco
relative_scaling (str) – see ctaplot.ana.relative_scaling
- Return type:
numpy.ndarray - [resolution, lower_confidence_limit, upper_confidence_limit]
- ctaplot.ana.ana.resolution_per_bin(x, y_true, y_reco, percentile=68.27, confidence_level=0.95, bias_correction=False, relative_scaling_method=None, bins=10)[source]
Resolution of y as a function of binned x.
- Parameters:
x (numpy.ndarray) –
y_true (numpy.ndarray) –
y_reco (numpy.ndarray) –
percentile (float) –
confidence_level (float) –
bias_correction (bool) –
relative_scaling_method (see ctaplot.ana.relative_scaling) –
bins (int or numpy.ndarray (see numpy.histogram)) –
- Returns:
(x_bins, res) – x_bins: bins for x res: resolutions with confidence level intervals for each bin
- Return type:
(numpy.ndarray, numpy.ndarray)
- ctaplot.ana.ana.resolution_per_energy(true, reco, true_energy, percentile=68.27, confidence_level=0.95, bias_correction=False, bins=None)[source]
- Parameters:
true (1d numpy.ndarray of simulated quantity) –
reco (1d numpy.ndarray of reconstructed quantity) –
true_energy (astropy.Quantity (1d array)) – len(true_energy) == len(true) == len(reco)
bins (astropy.Quantity (1d array)) –
- Returns:
energy_bins - 1D numpy.ndarray resolution: - 3D numpy.ndarray see ctaplot.ana.resolution
- Return type:
(energy_bins, resolution)
- ctaplot.ana.ana.roc_auc_per_energy(true_type, gammaness, true_energy, energy_bins=None, gamma_label=0, **roc_auc_score_opt)[source]
Compute AUC score as a function of the true gamma energy. The AUC score is calculated in a gamma versus all fashion.
- Parameters:
true_type (numpy.ndarray) – labels
gammaness (numpy.ndarray) – likeliness of a particle to be a gamma
true_energy (numpy.ndarray) – particles true energy
energy_bins (astropy.Quantity) –
gamma_label (label of gammas in true_type array) –
roc_auc_score_opt (see sklearn.metrics.roc_auc_score options) –
- Returns:
energy_bins, auc_scores
- Return type:
numpy.ndarray, numpy.ndarray
- ctaplot.ana.ana.stat_per_energy(energy, y, statistic='mean', bins=None)[source]
Return statistic for the given quantity per energy bins. The binning is given by irf_cta
- Parameters:
energy (astropy.Quantity (1d array)) – event energy
y (astropy.Quantity or numpy.ndarray (1d array)) – len(y) == len(energy)
statistic (string) – see scipy.stat.binned_statistic
bins (astropy.Quantity (1d array)) –
- Returns:
bin_stat, bin_edges, binnumber
- Return type:
astropy.Quantity or numpy.ndarray, astropy.Quantity, numpy.ndarray