Welcome to hepbasestack’s documentation!


Tools for resource management, etc.

Miscellaneous tools


Show a progress bar increasing every second for runtime seconds. This runs in its own thread, so the program can continue in the meantime. This can be useful for while loops which run for a certain time for example.

Parameters:runtime (int) – maxtime of the progress bar in seconds

Use as decorator to get the effective execution time of the decorated function

Parameters:func (func) – Measure the execution time of this function
Returns:wrapped func
Return type:func

Identify if a session is run in an jupyter notebook

Taken from https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook

hepbasestack.colors module

Color management. Colors are handled nicely in seaborn. For a quicker acces, we mix the seaborn color palette with the way colors handled in matplotlib. E.g. we can define our own color + the seaborn colors in the palette, but if they are not found this will automatically fall back to matplotlib

class hepbasestack.colors.ColorDict[source]

Bases: dict

Sole purpose is not to throw an error in case a key does not exist, but to return the key instead. This basically comes down to if a color is not prepdefined, then we rely on matplotlib to find it with the key instead.


Load a color pallete. This will get the predefined color palette, but returns a ColorDict instead, which allows for transparent pass through of non-exisiting color names. We will only allow for the first 9 colors of the specified seaborn color palette. It will also offer a color accessible by the key ‘inhibited’, which can be used to mark ‘forbidden’ regions in a plot.

Keyword Arguments:
 name (str) – A string which is passed though seaborn.color_palette

hepbasestack.itools module

Tools for managing iterables


Concat an iterable of iterables in a single iterable, chaining its elements

Parameters:iterable_of_iterables (iterable) – Currently supported is dimensionality of 2
hepbasestack.itools.multiplex(iterable, iterable_of_iterables)[source]

More or less the inverse of flatten. Adjust the shape of iterable to match that of iterable_of_iterables by stretching each value to be an iterable with the length of the respective element in iterable_of_iterables, but with always the same value

  • iterable – The array to be multiplexed
  • iterable_of_iterables – The shape to be matched


hepbasestack.itools.slicer(list_to_slice, slices)[source]

Generator Slice a list in individual slices

  • list_to_slice (list) – a list of items
  • slices (int) – how many lists will be sliced of

slices of the given list

Return type:


hepbasestack.logger module

A logger with customizable loglevel at runtime. The loglevel can be set via the global LOGLEVEL variable.

class hepbasestack.logger.AbstractCustomLoggerType[source]

Bases: type

A modified logging.logger. Do not use directly, but as metaclass. Whenever the logger is called, HErmes.utils.logger.LOGLEVEL is queried to check for a change in the loglevel and a new logger instance is created accordingly. Python inspect is used to inspect the stack.

class hepbasestack.logger.Logger[source]

Bases: object

A custom logger with loglevel changeable at runtime. To change the loglevel, set global LOGLEVEL variable in this namespace: 10 = DEBUG, 20 = INFO, 30 = WARNING


A logger from python logging on steroids.

Parameters:loglevel (int) – 10 = DEBUG, 20 = INFO, 30 = WARNING

hepbasestack.visual module

Set styles to a more simplistic and well readable setting. It might look less sophisticated, but the goal is to make it easy to read. Also provide some helper functions

hepbasestack.visual.adjust_minor_ticks(axis, which='x')[source]

Decorate the x-axis with a reasonable set of minor x-ticks

Parameters:axis (matplotlib.axis) – The axis to decorate
Keyword Arguments:
 which (str) – either “x”, “y” or “both”

A style suitable for notebooks and personal use.


A style with bigger legends suitable for plots in presentations

hepbasestack.layout module

Figure sizes for A4 paper.

A set of figure sizes for publication-ready figures on A4 paper based on the golden ratio. For the use with pylabe figure, e.g. fig =pylab.figure(figsize=FIGSIZE_A4)

Available layouts:

  • FIGSIZE_A4: Figure on full A4 width, portrait mode, golden ratio
  • FIGSIZE_A4_LANDSCAPE: Figure on full A4 width, landscape mode, golden ratio
  • FIGSIZE_A4_LANDSCAPE_HALF_HEIGHT: Figure on full A4 width, landscape mode, height half of golden ratio
  • FIGSIZE_A4_SQUARE: Figure on full A4 width, square

Indices and tables