Skip to content

Categories

eitprocessing.categories.Category

Category(name: str, parent: Self | None = None)

Data category indicating what type of information is saved in an object.

Categories are nested, where more specific categories are nested inside more general categories. The root category is simply named 'category'. Categories have a unique name within the entire tree.

To check the existence of a category with name within a category tree, either as subcategory or subsub(...)category, category.has_subcategory("<name>") can be used. The keyword in can be used as a shorthand.

Example:

>>> "tea" in category  # is the same as:
True
>>> category.has_subcategory("tea")
True

To select a subcategory, category["<name>"] can be used. You can select multiple categories at once. This will create a new tree with a temporary root, containing only the selected categories.

Example:

>>> foobar = categories["foo", "bar"]
>>> print(foobar)
Category('/temporary root')
>>> print(foobar.children)
(Category('/temporary root/foo'), Category('/temporary root/bar'))

Categories can be hand-crafted, created from a dictionary or a YAML string. See anytree.DictionaryImporter documentation for more info on the dictionary format. anytree documentation on YAML import/export shows the relevant structure of a normal YAML string.

Categories also supports a compact YAML format, where each category containing a subcategory is a sequence. Categories without subcategories are strings in those sequences.

root:
- sub 1 (without subcategories)
- sub 2 (with subcategories):
  - sub a (without subcategories)

Categories are read-only by default, as they should not be edited by the end-user during runtime. Consider editing the config file instead.

Each type of data that is attached to an eitprocessing object should be categorized as one of the available types of data. This allows algorithms to check whether it can apply itself to the provided data, preventing misuse of algorithms.

Example:

>>> categories = get_default_categories()
>>> print(categories)
Category('/category')
>>> print("pressure" in categories)
True
>>> categories["pressure"]
Category('/category/physical measurement/pressure')

has_subcategory

has_subcategory(subcategory: str) -> bool

Check whether this category contains a subcategory.

Returns True if the category and subcategory both exist. Returns False if the category exists, but the subcategory does not. Raises a ValueError

Attr

category: the category to be checked as an ancestor of the subcategory. This category should exist. subcategory: the subcategory to be checked as a descendent of the category.

RETURNS DESCRIPTION
bool

whether subcategory exists as a descendent of category.

TYPE: bool

RAISES DESCRIPTION
ValueError

if category does not exist.

from_yaml classmethod

from_yaml(string: str) -> Self

Load categories from YAML file.

from_compact_yaml classmethod

from_compact_yaml(string: str) -> Self

Load categories from compact YAML file.

from_dict classmethod

from_dict(dictionary: dict) -> Self

Create categories from dictionary.