Skip to content
Closed
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
54 changes: 47 additions & 7 deletions src/probeinterface/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ def read_maxwell(file: str | Path, well_name: str = "well000", rec_name: str = "

h5py = import_safely("h5py")
my_file = h5py.File(file, mode="r")
version = int(my_file["version"][0].decode())

if "mapping" in my_file.keys():
mapping = my_file["mapping"][:]
Expand All @@ -518,10 +519,35 @@ def read_maxwell(file: str | Path, well_name: str = "well000", rec_name: str = "

prb = {"channel_groups": {1: {}}}

channels = list(mapping["channel"])
electrodes = list(mapping["electrode"])
x_pos = list(mapping["x"])
y_pos = list(mapping["y"])
channels = np.array(mapping["channel"])
electrodes = np.array(mapping["electrode"])
assert len(channels) == len(electrodes)
mask = np.full(len(channels), True, dtype=bool)

# remove all duplicate channel-to-electrode assignments
mask_id = np.argwhere(mask).flatten()
channels_electrodes = [str(a) + " " + str(b) for a, b in zip(channels, electrodes)]
[u, u_i, u_v, u_c] = np.unique(channels_electrodes, return_index=True, return_inverse=True, return_counts=True)
for i in u_v[u_i[u_c > 1]]:
mask[mask_id[np.argwhere(channels_electrodes == u[i])[1:].flatten()]] = False

# remove all duplicate channel assigments corresponding to different electrodes (channel is a mix of mulitple electrode signals)
mask_id = np.argwhere(mask).flatten()
[u, u_i, u_v, u_c] = np.unique(channels[mask], return_index=True, return_inverse=True, return_counts=True)
for i in u_v[u_i[u_c > 1]]:
mask[mask_id[np.argwhere(channels[mask] == u[i])[:].flatten()]] = False

# remove subsequent duplicated electrodes (single electrode saved to multiple channels)
mask_id = np.argwhere(mask).flatten()
[u, u_i, u_v, u_c] = np.unique(electrodes[mask], return_index=True, return_inverse=True, return_counts=True)
for i in u_v[u_i[u_c > 1]]:
mask[mask_id[np.argwhere(electrodes[mask] == u[i])[1:].flatten()]] = False

channels = channels[mask]
electrodes = electrodes[mask]
x_pos = np.array(mapping["x"])[mask]
y_pos = np.array(mapping["y"])[mask]

geometry = {}
for c, x, y in zip(channels, x_pos, y_pos):
geometry[c] = [x, y]
Expand All @@ -536,9 +562,23 @@ def read_maxwell(file: str | Path, well_name: str = "well000", rec_name: str = "
chans = np.array(prb["channel_groups"][1]["channels"], dtype="int64")
positions = np.array([prb["channel_groups"][1]["geometry"][c] for c in chans], dtype="float64")

probe.set_contacts(positions=positions, shapes="rect", shape_params={"width": 5.45, "height": 9.3})
probe.annotate_contacts(electrode=electrodes)
probe.set_planar_contour(([-12.5, -12.5], [3845, -12.5], [3845, 2095], [-12.5, 2095]))
if version <= 20160704:
probe.set_contacts(positions=positions, shapes="rect", shape_params={"width": 5.45, "height": 9.3})
probe.annotate_contacts(electrode=electrodes)
probe.set_planar_contour(([-12.5, -12.5], [3845, -12.5], [3845, 2095], [-12.5, 2095]))
else:
e_w = 8.75
e_h = 12.5
probe.set_contacts(positions=positions, shapes="rect", shape_params={"width": e_w, "height": e_h})
probe.annotate_contacts(electrode=electrodes)
probe.set_planar_contour(
(
[-e_w / 2, -e_h / 2],
[3832.5 + e_w / 2, -e_h / 2],
[3832.5 + e_w / 2, 2082.5 + e_h / 2],
[-e_w / 2, 2082.5 + e_h / 2],
)
)

probe.set_device_channel_indices(np.arange(positions.shape[0]))

Expand Down