Skip to content

Commit

Permalink
Merge pull request #251 from EIT-ALIVE/081_fix_event_on_first_frame_p…
Browse files Browse the repository at this point in the history
…somhorst

Add check for event on first frame
  • Loading branch information
psomhorst authored Jun 25, 2024
2 parents 99f5e12 + bbe5ef4 commit 7c07575
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
Expand All @@ -12,6 +13,7 @@ on:
- "**.ipynb"
branches:
- main
- develop

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- develop

jobs:
verify:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dash_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
Expand All @@ -12,6 +13,7 @@ on:
- "**.ipynb"
branches:
- main
- develop

jobs:
call-build-workflow:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
Expand All @@ -12,6 +13,7 @@ on:
- "**.ipynb"
branches:
- main
- develop

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion eitprocessing/datahandling/loading/draeger.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _read_frame(
# The event marker stays the same until the next event occurs.
# Therefore, check whether the event marker has changed with
# respect to the most recent event. If so, create a new event.
if (previous_marker is not None) and (event_marker > previous_marker):
if ((previous_marker is not None) and (event_marker > previous_marker)) or (index == 0 and event_text):
events.append((frame_time, Event(event_marker, event_text)))
if timing_error:
warnings.warn("A timing error was encountered during loading.")
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
Path.resolve(Path(__file__).parent.parent),
)
data_directory = Path(environment) / "tests" / "test_data"
draeger_file1 = Path(data_directory) / "Draeger_Test3.bin"
draeger_file2 = Path(data_directory) / "Draeger_Test.bin"
timpel_file = Path(data_directory) / "Timpel_test.txt"
dummy_file = Path(data_directory) / "not_a_file.dummy"
draeger_file1 = data_directory / "Draeger_Test3.bin"
draeger_file2 = data_directory / "Draeger_Test.bin"
draeger_file3 = data_directory / "Draeger_Test_event_on_first_frame.bin"
timpel_file = data_directory / "Timpel_test.txt"
dummy_file = data_directory / "not_a_file.dummy"


@pytest.fixture(scope="session")
Expand Down
22 changes: 20 additions & 2 deletions tests/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from eitprocessing.datahandling.eitdata import EITData, Vendor
from eitprocessing.datahandling.loading import load_eit_data
from eitprocessing.datahandling.loading.draeger import DRAEGER_FRAMERATE
from eitprocessing.datahandling.sequence import Sequence
from tests.conftest import draeger_file1, draeger_file2, dummy_file, timpel_file
from tests.conftest import draeger_file1, draeger_file2, draeger_file3, dummy_file, timpel_file

# ruff: noqa: ERA001 #TODO: remove this line

Expand Down Expand Up @@ -105,9 +106,26 @@ def test_load_partial(


def test_illegal_first_frame():
for ff in [0.5, -1, "fdw"]:
for ff in [0.5, -1, "fdw", 1e12]:
with pytest.raises((TypeError, ValueError)):
_ = load_eit_data(draeger_file1, "draeger", first_frame=ff)

for ff2 in [0, 0.0, 1.0, None]:
_ = load_eit_data(draeger_file1, "draeger", first_frame=ff2)


def test_max_frames_too_large():
with pytest.warns():
_ = load_eit_data(draeger_file1, "draeger", max_frames=1e12)


def test_framerate_unset():
loaded_draeger = load_eit_data(draeger_file1, "draeger", framerate=None)
assert loaded_draeger.eit_data["raw"].framerate == DRAEGER_FRAMERATE


def test_event_on_first_frame(draeger2: Sequence):
draeger3 = load_eit_data(draeger_file3, vendor="draeger")
draeger3_events = draeger3.sparse_data["events_(draeger)"]
assert draeger3_events == draeger2.sparse_data["events_(draeger)"]
assert draeger3_events.time[0] == draeger3.eit_data["raw"].time[0]

0 comments on commit 7c07575

Please sign in to comment.