Skip to content

Data containers

eitprocessing.datahandling.sequence.Sequence dataclass

Sequence(
    label: str | None = None,
    name: str | None = None,
    description: str = "",
    eit_data: DataCollection[EITData] = lambda: DataCollection(EITData)(),
    continuous_data: DataCollection[ContinuousData] = lambda: DataCollection(
        ContinuousData
    )(),
    sparse_data: DataCollection[SparseData] = lambda: DataCollection(
        SparseData
    )(),
    interval_data: DataCollection[IntervalData] = lambda: DataCollection(
        IntervalData
    )(),
)

Sequence of timepoints containing respiratory data.

A Sequence object is a representation of data points over time. These data can consist of any combination of EIT frames (EITData), waveform data (ContinuousData) from different sources, or individual events (SparseData) occurring at any given timepoint. A Sequence can consist of an entire measurement, a section of a measurement, a single breath, or even a portion of a breath. A Sequence can consist of multiple sets of each type of data from the same time-points or can be a single measurement from just one source.

A Sequence can be split up into separate sections of a measurement or multiple (similar) Sequence objects can be merged together to form a single Sequence.

PARAMETER DESCRIPTION
label

Computer readable naming of the instance.

TYPE: str | None DEFAULT: None

name

Human readable naming of the instance.

TYPE: str | None DEFAULT: None

description

Human readable extended description of the data.

TYPE: str DEFAULT: ''

eit_data

Collection of one or more sets of EIT data frames.

TYPE: DataCollection[EITData] DEFAULT: lambda: DataCollection(EITData)()

continuous_data

Collection of one or more sets of continuous data points.

TYPE: DataCollection[ContinuousData] DEFAULT: lambda: DataCollection(ContinuousData)()

sparse_data

Collection of one or more sets of individual data points.

TYPE: DataCollection[SparseData] DEFAULT: lambda: DataCollection(SparseData)()

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

time property

time: ndarray

Time axis from either EITData or ContinuousData.

select_by_index

select_by_index(
    start: int | None = None,
    end: int | None = None,
    newlabel: str | None = None,
) -> Self

De facto implementation of the __getitem__ function.

This function can also be called directly to add a label to the sliced object. Otherwise a default label describing the slice and original object is attached.

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

concatenate classmethod

concatenate(a: Sequence, b: Sequence, newlabel: str | None = None) -> Sequence

Create a merge of two Sequence objects.

select_by_time

select_by_time(
    start_time: float | None = None,
    end_time: float | None = None,
    start_inclusive: bool = True,
    end_inclusive: bool = False,
    label: str | None = None,
    name: str | None = None,
    description: str = "",
) -> Self

Return a sliced version of the Sequence.

See SelectByTime.select_by_time().

eitprocessing.datahandling.eitdata.EITData dataclass

EITData(
    path: str | Path | list[Path | str],
    nframes: int,
    time: ndarray,
    sample_frequency: float,
    vendor: Vendor,
    label: str | None = None,
    name: str | None = None,
    *,
    pixel_impedance: ndarray
)

Container for EIT impedance data.

This class holds the pixel impedance from an EIT measurement, as well as metadata describing the measurement. The class is meant to hold data from (part of) a singular continuous measurement.

This class can't be initialized directly. Instead, use load_eit_data(<path>, vendor=<vendor>) to load data from disk.

PARAMETER DESCRIPTION
path

The path of list of paths of the source from which data was derived.

TYPE: str | Path | list[Path | str]

nframes

Number of frames.

TYPE: int

time

The time of each frame (since start measurement).

TYPE: ndarray

sample_frequency

The (average) frequency at which the frames are collected, in Hz.

TYPE: float

vendor

The vendor of the device the data was collected with.

TYPE: Vendor

label

Computer readable label identifying this dataset.

TYPE: str | None DEFAULT: None

name

Human readable name for the data.

TYPE: str | None DEFAULT: None

pixel_impedance

Impedance values for each pixel at each frame.

TYPE: ndarray

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

framerate property

framerate: float

Deprecated alias to sample_frequency.

select_by_time

