ContinuousData
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:
|
name
|
Human readable naming of the instance.
TYPE:
|
unit
|
Unit of the data, if applicable.
TYPE:
|
category
|
Category the data falls into, e.g. 'airway pressure'.
TYPE:
|
description
|
Human readable extended description of the data.
TYPE:
|
parameters
|
Parameters used to derive this data. |
derived_from
|
Traceback of intermediates from which the current data was derived. |
values
|
Data points.
TYPE:
|
loaded
property
¶
loaded: bool
Return whether the data was loaded from disk, or derived from elsewhere.
t
property
¶
t: TimeIndexer
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
¶
Create a copy deriving data from values attribute.
PARAMETER | DESCRIPTION |
---|---|
label
|
New label for the derived object.
TYPE:
|
function
|
Function that takes the values and returns the derived values.
TYPE:
|
func_args
|
Arguments to pass to function, if any.
TYPE:
|
**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:
|
Examples:
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:
|
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
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:
|
end_time
|
last time point. Defaults to last frame of sequence.
TYPE:
|
start_inclusive
|
TYPE:
|
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:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
if |
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
¶
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:
|
raise_
|
sets this method's behavior in case of non-equivalence. If
True, an
TYPE:
|
RAISES | DESCRIPTION |
---|---|
EquivalenceError
|
if |
RETURNS | DESCRIPTION |
---|---|
bool
|
bool describing result of equivalence comparison. |