Skip to content

Updated/Fixed code for MaxWell systems. #354

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
47 changes: 40 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,28 @@ 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 assigments corresponding to different electrodes (channel is a mix of mulitple electrode signals)
mask_id = np.argwhere(mask).flatten()
[u, u_c] = np.unique(channels[mask], return_counts=True)
for i in np.argwhere(u_c > 1).flatten():
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_c] = np.unique(electrodes[mask], return_counts=True)
for i in np.argwhere(u_c > 1).flatten():
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 +555,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
Loading