Reporting and Plotting#

datapipe_testbench.plotting#

Helper functions for plotting.

class PerformancePoster[source]#

Bases: object

Class for making a performance poster.

aeff_compare(ax, ref, others, yscale='log', **extra_conf)[source]#

Compare effective area metrics.

aeff_rat_compare(ax, ref, others, yscale='linear', **extra_conf)[source]#

Compare effective area metrics using ratio.

angres_compare(ax, ref, others, yscale='linear', **extra_conf)[source]#

Compare angular resolution metrics.

angres_rat_compare(ax, ref, others, yscale='linear', **extra_conf)[source]#

Compare angular resolution metrics using ratio.

bkg_compare(ax, ref, others, yscale='log', **extra_conf)[source]#

Compare background rate metrics.

bkg_rat_compare(ax, ref, others, yscale='linear', **extra_conf)[source]#

Compare background rate metrics using ratio.

e_bias_res_compare(ax, ref, others, kind='Energy resolution', yscale='linear', **extra_conf)[source]#

Compare energy resolution and energy bias metrics.

e_bias_res_rat_compare(ax, ref, others, kind='Energy resolution', yscale='linear', **extra_conf)[source]#

Compare energy resolution and energy bias metrics using ratio.

gernot_plot(ref, other)[source]#

Produce a Gernot plot.

sens_compare(ax, ref, others, yscale='log', **extra_conf)[source]#

Compare sensitivity metrics.

sens_rat_compare(ax, ref, others, yscale='linear', **extra_conf)[source]#

Compare sensitivity metrics using ratio.

class SqrtScale(axis)[source]#

Bases: ScaleBase

Scale for bins in theta square or equivalent.

Parameters:
axisAxis

The axis for the scale.

Construct a new scale.

Notes

The following note is for scale implementers.

For back-compatibility reasons, scales take an Axis object as first argument. However, this argument should not be used: a single scale object should be usable by multiple Axises at the same time.

get_transform()[source]#

Return the transform associated with this scale.

set_default_locators_and_formatters(axis)[source]#

Set defaults.

crude_median_plot(ax, metric, yscale='sqrt', xscale='log', scale_min=-1, scale_max=2)[source]#

Plot crude median estimate of histogram.

Takes a [x,y,z] shape histogram, finds the bin containing the median, and plots the center value of that bin in a 2d plot. Calculates the empirical cumulant, then find median by searching for the bin where the cumulant crosses 1/2.

Requires at least 10 counts along z to estimate the median

make_table_rows(res_dict)[source]#

Transform a result dict containing distance measures to a list that mdutils table function will accept.

plot_complement_spans(span_dict, is_good_span, xlabel, title_prefix, log=True)[source]#

Make summary plots of a set of spans.

Parameters:
span_dict

Dictionary with all necessary information to do the rectangles plots.

is_good_spanbool

Indicates if a given span shows something positive, colouring it green. If false the span will be painted using a red colour.

xlabel
title_prefix
log

By default, True.

plot_fail_spans(req_result, xlabel, title_prefix, log=True)[source]#

Make summary plot of ‘fail spans’.

plot_irf_table(ax, table, column, prefix=None, lo_name=None, hi_name=None, label=None, **mpl_args)[source]#

Easily plot irf table.

plot_linear_spans(req_result, xlabel, title_prefix, log=True)[source]#

Make summary plot of linear regions.

plot_spans(ax, spans, y=0, height=0.2, alpha=0.3)[source]#

Easily plot spans found by datapipe_testbench.stat_helpers.find_positive_spans.

setup_profiledata_axes(data, ax: Axes | None = None) Axes[source]#

Set axis properties from a ProfileData object.

We don’t want a full plot() function here, as that is too inflexiable. This just sets up the attributes of the axis object

datapipe_testbench.report#

Tools to help write a summary report.

class Report(*args: Any, **kwargs: Any)[source]#

Bases: Document

Class to write a summary of a benchmark to .pdf.

add_header(level, title)[source]#

Add new section to document.

Parameters:
levelint

Level 1-5 of the header to add.

titlestr

Title for the header.

add_image(path, caption='', width=0.95)[source]#

Add image to document.

Parameters:
pathstr

Relative or absolute path to image.

widthfloat

In fraction of linewidth (0 to 1). By default, 0.95.

captionstr

Image caption. By default, “”.

add_table(lines)[source]#

Add table to document.

Parameters:
lines

