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

Fix: save a copy of group ids in CommonReferenceRecording #2215

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

oaaij-gnahz
Copy link
Contributor

Hi,

I found a potential bug and fix while using common_reference.

Problem scenario: In my original recording object, channel IDs are the same as channel indices. I use common_reference after a combination of channel_slice and split_by while keeping the original IDs. Then when re-loading my latest recording object from the JSON file, the ids_to_indices function of the CommonReferenceRecording object would raise error suggesting the channel ID is not found.

My guess for the cause: After channel_slice, the channel IDs and indices are different. When initializing CommonReferenceRecording, the groups property is directly modified to reflect indices. Then when re-loading from kwargs, it would run the function ids_to_indices again, but this time the input property groups reflects indices and it should really reflect IDs. This causes error on some occasion (in my case, split_by is called after channel_slice so that may complicate the IDs of each channel), although most of the usual cases would not elicit the error.

I upload my fix here, treating groups property similarly as ref_channel_ids. Would you take a look?

Thanks!

@alejoe91 alejoe91 added the preprocessing Related to preprocessing module label Nov 16, 2023
@alejoe91
Copy link
Member

Thanks @oaaij-gnahz

I'm having a hard time understanding exactly how behavior is changed. It seems you have only renamed groups to groups_inds, or am I missing something?

@oaaij-gnahz
Copy link
Contributor Author

oaaij-gnahz commented Nov 21, 2023

Thanks @oaaij-gnahz

I'm having a hard time understanding exactly how behavior is changed. It seems you have only renamed groups to groups_inds, or am I missing something?

Hi @alejoe91
Thanks for the reply! I applied the changes you suggested.

I think the difference that this commit makes is: when the CommonReferenceRecording gets created, previously it saves the group indices to the kwargs of the object; now it saves the group labels to the kwargs. I think the latter is correct, because if I were to create the recording object from the kwargs in a JSON file, then I should know the group labels, which the init function of CommonReferenceRecording will convert to indices using ids_to_indices. Otherwise (before this change), ids_to_indices will receive indices instead of label/IDs as input, which may cause incorrectness. That is based on my understanding, and the error on my end did disappear after the change. Does that makes sense?

@@ -98,15 +98,17 @@ def __init__(

# tranforms groups (ids) to groups (indices)
if groups is not None:
groups = [self.ids_to_indices(g) for g in groups]
group_indices = [self.ids_to_indices(g) for g in groups]
Copy link
Member

Choose a reason for hiding this comment

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

@oaaij-gnahz same name change should apply to all other groups_inds!

@alejoe91
Copy link
Member

Yep, makes sense! I left another comment!

Apply suggested changes
@oaaij-gnahz
Copy link
Contributor Author

I applied the same name change to all other groups_inds. Apologies for the oversight. Thanks for pointing that out!

@alejoe91 alejoe91 merged commit 4d1796c into SpikeInterface:main Nov 22, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preprocessing Related to preprocessing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants