From c5ba24492037bbfb4ad2b08072ba75cc4bc4b103 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 9 Oct 2024 12:27:23 -0600 Subject: [PATCH 1/4] refactor open ephys --- src/probeinterface/io.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 1175c4b0..318902ae 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -1081,7 +1081,7 @@ def write_csv(file, probe): probe_part_number_to_probe_type = { # NP1.0 "PRB_1_4_0480_1": "0", - "PRB_1_4_0480_1_C": "0", + "PRB_1_4_0480_1_C": "0", # This is the metal cap version "PRB_1_2_0480_2": "0", "NP1010": "0", None: "0", # for old version without a probe number we assume 1.0 @@ -1763,19 +1763,36 @@ def read_openephys( positions[:, 0] += x_shift contact_ids = [] + probe_dict = npx_probe[ptype] + shank_pitch = probe_dict["shank_pitch"] + y_pitch = probe_dict["y_pitch"] # Vertical spacing between the centers of adjacent contacts + x_pitch = probe_dict["x_pitch"] # Horizontal spacing between the centers of contacts within the same row + number_of_columns = probe_dict["ncol"] + probe_stagger = probe_dict["stagger"] + shank_number = probe_dict["shank_number"] + for i, pos in enumerate(positions): + # Do not calculate contact ids if the probe type is not known if ptype is None: contact_ids = None break - - stagger = np.mod(pos[1] / npx_probe[ptype]["y_pitch"] + 1, 2) * npx_probe[ptype]["stagger"] - shank_id = shank_ids[i] if npx_probe[ptype]["shank_number"] > 1 else 0 - + + x_pos = pos[0] + y_pos = pos[1] + + # Adds a shift to rows in the staggered configuration + is_row_staggered = np.mod(y_pos / y_pitch + 1, 2) == 1 + stagger = probe_stagger if is_row_staggered else 0 + + # Map the positions to the contacts ids + shank_id = shank_ids[i] if shank_number > 1 else 0 contact_id = int( - (pos[0] - stagger - npx_probe[ptype]["shank_pitch"] * shank_id) / npx_probe[ptype]["x_pitch"] - + npx_probe[ptype]["ncol"] * pos[1] / npx_probe[ptype]["y_pitch"] + (x_pos - stagger - shank_pitch * shank_id) / x_pitch + + number_of_columns * y_pos / y_pitch ) - if npx_probe[ptype]["shank_number"] > 1: + + + if shank_number > 1: contact_ids.append(f"s{shank_id}e{contact_id}") else: contact_ids.append(f"e{contact_id}") From ae9277f67a62b724b964500ecce0af9fbc97e063 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:29:20 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/probeinterface/io.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 318902ae..301098d5 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -1765,33 +1765,29 @@ def read_openephys( contact_ids = [] probe_dict = npx_probe[ptype] shank_pitch = probe_dict["shank_pitch"] - y_pitch = probe_dict["y_pitch"] # Vertical spacing between the centers of adjacent contacts - x_pitch = probe_dict["x_pitch"] # Horizontal spacing between the centers of contacts within the same row + y_pitch = probe_dict["y_pitch"] # Vertical spacing between the centers of adjacent contacts + x_pitch = probe_dict["x_pitch"] # Horizontal spacing between the centers of contacts within the same row number_of_columns = probe_dict["ncol"] probe_stagger = probe_dict["stagger"] - shank_number = probe_dict["shank_number"] + shank_number = probe_dict["shank_number"] for i, pos in enumerate(positions): # Do not calculate contact ids if the probe type is not known if ptype is None: contact_ids = None break - + x_pos = pos[0] y_pos = pos[1] - + # Adds a shift to rows in the staggered configuration is_row_staggered = np.mod(y_pos / y_pitch + 1, 2) == 1 stagger = probe_stagger if is_row_staggered else 0 - + # Map the positions to the contacts ids shank_id = shank_ids[i] if shank_number > 1 else 0 - contact_id = int( - (x_pos - stagger - shank_pitch * shank_id) / x_pitch - + number_of_columns * y_pos / y_pitch - ) - - + contact_id = int((x_pos - stagger - shank_pitch * shank_id) / x_pitch + number_of_columns * y_pos / y_pitch) + if shank_number > 1: contact_ids.append(f"s{shank_id}e{contact_id}") else: From 6150261a3146164ed714be69594168bb51d156b1 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 15 Oct 2024 14:53:28 -0600 Subject: [PATCH 3/4] zach suggestions --- src/probeinterface/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 318902ae..2b926859 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -1782,12 +1782,12 @@ def read_openephys( # Adds a shift to rows in the staggered configuration is_row_staggered = np.mod(y_pos / y_pitch + 1, 2) == 1 - stagger = probe_stagger if is_row_staggered else 0 + row_stagger = probe_stagger if is_row_staggered else 0 # Map the positions to the contacts ids shank_id = shank_ids[i] if shank_number > 1 else 0 contact_id = int( - (x_pos - stagger - shank_pitch * shank_id) / x_pitch + (x_pos - row_stagger - shank_pitch * shank_id) / x_pitch + number_of_columns * y_pos / y_pitch ) From bc1b6c06591f1047a578c8ef72d9247527c67975 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:54:52 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/probeinterface/io.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 95cbf1ff..172a0e93 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -1786,7 +1786,9 @@ def read_openephys( # Map the positions to the contacts ids shank_id = shank_ids[i] if shank_number > 1 else 0 - contact_id = int((x_pos - row_stagger - shank_pitch * shank_id) / x_pitch + number_of_columns * y_pos / y_pitch) + contact_id = int( + (x_pos - row_stagger - shank_pitch * shank_id) / x_pitch + number_of_columns * y_pos / y_pitch + ) if shank_number > 1: contact_ids.append(f"s{shank_id}e{contact_id}")