Api Documentation¶
Contents
Sheet¶
The Sheet is the container holding the information, that is then accessed by one of the renderers. A sheet also represents an output directory in which caches and generated files are stored
-
class
datasheet.sheet.
Sheet
(outdir: str)[source]¶ Main class of the library
- Parameters
outdir (str) – The output directory, in which all files are stored.
- Variables
type_wrap_map (dict) – Defines the mapping from input types to
ElementInterface
s. It is not possible to use tuple as key, as that will be ignored, because it is required for the special treatment theMultiCell
Interface needs
-
__lshift__
(obj: Any)[source]¶ Object adding operator, automatically wraps passed objects into fitting type wrappers according to Sheet.type_wrap_map
-
add_current_figure
(clear: bool = True, **fig_args)[source]¶ Convinienve method to add the current figure, and optionally clear it afterwards.
- Parameters
clear (bool) – whether or not to clear the figue
fig_args – forwarded to
Figure
-
cache
(func, **cache_args) → joblib.memory.MemorizedFunc[source]¶ Datasheet automatically creates a joblib.Memory object, with the outdir as cache dir, to have easy access to persistent caching. This method exposes the memory-object’s cache() method.
-
gate_cache
(func, recompute, key=None)[source]¶ Wraps a function. The returned function will execute the wrapped function and store the results, if it does not find a saved result already. If recompute is True the wrapped function will also be executed if a saved result is found. If a stored result is found, and recompute is False the wrapped function will always return the stored result, independent of the calling parameters, or whether the source code of the cached function changed.
the key parameter determines the save file. By default the name of the wrapped function is used. In case of wanting to save multiple results for one function, it can be wrapped multiple times with different keys
Types¶
Every object that is added to a Sheet is wrapped in a Type-Object, which is derived
from ElementInterface
. These classes purpose is to carry information on their
contained data. If a Type has a save_to_dir function it will be called when the
object is added to the sheet.
-
class
datasheet.types.
DF
(content: Any, rel_save_path: pathlib.Path = None, save_format: str = 'tex')[source]¶ Pandas.DataFrame
- Parameters
save_format (str) – supports to either save the dataframe as latex-table or csv-file. Valid values are “tex” and “csv”
-
class
datasheet.types.
ElementInterface
(content: Any, rel_save_path: pathlib.Path = None)[source]¶ Base class for all other Interfaces.
To add an interface, 3 steps are neccessary:
- Define a class for it, which is derived from ElementInterface.
If it has a method named ‘save_to_dir’ which takes one argument: the output directory, it will be called by
datasheet.sheet.Sheet.__lshift__
. This way it is possible to save files, that can be used in the render-handlers.
Optionally define a mapping for a type to be wrapped automatically with your new interface by
datasheet.sheet.Sheet.__lshift__
inSheet.type_wrap_map
- Parameters
content (Any) – the actual element
rel_save_path (Path) – the output path in case a file should be stored, if not set, it can be assigned automatically using
ElementInterface.get_outfile
-
class
datasheet.types.
Figure
(content: Any, rel_save_path: pathlib.Path = None, dpi: int = 300, bbox_inches: str = 'tight', transparent: bool = False, extension: str = 'png', scale: float = 0.7)[source]¶ matplotlib.pyplot.figure
All arguments except scale are passed to matplotlib.figure.Figure.save_fig.
- Parameters
scale (float) – can be used by the renderer as a relative size
-
class
datasheet.types.
MD
(content: Any, rel_save_path: pathlib.Path = None, offset: dataclasses.InitVar = -1)[source]¶ Markdown
- Parameters
offset – the ammount of characters to strip of the left of each line. Determined automatically if set to -1.
-
class
datasheet.types.
MultiCell
(content: Any, rel_save_path: pathlib.Path = None)[source]¶ Allows to use multiple elements in a Row. Takes a tuple as argument
-
class
datasheet.types.
Nifti
(content: Any, rel_save_path: pathlib.Path = None)[source]¶ nibabel.Nifti1Image
Renderer¶
Renderers are responsible for creating a final output file. Currentrly only the
html_renderer exists, which is automatically called by datasheet.sheet.Sheet.render
but to configure the render process it is also possible to call it manually like this:
renderer(sheet.entries, sheet.outdir, render_arg1, render_arg2)
-
datasheet.html_renderer.
render_html
(entries, outdir: pathlib.Path, style_sheet: str = 'default.css', max_index_len: int = 25)[source]¶ Renders a
Sheet
as HTML-page.- Parameters
outdir (Path) – The outputfolder to store the page in, usually
Sheet.outdir
.style_sheet (str) – the css file to include in the page. It is looked for in datasheet.data, currently this is the only valid value for this parameter
max_index_len (int) – maximal number of characters a title can have before its index is abreviated.