List of lines. Each line is a list of string, one per cell. First line is header.

datapipe_testbench.requirements#

Sub-module to define anything related to requirement checks.

req_median(metric, reference, rtol)[source]#

Check a requirement on the median of a distribution.

Parameters:
metrichist.Hist

Metric to check

rtol

Relative tolerance in percentage (1 = 1%).

datapipe_testbench.comparers#

Not sure if this will be kept separate.

class ComparisonResult(name: str, plots: dict, measure: dict | None = None, tests: dict | None = None)[source]#

Bases: object

Placeholder class for storing comparisons.

store(store: ResultStore, metric_id)[source]#

Write the results to disk.

Writes the contained results to the provided ResultStore in the format most appropriate for each kind of result.

datapipe_testbench.compare_1d#

Classes for comparing 1d metrics in various situations.

class CompareByCat1D(cat_axis)[source]#

Bases: object

Class for comparing 1d histograms grouped by category.

distance_by_category(ref, others)[source]#

Measure the wasserstein distance between ref and comparison histograms grouped by category.

plot_compare_by_category(ref, others, xscale='linear', yscale='log', density=False, yerr=True, n_cols=None)[source]#

Plot 1d ref and comparison histograms grouped by category.

plot_compare_by_category_from_method(ref, others, method_name, xscale='linear', yscale='log', density=False, yerr=True, n_cols=None)[source]#

Plot 1d ref and comparison histograms grouped by category.

plot_compare_tuples_by_category_in_bins(ref, others, bins, ybin_label='energy', ybin_unit='TeV', tup1_label='gammas', tup2_label='protons', density=True, yerr=True)[source]#

Plot two lines from same metric against two lines of other metric.

Takes tuples of metrics with the shape: [category, bin_property, property] and plots the 1d distribution of property in a given bin from the two tuples into the same axes, making one column of axes per category, and one row per bin value provided.

compare_1d_metrics(ax, ref, others, external_config={})[source]#

Compare several 1d histograms.

compare_rat_1d_metrics(ax, ref, others, external_config={})[source]#

Compare several 1d histograms by taking their ratio.

datapipe_testbench.compare_2d#

Classes for comparing 2d metrics in various situations.

class CompareByCat2D(cat_axis)[source]#

Bases: object

Class for comparing 2d histograms grouped by category.

compare_disp_with_lin(hists, lin_threshold=0.015)[source]#

Compare dispersion matrix with linearity.

Takes a set of 3d histograms with axes [category, x-axis, y-axis], using x_ax as true values, and y_ax as reco/true - 1. It computes RMS in each true bin, comparing the result with the provided requirement values assumed to be in same units as the histograms.

compare_disp_with_req(req_xs, req_ys, hists)[source]#

Compare dispersion matrix with requirements.

Takes a set of 3d histograms with axes [category, x-axis, y-axis], using x_ax as true values, and y_ax as reco/true - 1. It computes RMS in each true bin, comparing the result with the provided requirement values assumed to be in same units as the histograms.

plot_compare_2dhist_mean(ref, others, xscale='log', yscale='linear', **fig_args)[source]#

Compare means of 2d histograms.

plot_compare_2dhist_rms(ref, others, xscale='log', yscale='linear', **fig_args)[source]#

Compare binwise RMS values, groups by category.

Takes a set of 3d histograms with axes [category, x-axis, y-axis], for each x-bin an RMS is calculated using the y-values.

plot_compare_2dhist_rms_with_req(req_xs, req_ys, ref, others, xscale='log', yscale='linear', **fig_args)[source]#

Compare binwise RMS values, groups by category.

Takes a set of 3d histograms with axes [category, x-axis, y-axis], for each x-bin an RMS is calculated using the y-values.

Then it draws the provided requirement values on top.

plot_compare_cut_disp_by_cat(ref, others, cuts_dict, xscale='log', yscale='linear', **fig_args)[source]#

Plot “dispersion” plots in user defined bins along a third axis.

Takes a set of 4d histograms with axes: [category, cut_axis, x-axis, y-axis]. and makes a plot grouping by category and further sub-grouping using the provided cuts_dict to split the cut_axis, making 2d histograms for each category and bin in the cut_axis.

plot_compare_disp_by_category(ref, others, xscale='log', yscale='linear', normed=False)[source]#

Plot “dispersion” plots.

Takes a set of 3d histograms with axes [category, x-axis, y-axis].

Groups by category

datapipe_testbench.constants#

Constants.