Skip to content

Commit

Permalink
fix labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniBodor committed Nov 30, 2023
1 parent 3133ed2 commit 94aa61c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 4 additions & 2 deletions eitprocessing/eit_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ def check_equivalence(cls, a: T, b: T, raise_=False) -> bool:
return False

def _sliced_copy(
self: Self, start_index: int, end_index: int, label: str | None = None
self,
start_index: int,
end_index: int,
label: str,
) -> Self:
super()._sliced_copy(start_index, end_index, label)
cls = self._get_vendor_class(self.vendor)
time = self.time[start_index:end_index]
nframes = len(time)
Expand Down
2 changes: 0 additions & 2 deletions eitprocessing/eit_data/eit_data_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def concatenate(cls, a: Self, b: Self) -> Self:
def _sliced_copy(
self, start_index: int, end_index: int, label: str | None = None
) -> Self:
super()._sliced_copy(start_index, end_index, label)

pixel_impedance = self.pixel_impedance[start_index:end_index, :, :]

return self.__class__(
Expand Down
28 changes: 15 additions & 13 deletions eitprocessing/mixins/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class SelectByIndex(ABC):
time: NDArray
label: str

def select_by_index( # pylint: disable=too-many-arguments
Expand All @@ -23,9 +22,17 @@ def select_by_index( # pylint: disable=too-many-arguments
warnings.warn("No starting or end timepoint was selected.")
return self

start = 0 or None
start = start or 0
if end is None:
end = len(self.time)
end = len(self)

if label is None:
if start > end:
label = f"No frames selected from <{self.label}>"
elif start < end - 1:
label = f"Slice ({start}-{end-1}) of <{self.label}>"
else:
label = f"Frame ({start}) of <{self.label}>"

return self._sliced_copy(start_index=start, end_index=end, label=label)

Expand All @@ -40,24 +47,19 @@ def __getitem__(self, key: slice | int):
return self.select_by_index(start_index, end_index)

if isinstance(key, int):
return self.select_by_index(start=key, end=key)
return self.select_by_index(start=key, end=key + 1)

raise TypeError(
f"Invalid slicing input. Should be `slice` or `int`, not {type(key)}."
)

@abstractmethod
def _sliced_copy(
self, start_index: int, end_index: int, label: str | None = None
self,
start_index: int,
end_index: int,
label: str,
) -> Self:
if label is None:
if start_index >= end_index:
pass
elif start_index < end_index - 1:
label = f"Frame ({start_index}) of <{self.label}>"
else:
label = f"Slice ({start_index}-{end_index-1}) of <{self.label}>"

...


Expand Down

0 comments on commit 94aa61c

Please sign in to comment.