Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eitprocessing/datahandling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from copy import deepcopy
from dataclasses import dataclass

from typing_extensions import Self

from eitprocessing.datahandling.mixins.equality import Equivalence


@dataclass(eq=False)
class DataContainer(Equivalence):
"""Base class for data container classes."""

def deepcopy(self) -> Self:
"""Return a deep copy of the object."""
return deepcopy(self)
12 changes: 7 additions & 5 deletions eitprocessing/datahandling/datacollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ def _check_item(
raise TypeError(msg)

if key and key != item.label:
# It is expected that an item in this collection has a key equal to the label of the value.
msg = f"'{key}' does not match label '{item.label}'."
msg = f"'{key}' does not match label '{item.label}'. Keys to Collection items must match their labels."
raise KeyError(msg)

if not key:
key = item.label

if not overwrite and key in self:
# Generally it is not expected one would want to overwrite existing data with different/derived data. One
# should probably change the label instead over overwriting existing data.
msg = f"Item with label {key} already exists. Use `overwrite=True` to overwrite."
# Generally it is not expected one would want to overwrite existing data with different/derived data.
# One should probably change the label instead over overwriting existing data.
# To force an overwrite, use __setitem__ and set `overwrite=True`.
msg = (
f"Item with label {key} already exists and cannot be overwritten. Please use a different label instead."
)
raise KeyError(msg)

def get_loaded_data(self) -> dict[str, V]:
Expand Down
1 change: 1 addition & 0 deletions eitprocessing/datahandling/eitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class is meant to hold data from (part of) a singular continuous measurement.
sample_frequency: float = field(metadata={"check_equivalence": True}, repr=False)
vendor: Vendor = field(metadata={"check_equivalence": True}, repr=False)
label: str | None = field(default=None, compare=False, metadata={"check_equivalence": True})
description: str = field(default="", compare=False, repr=False)
name: str | None = field(default=None, compare=False, repr=False)
pixel_impedance: np.ndarray = field(repr=False, kw_only=True)

Expand Down
40 changes: 40 additions & 0 deletions eitprocessing/datahandling/mixins/plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from __future__ import annotations

from matplotlib import pyplot as plt

from eitprocessing.datahandling.continuousdata import ContinuousData
from eitprocessing.datahandling.sequence import Sequence


class Plotting:
"""Mixin class that adds methods for graphical outputs."""

def plot_waveforms(
self: Sequence | ContinuousData,
waveforms: str | list[str], # TODO: check that str is correct type hint
reset_x: bool = False,
) -> None:
"""Plot waveform data against time.

Args:
waveforms: Name(s) of ContinuousData objects to plot. #TODO: can this be other than ContinuousData?
reset_x:
If False (default), the time (x-) axis starts at t0 (i.e., the first time point in the `Sequence`).
If True, the time (x-) axis starts at 0 (i.e. t0 is subtracted from each time point).
"""
if not isinstance(self, (Sequence | ContinuousData)):
msg = "XXXXXXXX" # TODO: write error message
raise TypeError(msg)

if not isinstance(waveforms, list):
waveforms = [waveforms]
n_waveforms = len(waveforms)

offset = self.time[0] if reset_x else 0

fig, axes = plt.subplots(n_waveforms, 1, sharex=True, figsize=(8, 3 * n_waveforms))
fig.tight_layout()

for ax, key in zip(axes, waveforms, strict=False):
ax.plot(self.time - offset, self.waveform_data[key])
ax.set_title(key)
188 changes: 0 additions & 188 deletions eitprocessing/datahandling/mixins/test_eq.ipynb

This file was deleted.

Loading
Loading