Skip to content
Merged
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
40 changes: 35 additions & 5 deletions eitprocessing/continuous_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ def __post_init__(self) -> None:
self.lock("time")

def __setattr__(self, attr: str, value: Any): # noqa: ANN401
old_value = getattr(self, attr)
if isinstance(old_value, np.ndarray) and old_value.flags["WRITEABLE"] is False:
msg = f"Attribute '{attr}' is locked and can't be overwritten."
raise AttributeError(msg)
super().__setattr__(self, attr, value)
try:
old_value = getattr(self, attr)
except AttributeError:
pass
else:
if isinstance(old_value, np.ndarray) and old_value.flags["WRITEABLE"] is False:
msg = f"Attribute '{attr}' is locked and can't be overwritten."
raise AttributeError(msg)
super().__setattr__(attr, value)

def copy(
self,
Expand Down Expand Up @@ -174,3 +178,29 @@ def locked(self) -> bool:
def loaded(self) -> bool:
"""Return whether the data was loaded from disk, or derived from elsewhere."""
return len(self.derived_from) == 0

def __len__(self):
return len(self.time)

def _sliced_copy(
self,
start_index: int,
end_index: int,
label: str,
) -> Self:
# TODO: check correct implementation
cls = self.__class__
time = self.time[start_index:end_index]
values = self.values[start_index:end_index]
description = f"Slice ({start_index}-{end_index}) of <{self.description}>"

return cls(
label=label,
name=self.name,
unit=self.unit,
category=self.category,
description=description,
derived_from=[*self.derived_from, self],
time=time,
values=values,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContinuousData was still missing len. Added a suggestion in slicedcopy_continuousdata_suggestions_psomhorst.

5 changes: 3 additions & 2 deletions eitprocessing/eit_data/draeger.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _from_path(
(
continuous_data_collection,
sparse_data_collections,
) = cls._convert_medibus_data(medibus_data)
) = cls._convert_medibus_data(medibus_data, time)

return (
eit_data_collection,
Expand All @@ -127,6 +127,7 @@ def _from_path(
def _convert_medibus_data(
cls,
medibus_data: NDArray,
time: NDArray,
) -> tuple[DataCollection, DataCollection]:
continuous_data_collection = DataCollection(ContinuousData)
sparse_data_collection = DataCollection(SparseData)
Expand All @@ -138,7 +139,7 @@ def _convert_medibus_data(
name=field_info.signal_name,
description=f"Continuous {field_info.signal_name} data loaded from file",
unit=field_info.unit,
loaded=True,
time=time,
values=data,
category=field_info.signal_name,
)
Expand Down