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 category.has_subcategory("<name>")
can be used. The keyword in
can be used as a shorthand.
Example:
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.
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
¶
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:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
if category does not exist. |