eitprocessing.categories

Attributes

COMPACT_YAML_FILE_MODULE

COMPACT_YAML_FILE_NAME

Classes

Category

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

_IgnoreReadonly

Context manager allowing temporarily ignoring the read-only attribute.

Functions

get_default_categories(→ Category)

Loads the default categories from file.

check_category(→ bool)

Check whether the category of a dataset is a given category or one of it's subcategories.

Module Contents

eitprocessing.categories.COMPACT_YAML_FILE_MODULE = 'eitprocessing.config'[source]
eitprocessing.categories.COMPACT_YAML_FILE_NAME = 'categories-compact.yaml'[source]
class eitprocessing.categories.Category(name: str, parent: typing_extensions.Self | None = None)[source]

Bases: anytree.Node

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 <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: >>> category.has_subcategory(“tea”)

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](https://anytree.readthedocs.io/en/latest/importer/dictimporter.html) for more info on the dictionary format. [anytree documentation on YAML import/export](https://anytree.readthedocs.io/en/latest/tricks/yaml.html) 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.

```yaml 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 measurements/pressure’)

readonly = True[source]
has_subcategory(subcategory: str) bool[source]

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:

whether subcategory exists as a descendent of category.

Return type:

bool

Raises:

ValueError – if category does not exist.

__getitem__(name: str | tuple[str])[source]
__contains__(item: str | typing_extensions.Self)[source]
classmethod from_yaml(string: str) typing_extensions.Self[source]

Load categories from YAML file.

classmethod from_compact_yaml(string: str) typing_extensions.Self[source]

Load categories from compact YAML file.

classmethod from_dict(dictionary: dict) typing_extensions.Self[source]

Create categories from dictionary.

_pre_attach_children(children: list[typing_extensions.Self]) None[source]

Checks for non-unique categories before adding them to an existing category tree.

_pre_attach(parent: typing_extensions.Self) None[source]

Method call before attaching to parent.

_pre_detach(parent: typing_extensions.Self) None[source]

Method call before detaching from parent.

_check_unique(raise_: bool = False) bool[source]
eitprocessing.categories.get_default_categories() Category[source]

Loads the default categories from file.

This returns the categories used in the eitprocessing package. The root category is simply called ‘root’. All other categories are subdivided into physical measurements, calculated values and others.

This function is cached, meaning it only loads the data once, and returns the same object every time afterwards.

eitprocessing.categories.check_category(data: eitprocessing.datahandling.DataContainer, category: str, *, raise_: bool = False) bool[source]

Check whether the category of a dataset is a given category or one of it’s subcategories.

Example: >>> data = ContinuousData(…, category=”impedance”, …) >>> check_category(data, “impedance”) # True >>> check_category(data, “pressure”) # False >>> check_category(data, “pressure”, raise_=True) # raises ValueError >>> check_category(data, “does not exist”, raise_=False) # raises ValueError

Parameters:
  • data – DataContainer object with a category attribute.

  • category – Category to match the data category against. The data category will match this and all subcategories.

  • raise – Keyword only. Whether to raise an exception if the data is not a (sub)category.

Returns:

Whether the data category matches.

Return type:

bool

Raises:
  • ValueError – If the provided category does not exist.

  • ValueError – If the data category does not match the provided category.

class eitprocessing.categories._IgnoreReadonly(items: Category | collections.abc.Sequence[Category])[source]

Context manager allowing temporarily ignoring the read-only attribute.

For internal use only.

Example: >>> foo = categories[“foo”] >>> foo.parent = None # raises RuntimeError >>> with _IgnoreReadonly(foo): >>> foo.parent = None # does not raise RuntimeError

items: collections.abc.Sequence[Category][source]
__enter__() None[source]
__exit__(exc_type: object, exc_value: object, traceback: object) None[source]