From 046315bdb8fe651621c58e1825c5f055b56fb474 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Mon, 16 Dec 2024 15:46:43 +0100 Subject: [PATCH 1/5] Estimate sample frequency in Draeger bin files --- eitprocessing/datahandling/loading/draeger.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eitprocessing/datahandling/loading/draeger.py b/eitprocessing/datahandling/loading/draeger.py index 0160204b9..6efc82145 100644 --- a/eitprocessing/datahandling/loading/draeger.py +++ b/eitprocessing/datahandling/loading/draeger.py @@ -88,9 +88,14 @@ def load_from_single_path( previous_marker, ) + estimated_sample_frequency = round((len(time) - 1) / (time[-1] - time[0]), 6) + if not sample_frequency: - msg = "No sample frequency provided. " - raise ValueError(msg) + sample_frequency = estimated_sample_frequency + + if sample_frequency != estimated_sample_frequency: + msg = "Provided sample frequency {} does not match the estimated sample frequency." + warnings.warn(msg, RuntimeWarning) # time wraps around the number of seconds in a day time = np.unwrap(time, period=24 * 60 * 60) From 093fd1ae6f52acc58bc12cbcf5babb0b0a961caa Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Mon, 16 Dec 2024 20:59:20 +0100 Subject: [PATCH 2/5] Make sample_frequency optional when loading Draeger data --- eitprocessing/datahandling/loading/__init__.py | 6 +----- eitprocessing/datahandling/loading/draeger.py | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/eitprocessing/datahandling/loading/__init__.py b/eitprocessing/datahandling/loading/__init__.py index 3dad111fa..ca3c37d9f 100644 --- a/eitprocessing/datahandling/loading/__init__.py +++ b/eitprocessing/datahandling/loading/__init__.py @@ -33,7 +33,7 @@ def load_eit_data( Defaults to the same value as label. description: long description of sequence for human interpretation. sample_frequency: sample frequency at which the data was recorded. - Default for Draeger: 20 + No default for Draeger. Will be autodetected. Warns if autodetected differs from provided. Default for Timpel: 50 Default for Sentec: 50.2 first_frame: index of first frame to load. @@ -68,10 +68,6 @@ def load_eit_data( Vendor.SENTEC: sentec.load_from_single_path, }[vendor] - if vendor == Vendor.DRAEGER and not sample_frequency: - msg = """Provide a sample frequency when loading Draeger data.""" - raise NotImplementedError(msg) # automatic sample frequency detection is to be implemented per #217 - first_frame = _check_first_frame(first_frame) paths = EITData.ensure_path_list(path) diff --git a/eitprocessing/datahandling/loading/draeger.py b/eitprocessing/datahandling/loading/draeger.py index 6efc82145..a47f1e098 100644 --- a/eitprocessing/datahandling/loading/draeger.py +++ b/eitprocessing/datahandling/loading/draeger.py @@ -28,7 +28,7 @@ def load_from_single_path( path: Path, - sample_frequency: float, + sample_frequency: float | None = None, first_frame: int = 0, max_frames: int | None = None, ) -> dict[str, DataCollection]: From 98a7649697761db686d844c71fa1aa8cd03f9c96 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Mon, 16 Dec 2024 20:59:30 +0100 Subject: [PATCH 3/5] Add tests for sample frequency --- tests/test_loading.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_loading.py b/tests/test_loading.py index 164783b12..46c748d26 100644 --- a/tests/test_loading.py +++ b/tests/test_loading.py @@ -41,6 +41,15 @@ def test_loading_draeger( # assert draeger_both != draeger_inverted +def test_sample_frequency_draeger(): + with_sf = load_eit_data(draeger_file1, vendor="draeger", sample_frequency=20) + without_sf = load_eit_data(draeger_file1, vendor="draeger") + assert with_sf.eit_data["raw"].sample_frequency == without_sf.eit_data["raw"].sample_frequency + + with pytest.warns(RuntimeWarning): + _ = load_eit_data(draeger_file1, vendor="draeger", sample_frequency=50) + + def test_loading_timpel( draeger1: Sequence, timpel1: Sequence, @@ -69,10 +78,6 @@ def test_loading_illegal(): with pytest.raises(OSError): _ = load_eit_data(timpel_file, vendor="draeger", sample_frequency=20) - # no sample frequency provided - with pytest.raises(NotImplementedError): - _ = load_eit_data(timpel_file, vendor="draeger", sample_frequency=None) - def test_load_partial( draeger2: Sequence, From 87fb1eb482c370c02b05b6267aa3c87c27feca80 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Wed, 18 Dec 2024 16:44:39 +0100 Subject: [PATCH 4/5] Fix error message --- eitprocessing/datahandling/loading/draeger.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eitprocessing/datahandling/loading/draeger.py b/eitprocessing/datahandling/loading/draeger.py index a47f1e098..bbc823226 100644 --- a/eitprocessing/datahandling/loading/draeger.py +++ b/eitprocessing/datahandling/loading/draeger.py @@ -94,7 +94,10 @@ def load_from_single_path( sample_frequency = estimated_sample_frequency if sample_frequency != estimated_sample_frequency: - msg = "Provided sample frequency {} does not match the estimated sample frequency." + msg = ( + f"Provided sample frequency ({sample_frequency}) does not match " + f"the estimated sample frequency ({estimated_sample_frequency})." + ) warnings.warn(msg, RuntimeWarning) # time wraps around the number of seconds in a day From 64a68d034270cc08103a13535b940d76c7521147 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Wed, 18 Dec 2024 16:44:48 +0100 Subject: [PATCH 5/5] Reduce precision of rounding --- eitprocessing/datahandling/loading/draeger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eitprocessing/datahandling/loading/draeger.py b/eitprocessing/datahandling/loading/draeger.py index bbc823226..55d694e8c 100644 --- a/eitprocessing/datahandling/loading/draeger.py +++ b/eitprocessing/datahandling/loading/draeger.py @@ -88,7 +88,7 @@ def load_from_single_path( previous_marker, ) - estimated_sample_frequency = round((len(time) - 1) / (time[-1] - time[0]), 6) + estimated_sample_frequency = round((len(time) - 1) / (time[-1] - time[0]), 4) if not sample_frequency: sample_frequency = estimated_sample_frequency