Welcome to Leopard’s documentation!

Indices and tables

Module documentation

Module for laboratory reporting.

Containers data and interpretations together and then streamlines it to different output formats.

class leopard.Report(title, intro='', conclusion='', outname='', outfile=None, author=None, addTime=True, makeDir=False)[source]

Contains as main attribute a list of sections. Defines methods of outputting the sections. outfile should not include a final extension, as that is determined by the different output methods.

static getReportTable(reportzipfile, tablefilename, inReportsDir=True, verbose=False)[source]

Get a pandas table from a previous report

Parameters:
  • reportzipfile (str) – Zip folder location, ‘.zip’ extension is optional.
  • tablefilename (str or list int) – Table location within the zip folder. Can be provided as the filename within the zip folder, or a list of integers indicating its exact position (1-indexed). If you provide an empty string or list, all available table filenames in the zip folder will be printed.
  • inReportsDir (bool) – Search reportzipfile relative to reportsDir.
Returns:

pd.DataFrame

list()[source]

Get an overview of the report content list

outputPDF(**kwargs)[source]

Makes a pdf report with pylatex kwargs are send to doc.generate_pdf -> see pylatex.Document.generate_pdf for help

outputWord()[source]

Output report to word docx

outputZip(figtype='png')[source]

Outputs the report in a zip container. Figs and tabs as pngs and excells.

Parameters:figtype (str) – Figure type of images in the zip folder.
class leopard.Section(title, text, figures=None, tables=None, subsections=None, code=None, tablehead=None, tablecolumns=None, clearpage=False)[source]

Report sections. Defines methods dealing with the structure of sections, and section specific output.

tablehead => set to integer to only show DataFrame.head(tablehead) rows in this section

For adding subsections, a method is provided.

append(*args, toSection=None, **kwargs)[source]

Append a new section If toSection is None, section is appended to the main section/subs list. Else if toSection is int or (int,int,…), it gets added to the subs (subsection) list of the specified section.

args and kwargs are processed by Section class initiation

static sectionFromFunction(function, *args, **kwargs)[source]

This staticmethod executes the function that is passed with the provided args and kwargs. The first line of the function docstring is used as the section title, the comments within the function body are parsed and added as the section text. The function should return an ordered dict of figures and tables, that are then attached to the section.

Parameters:function (function) – The function that generates the section content.
Returns:Section
>>> # Section title of example function
... def exampleFunction(a,b=None):
...     'Mock figures and tables included'
...     figures = (('fig1',Mock()),('fig2',Mock()))
...     tables = (('tab1',Mock()),('tab2',Mock()))
...     return figures, tables
>>> Section.sectionFromFunction(exampleFunction,Mock(),b=Mock())
<Section @ Section title of example function>
sectionOutZip(zipcontainer, zipdir='', figtype='png')[source]

Prepares section for zip output

static sectionWalker(section, callback, *args, walkTrace=(), **kwargs)[source]

callback needs to be a function that handles different Section elements appropriately walkTrace needs to be a tuple, indicate the route to the section, e.g. (1,2,0)

walkerWrapper()[source]

Wraps a callback function in a wrapper that will be applied to all [sub]sections.

Returns:function

Leopard utility functions and classes

class leopard.utils.FigureDict(*args, section=None, **kwds)[source]

Connects the report section to the dict Currently not used!

class leopard.utils.LeopardDict[source]

Leopard Dictionary

Ordered dictionary that only allows string keys. Integers can be used to query the dict instead of the string key.

leopard.utils.makeFigFromFile(filename, *args, **kwargs)[source]

Renders an image in a matplotlib figure, so it can be added to reports args and kwargs are passed to plt.subplots

leopard.utils.pdSeriesToFrame(pdseries, colname='value')[source]

Returns a series as a pd dataframe