select_by_time(
    start_time: float | None = None,
    end_time: float | None = None,
    start_inclusive: bool = False,
    end_inclusive: bool = False,
    label: str | None = None,
) -> Self

Get a shortened copy of the object, starting from start_time and ending at end_time.

Given a start and end time stamp (i.e. its value, not its index), return a slice of the original object, which must contain a time axis.

PARAMETER DESCRIPTION
start_time

first time point to include. Defaults to first frame of sequence.

TYPE: float | None DEFAULT: None

end_time

last time point. Defaults to last frame of sequence.

TYPE: float | None DEFAULT: None

start_inclusive

True), end_inclusive (default False): these arguments control the behavior if the given time stamp does not match exactly with an existing time stamp of the input. if True: the given time stamp will be inside the sliced object. if False: the given time stamp will be outside the sliced object.

TYPE: default DEFAULT: False

label

Description. Defaults to None, which will create a label based on the original object label and the frames by which it is sliced.

TYPE: str | None DEFAULT: None

RAISES DESCRIPTION
TypeError

if self does not contain a time attribute.

ValueError

if time stamps are not sorted.

RETURNS DESCRIPTION
Self

A shortened copy of the object.

select_by_index

select_by_index(
    start: int | None = None,
    end: int | None = None,
    newlabel: str | None = None,
) -> Self

De facto implementation of the __getitem__ function.

This function can also be called directly to add a label to the sliced object. Otherwise a default label describing the slice and original object is attached.

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

ensure_path_list staticmethod

ensure_path_list(path: str | Path | list[str | Path]) -> list[Path]

Return the path or paths as a list.

The path of any EITData object can be a single str/Path or a list of str/Path objects. This method returns a list of Path objects given either a str/Path or list of str/Paths.

calculate_global_impedance

calculate_global_impedance() -> ndarray

Return the global impedance, i.e. the sum of all included pixels at each frame.

eitprocessing.datahandling.continuousdata.ContinuousData dataclass

ContinuousData(
    label: str,
    name: str,
    unit: str,
    category: str,
    description: str = "",
    parameters: dict[str, Any] = dict(),
    derived_from: Any | list[Any] = list(),
    *,
    time: ndarray,
    values: ndarray,
    sample_frequency: float | None = None
)

Container for data with a continuous time axis.

Continuous data is assumed to be sequential (i.e. a single data point at each time point, sorted by time) and continuously measured/created at a fixed sampling frequency. However, a fixed interval between consecutive time points is not enforced to account for floating point arithmetic, devices with imperfect sampling frequencies, and other sources of variation.

PARAMETER DESCRIPTION
label

Computer readable naming of the instance.

TYPE: str

name

Human readable naming of the instance.

TYPE: str

unit

Unit of the data, if applicable.

TYPE: str

category

Category the data falls into, e.g. 'airway pressure'.

TYPE: str

description

Human readable extended description of the data.

TYPE: str DEFAULT: ''

parameters

Parameters used to derive this data.

TYPE: dict[str, Any] DEFAULT: dict()

derived_from

Traceback of intermediates from which the current data was derived.

TYPE: Any | list[Any] DEFAULT: list()

values

Data points.

TYPE: ndarray

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

locked property

locked: bool

Return whether the values attribute is locked.

See lock().

loaded property

loaded: bool

Return whether the data was loaded from disk, or derived from elsewhere.

select_by_time

select_by_time(
    start_time: float | None = None,
    end_time: float | None = None,
    start_inclusive: bool = False,
    end_inclusive: bool = False,
    label: str | None = None,
) -> Self

Get a shortened copy of the object, starting from start_time and ending at end_time.

Given a start and end time stamp (i.e. its value, not its index), return a slice of the original object, which must contain a time axis.

PARAMETER DESCRIPTION
start_time

first time point to include. Defaults to first frame of sequence.

TYPE: float | None DEFAULT: None

end_time

last time point. Defaults to last frame of sequence.

TYPE: float | None DEFAULT: None

start_inclusive

True), end_inclusive (default False): these arguments control the behavior if the given time stamp does not match exactly with an existing time stamp of the input. if True: the given time stamp will be inside the sliced object. if False: the given time stamp will be outside the sliced object.

