Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Biocam brw v4.x files #216

Merged
merged 4 commits into from
Jan 11, 2024
Merged
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
29 changes: 25 additions & 4 deletions src/probeinterface/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,38 @@ 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()

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
num_channels = None
for key in rf:
if key.startswith("Well_"):
num_channels = len(rf[key]["StoredChIdxs"])
break
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"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)

# 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")
Expand Down