From 66b3f3e21b1c9e737f1762fe291447e69d0965de Mon Sep 17 00:00:00 2001 From: mahlzahn Date: Thu, 7 Sep 2023 15:00:59 +0200 Subject: [PATCH 1/4] add support for Biocam brw v4.x files --- src/probeinterface/io.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index cd855afb..d5da5c96 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -560,11 +560,27 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: h5py = import_safely("h5py") rf = h5py.File(file, "r") + if '3BRecInfo' in rf.keys(): # brw v3.x + # get channel positions + channels = rf["3BRecInfo/3BMeaStreams/Raw/Chs"][:] + rows = channels["Row"] - 1 + cols = channels["Col"] - 1 + else: # brw v4.x + for key in rf: + if key[:5] == 'Well_': + num_channels = len(rf[key]['StoredChIdxs']) + break + try: + num_channels_x = num_channels_y = int(np.sqrt(num_channels)) + except NameError: + raise RuntimeError( + "No Well found in the file") + if num_channels_x * num_channels_y != num_channels: + raise RuntimeError( + f'Cannot determine structure of the MEA plate with {n_channels} channels') + rows = np.repeat(range(num_channels_x), num_channels_y) + cols = np.tile(range(num_channels_y), num_channels_x) - # get channel positions - channels = rf["3BRecInfo/3BMeaStreams/Raw/Chs"][:] - rows = channels["Row"] - 1 - cols = channels["Col"] - 1 positions = np.vstack((rows, cols)).T * mea_pitch probe = Probe(ndim=2, si_units="um") From e3ac476cc75bf162069f34a8eb342a719dca1ffa Mon Sep 17 00:00:00 2001 From: mahlzahn Date: Mon, 20 Nov 2023 17:48:04 +0100 Subject: [PATCH 2/4] add fix num_channels in error message --- src/probeinterface/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index d5da5c96..beb07372 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -577,7 +577,7 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: "No Well found in the file") if num_channels_x * num_channels_y != num_channels: raise RuntimeError( - f'Cannot determine structure of the MEA plate with {n_channels} channels') + f'Cannot determine structure of the MEA plate with {num_channels} channels') rows = np.repeat(range(num_channels_x), num_channels_y) cols = np.tile(range(num_channels_y), num_channels_x) From bc2a2f6b8216a9a6a64cb5e25c7a894de09b5569 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:48:43 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/probeinterface/io.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index beb07372..86cbcdf1 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -560,24 +560,22 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: h5py = import_safely("h5py") rf = h5py.File(file, "r") - if '3BRecInfo' in rf.keys(): # brw v3.x + if "3BRecInfo" in rf.keys(): # brw v3.x # get channel positions channels = rf["3BRecInfo/3BMeaStreams/Raw/Chs"][:] rows = channels["Row"] - 1 cols = channels["Col"] - 1 - else: # brw v4.x + else: # brw v4.x for key in rf: - if key[:5] == 'Well_': - num_channels = len(rf[key]['StoredChIdxs']) + if key[:5] == "Well_": + num_channels = len(rf[key]["StoredChIdxs"]) break try: num_channels_x = num_channels_y = int(np.sqrt(num_channels)) except NameError: - raise RuntimeError( - "No Well found in the file") + raise RuntimeError("No Well found in the file") if num_channels_x * num_channels_y != num_channels: - raise RuntimeError( - f'Cannot determine structure of the MEA plate with {num_channels} channels') + raise RuntimeError(f"Cannot determine structure of the MEA plate with {num_channels} channels") rows = np.repeat(range(num_channels_x), num_channels_y) cols = np.tile(range(num_channels_y), num_channels_x) From 368d3f65fa7c2d92b4db83664b0988496fd4921e Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Wed, 10 Jan 2024 12:39:07 +0100 Subject: [PATCH 4/4] Better exception handling and notes --- src/probeinterface/io.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 86cbcdf1..8280cd3d 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -554,6 +554,10 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: -------- probe : Probe object + Notes + ----- + In case of multiple wells, the function will return the probe of the first plate. + """ file = Path(file).absolute() assert file.is_file() @@ -566,16 +570,19 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: rows = channels["Row"] - 1 cols = channels["Col"] - 1 else: # brw v4.x + num_channels = None for key in rf: - if key[:5] == "Well_": + if key.startswith("Well_"): num_channels = len(rf[key]["StoredChIdxs"]) break - try: - num_channels_x = num_channels_y = int(np.sqrt(num_channels)) - except NameError: - raise RuntimeError("No Well found in the file") + assert num_channels is not None, "No Well found in the file" + + num_channels_x = num_channels_y = int(np.sqrt(num_channels)) if num_channels_x * num_channels_y != num_channels: - raise RuntimeError(f"Cannot determine structure of the MEA plate with {num_channels} channels") + raise RuntimeError( + f"Electrode configuration is not a square. Cannot determine configuration of the MEA " + f"plate with {num_channels} channels" + ) rows = np.repeat(range(num_channels_x), num_channels_y) cols = np.tile(range(num_channels_y), num_channels_x)