TYPE: default DEFAULT: False

label

Description. Defaults to None, which will create a label based on the original object label and the frames by which it is sliced.

TYPE: str | None DEFAULT: None

RAISES DESCRIPTION
TypeError

if self does not contain a time attribute.

ValueError

if time stamps are not sorted.

RETURNS DESCRIPTION
Self

A shortened copy of the object.

select_by_index

select_by_index(
    start: int | None = None,
    end: int | None = None,
    newlabel: str | None = None,
) -> Self

De facto implementation of the __getitem__ function.

This function can also be called directly to add a label to the sliced object. Otherwise a default label describing the slice and original object is attached.

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

copy

copy(
    label: str,
    *,
    name: str | None = None,
    unit: str | None = None,
    description: str | None = None,
    parameters: dict | None = None
) -> Self

Create a copy.

Whenever data is altered, it should probably be copied first. The alterations should then be made in the copy.

derive

derive(
    label: str, function: Callable, func_args: dict | None = None, **kwargs
) -> Self

Create a copy deriving data from values attribute.

PARAMETER DESCRIPTION
label

New label for the derived object.

TYPE: str

function

Function that takes the values and returns the derived values.

TYPE: Callable

func_args

Arguments to pass to function, if any.

TYPE: dict | None DEFAULT: None

**kwargs

Values for changed attributes of derived object.

DEFAULT: {}

Example:

def convert_data(x, add=None, subtract=None, multiply=None, divide=None):
    if add:
        x += add
    if subtract:
        x -= subtract
    if multiply:
        x *= multiply
    if divide:
        x /= divide
    return x


data = ContinuousData(
    name="Lung volume (in mL)", label="volume_mL", unit="mL", category="volume", values=some_loaded_data
)
derived = data.derive("volume_L", convert_data, {"divide": 1000}, name="Lung volume (in L)", unit="L")

lock

lock(*attr: str) -> None

Lock attributes, essentially rendering them read-only.

Locked attributes cannot be overwritten. Attributes can be unlocked using unlock().

PARAMETER DESCRIPTION
*attr

any number of attributes can be passed here, all of which will be locked. Defaults to "values".

TYPE: str DEFAULT: ()

Examples:

>>> # lock the `values` attribute of `data`
>>> data.lock()
>>> data.values = [1, 2, 3] # will result in an AttributeError
>>> data.values[0] = 1      # will result in a RuntimeError

unlock

unlock(*attr: str) -> None

Unlock attributes, rendering them editable.

Locked attributes cannot be overwritten, but can be unlocked with this function to make them editable.

PARAMETER DESCRIPTION
*attr

any number of attributes can be passed here, all of which will be unlocked. Defaults to "values".

TYPE: str DEFAULT: ()

Examples:

>>> # lock the `values` attribute of `data`
>>> data.lock()
>>> data.values = [1, 2, 3] # will result in an AttributeError
>>> data.values[0] = 1      # will result in a RuntimeError
>>> data.unlock()
>>> data.values = [1, 2, 3]
>>> print(data.values)
[1,2,3]
>>> data.values[0] = 1      # will result in a RuntimeError
>>> print(data.values)
1

eitprocessing.datahandling.sparsedata.SparseData dataclass

SparseData(
    label: str,
    name: str,
    unit: str | None,
    category: str,
    time: ndarray,
    description: str = "",
    parameters: dict[str, Any] = dict(),
    derived_from: list[Any] = list(),
    values: Any | None = None,
)

Container for data related to individual time points.

Sparse data is data for which the time points are not necessarily evenly spaced. Data can consist time-value pairs or only time points.

Sparse data differs from interval data in that each data points is associated with a single time point rather than a time range.

Examples are data points at end of inspiration/end of expiration (e.g. tidal volume, end-expiratoy lung impedance) or detected time points (e.g. QRS complexes).

PARAMETER DESCRIPTION
label

Computer readable name.

TYPE: str

name

Human readable name.

TYPE: str

unit

Unit of the data, if applicable.

TYPE: str | None

category

