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

Refactor open ephys #305

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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: 21 additions & 8 deletions src/probeinterface/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1763,19 +1763,32 @@ 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]

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"]
)
if npx_probe[ptype]["shank_number"] > 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain to me the case where you would have a probe_stagger but not need it? Or is it possible to have row stagger and column stagger and that is why you are checking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can help me to find terminology?

The value on the left stagger is the displacement for that specific row. Some rows are displaced and some are not and this calculated on the is_row_staggered variable.

In other words, probe_stagger is the global variable that characterized the probe whereas stagger is the one of the row. Maybe it should be called row_stagger or row_displacement? Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this was more me misreading. Maybe to make it clearer I would day

is_this_row_staggered = xx
stagger_for_this_row = probe_stager

The this helps emphasize a particular row whereas my confusion was is_row_staggered made me think you were doing a global check rather than a specific row. But that's a lot of typing. So this is a soft rec now that I see what you mean!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that that is simple change that would improve readability. Pushing it.


# 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)

if shank_number > 1:
contact_ids.append(f"s{shank_id}e{contact_id}")
else:
contact_ids.append(f"e{contact_id}")
Expand Down