rail.plotting.plotter module

class rail.plotting.plotter.RailPlotter(**kwargs)[source]

Bases: Configurable, DynamicClass

Base class for making matplotlib plot

The main function in this class is:

run(prefix: str, kwargs**: Any) -> dict[str, RailPlotHolder]

This function will make a set of plots and return them in a dict. prefix is string that gets prepended to plot names.

The data to be plotted is passed in via the kwargs.

Sub-classes should implement

config_options: dict[str, ceci.StageParameter]

that will be used to configure things like the axes binning, selection functions, and other plot-specfic options

input_type: RailPZPointEstimateDataset

that specifics the inputs that the sub-classes expect, this is used the check the kwargs that are passed to the run function.

A function:

_make_plots(self, prefix: str, **kwargs: Any) -> dict[str, RailPlotHolder]:

That actually makes the plots. It does not need to do the checking that the correct kwargs have been given.

Parameters:

kwargs (Any)

input_type

alias of RailDataset

static iterate(plotters, datasets, **kwargs)[source]

Utility function to several plotters of several data sets

Return type:

dict[str, RailPlotDict]

Parameters:
  • plotters (list[RailPlotter]) – Plotters to run

  • datasets (list[RailDatasetHolder]) – Prefixes and datasets to iterate over

  • kwargs (Any)

Returns:

out_dict – Dictionary of the newly created figures

Return type:

dict[str, RailPlotDict]

static iterate_plotters(name, plotters, prefix, dataset, **kwargs)[source]

Utility function to run several plotters on the same data

Return type:

RailPlotDict

Parameters:
  • name (str) – Name to give to the RailPlotDict

  • plotters (list[RailPlotter]) – Plotters to run

  • prefix (str) – Prefix to append to plot names, e.g., the p(z) algorithm or analysis ‘flavor’

  • kwargs (dict[str, Any]) – Used to pass the data to make the plots

  • dataset (RailDatasetHolder)

Returns:

out_dict – Dictionary of the newly created figures

Return type:

RailPlotDict

run(prefix, **kwargs)[source]

Make all the plots given the data

Return type:

dict[str, RailPlotHolder]

Parameters:
  • prefix (str) – Prefix to append to plot names, e.g., the p(z) algorithm or analysis ‘flavor’

  • kwargs (dict[str, Any]) – Used to pass the data to make the plots

Returns:

out_dict – Dictionary of the newly created figures

Return type:

dict[str, RailPlotHolder]

sub_classes: dict[str, type[DynamicClass]] = {'CatPlotterColorsVsTruth': <class 'rail.plotting.cat_plotters.CatPlotterColorsVsTruth'>, 'CatPlotterMagntidues': <class 'rail.plotting.cat_plotters.CatPlotterMagntidues'>, 'CatPlotterMagntiduesVsTruth': <class 'rail.plotting.cat_plotters.CatPlotterMagntiduesVsTruth'>, 'CatPlotterTruth': <class 'rail.plotting.cat_plotters.CatPlotterTruth'>, 'NZPlotterTomoBins': <class 'rail.plotting.nz_plotters.NZPlotterTomoBins'>, 'RailPlotter': <class 'rail.plotting.plotter.RailPlotter'>}
to_yaml_dict()[source]

Create a yaml-convertable dict for this object

Return type:

dict[str, dict[str, Any]]

static write_plots(fig_dict, outdir='.', figtype='png', purge=False)[source]

Utility function to write several plots do disk

Return type:

None

Parameters:
  • fig_dict (dict[str, RailPlotDict]) – Dictionary of figures to write

  • outdir (str) – Directory to write figures in

  • figtype (str) – Type of figures to write, e.g., png, pdf…

  • purge (bool) – Delete figure after saving

yaml_tag: str = 'Plotter'
class rail.plotting.plotter.RailPlotterList(**kwargs)[source]

Bases: Configurable

The class collects a set of plotter that can all run on the same data.

E.g., plotters that can all run on a dict that looks like {truth:np.ndarray, pointEstimates: np.ndarray} could be put into a PlotterList. This make it easier to collect similar types of plots.

Parameters:

kwargs (Any)

config_options: dict[str, StageParameter] = {'dataset_holder_class': Parameter(Dataset holder that provides datset types expected by plotter on the list, type: <class 'str'>, default: None [required]), 'name': Parameter(PlotterList name, type: <class 'str'>, default: None [required]), 'plotters': Parameter(List of plotter to include, type: <class 'list'>, default: [] [optional])}
resolve(plotter_factory)[source]

Extract the plotters

Return type:

list[RailPlotter]

Parameters:

plotter_factory (RailPlotterFactory)

Paramters

plotter_factory:

Factory used to make the plotters.

returns:

Requested plotters.

rtype:

list[RailPlotter]

Notes

This will enforce that each plotter expects the compatible dataset_types

yaml_tag: str = 'PlotterList'