Category the data falls into, e.g. 'detected r peak'.

TYPE: str

description

Human readable extended description of the data.

TYPE: str DEFAULT: ''

parameters

Parameters used to derive the data.

TYPE: dict[str, Any] DEFAULT: dict()

derived_from

Traceback of intermediates from which the current data was derived.

TYPE: list[Any] DEFAULT: list()

values

List or array of values. These van be numeric data, text or Python objects.

TYPE: Any | None DEFAULT: None

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

has_values property

has_values: bool

True if the SparseData has values, False otherwise.

select_by_time

select_by_time(
    start_time: float | None = None,
    end_time: float | None = None,
    start_inclusive: bool = False,
    end_inclusive: bool = False,
    label: str | None = None,
) -> Self

Get a shortened copy of the object, starting from start_time and ending at end_time.

Given a start and end time stamp (i.e. its value, not its index), return a slice of the original object, which must contain a time axis.

PARAMETER DESCRIPTION
start_time

first time point to include. Defaults to first frame of sequence.

TYPE: float | None DEFAULT: None

end_time

last time point. Defaults to last frame of sequence.

TYPE: float | None DEFAULT: None

start_inclusive

True), end_inclusive (default False): these arguments control the behavior if the given time stamp does not match exactly with an existing time stamp of the input. if True: the given time stamp will be inside the sliced object. if False: the given time stamp will be outside the sliced object.

TYPE: default DEFAULT: False

label

Description. Defaults to None, which will create a label based on the original object label and the frames by which it is sliced.

TYPE: str | None DEFAULT: None

RAISES DESCRIPTION
TypeError

if self does not contain a time attribute.

ValueError

if time stamps are not sorted.

RETURNS DESCRIPTION
Self

A shortened copy of the object.

select_by_index

select_by_index(
    start: int | None = None,
    end: int | None = None,
    newlabel: str | None = None,
) -> Self

De facto implementation of the __getitem__ function.

This function can also be called directly to add a label to the sliced object. Otherwise a default label describing the slice and original object is attached.

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

eitprocessing.datahandling.intervaldata.IntervalData dataclass

IntervalData(
    label: str,
    name: str,
    unit: str | None,
    category: str,
    intervals: list[Interval | tuple[float, float]],
    values: list[Any] | None = None,
    parameters: dict[str, Any] = dict(),
    derived_from: list[Any] = list(),
    description: str = "",
    default_partial_inclusion: bool = False,
)

Container for interval data existing over a period of time.

Interval data is data that consists for a given time interval. Examples are a ventilator setting (e.g. end-expiratory pressure), the position of a patient, a maneuver (end-expiratory hold) being performed, detected periods in the data, etc.

Interval data consists of a number of intervals that may or may not have values associated with them.

Examples of IntervalData with associated values are certain ventilator settings (e.g. end-expiratory pressure) and the position of a patient. Examples of IntervalData without associated values are indicators of maneouvres (e.g. a breath hold) or detected occurences (e.g. a breath).

Interval data can be selected by time through the select_by_time(start_time, end_time) method. Alternatively, t[start_time:end_time] can be used.

PARAMETER DESCRIPTION
label

Computer readable label identifying this dataset.

TYPE: str

name

Human readable name for the data.

TYPE: str

unit

The unit of the data, if applicable.

TYPE: str | None

category

Category the data falls into, e.g. 'breath'.

TYPE: str

intervals

A list of intervals (tuples containing a start time and end time).

TYPE: list[Interval | tuple[float, float]]

values

An optional list of values associated with each interval.

TYPE: list[Any] | None DEFAULT: None

parameters

Parameters used to derive the data.

TYPE: dict[str, Any] DEFAULT: dict()

derived_from

Traceback of intermediates from which the current data was derived.

TYPE: list[Any] DEFAULT: list()

description

Extended human readible description of the data.

TYPE: str DEFAULT: ''

default_partial_inclusion

Whether to include a trimmed version of an interval when selecting data

TYPE: bool DEFAULT: False

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

has_values property

has_values: bool

True if the IntervalData has values, False otherwise.

select_by_index

select_by_index(
    start: int | None = None,
    end: int | None = None,
    newlabel: str | None = None,
) -> Self

De facto implementation of the __getitem__ function.

This function can also be called directly to add a label to the sliced object. Otherwise a default label describing the slice and original object is attached.

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

select_by_time

select_by_time(
    start_time: float | None = None,
    end_time: float | None = None,
    partial_inclusion: bool | None = None,
    newlabel: str | None = None,
) -> Self

Create a new copy of the object, selecting data between start_time and end_time.

This function returns a shortened copy of the object, containing data from the specified start_time to end_time.

If partial_inclusion is set to True, any intervals that overlap with the start_time or end_time are included in the selection, and their times are adjusted to fit within the specified range. If partial_inclusion is False, intervals that overlap the start or end times are excluded from the selection.

For example: - Set partial_inclusion to True for cases like "set_driving_pressure" where you want to include settings that were active before the start_time. - Set partial_inclusion to False for cases like "detected_breaths" where you want to exclude partial data that doesn't fully fit within the time range.

Note that the end_time is always included in the selection if it is present in the original object.

PARAMETER DESCRIPTION
start_time

The earliest time point to include in the copy.

TYPE: float | None DEFAULT: None

end_time

The latest time point to include in the copy.

TYPE: float | None DEFAULT: None

partial_inclusion

Whether to include intervals that overlap with the start_time or end_time.

TYPE: bool | None DEFAULT: None

newlabel

A new label for the copied object.

TYPE: str | None DEFAULT: None

eitprocessing.datahandling.datacollection.DataCollection

DataCollection(data_type: type[V], *args, **kwargs)

A collection of a single type of data with unique labels.

A DataCollection functions largely as a dictionary, but requires a data_type argument, which must be one of the data containers existing in this package. When adding an item to the collection, the type of the value must match the data_type of the collection. Furthermore, the key has to match the attribute 'label' attached to the value.

The convenience method add() adds an item by setting the key to value.label.

PARAMETER DESCRIPTION
data_type

the data container stored in this collection.

TYPE: type[V]

t property

Slicing an object using the time axis instead of indices.

Example:

>>> sequence = load_eit_data(<path>, ...)
>>> time_slice1 = sequence.t[tp_start:tp_end]
>>> time_slice2 = sequence.select_by_time(tp_start, tp_end)
>>> time_slice1 == time_slice2
True

isequivalent

isequivalent(other: Self, raise_: bool = False) -> bool

Test whether the data structure between two objects are equivalent.

Equivalence, in this case means that objects are compatible e.g. to be merged. Data content can vary, but e.g. the category of data (e.g. airway pressure, flow, tidal volume) and unit, etc., must match.

PARAMETER DESCRIPTION
other

object that will be compared to self.

TYPE: Self

raise_

sets this method's behavior in case of non-equivalence. If True, an EquivalenceError is raised, otherwise False is returned.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
EquivalenceError

if raise_ == True and the objects are not

RETURNS DESCRIPTION
bool

bool describing result of equivalence comparison.

add

add(*item: V, overwrite: bool = False) -> None

Add one or multiple item(s) to the collection using the item label as the key.

get_loaded_data

get_loaded_data() -> dict[str, V]

Return all data that was directly loaded from disk.

get_data_derived_from

get_data_derived_from(obj: V) -> dict[str, V]

Return all data that was derived from a specific source.

get_derived_data

get_derived_data() -> dict[str, V]

Return all data that was derived from any source.

concatenate

concatenate(other: Self) -> Self

Concatenate this collection with an equivalent collection.

Each item of self of concatenated with the item of other with the same key.

select_by_time

select_by_time(
    start_time: float | None,
    end_time: float | None,
    start_inclusive: bool = True,
    end_inclusive: bool = False,
) -> DataCollection

Return a DataCollection containing sliced copies of the items.

eitprocessing.datahandling.breath.Breath dataclass

Breath(start_time: float, middle_time: float, end_time: float)

Represents a breath with a start, middle and end time.

eitprocessing.datahandling.event.Event dataclass

Event(marker: int, text: str)

Single time point event registered during an EIT measurement.