-
Notifications
You must be signed in to change notification settings - Fork 24
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
add max_channel column for phy interface #961
base: main
Are you sure you want to change the base?
Changes from 1 commit
bd0222a
ddba67e
6a6af5a
576290e
694b845
c93a7ce
379449f
14dea0d
a82d98b
273da61
33ba125
311cb1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
from typing import Optional | ||
from pathlib import Path | ||
from typing import Optional, Literal | ||
|
||
import numpy as np | ||
from pynwb.file import NWBFile | ||
|
||
from ..basesortingextractorinterface import BaseSortingExtractorInterface | ||
from ....utils import FolderPathType | ||
from ....utils import FolderPathType, DeepDict | ||
|
||
|
||
class PhySortingInterface(BaseSortingExtractorInterface): | ||
|
@@ -23,6 +27,23 @@ def get_source_schema(cls) -> dict: | |
] = "Path to the output Phy folder (containing the params.py)." | ||
return source_schema | ||
|
||
def get_max_channel(self): | ||
folder_path = Path(self.source_data['folder_path']) | ||
|
||
templates = np.load(str(folder_path / 'templates.npy')) | ||
channel_map = np.load(str(folder_path / 'channel_map.npy')) | ||
whitening_mat_inv = np.load(str(folder_path / "whitening_mat_inv.npy")) | ||
templates_unwh = templates @ whitening_mat_inv | ||
|
||
cluster_ids = self.sorting_extractor.get_property('original_cluster_id') | ||
templates = templates_unwh[cluster_ids] | ||
|
||
max_over_time = np.max(templates, axis=1) | ||
idx_max_channel = np.argmax(max_over_time, axis=1) | ||
max_channel = channel_map[idx_max_channel].ravel() | ||
|
||
return max_channel | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, two other questions here:
Now I am aware that you are using machinery that is already there in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I shared this with a friend that uses Phy and he flagged that. Reading the documentation I feel less certain. We could do a roun-trip with spikeinterface artificial data and the export to phy functionality to see if your function gets it right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is some code by Nick Stteinmetz that calculates templates max without using the amplitudes (but they don't do the de-whitening step that you do) https://github.com/cortex-lab/spikes/blob/master/analysis/templatePositionsAmplitudes.m There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think he does. Look at winv There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the block where the max channel is calculated take the temps as they come directly from the input: Am I missing something? |
||
def __init__( | ||
self, | ||
folder_path: FolderPathType, | ||
|
@@ -41,3 +62,29 @@ def __init__( | |
verbose : bool, default: True | ||
""" | ||
super().__init__(folder_path=folder_path, exclude_cluster_groups=exclude_cluster_groups, verbose=verbose) | ||
|
||
def add_to_nwbfile( | ||
self, | ||
nwbfile: NWBFile, | ||
metadata: Optional[DeepDict] = None, | ||
stub_test: bool = False, | ||
write_ecephys_metadata: bool = False, | ||
write_as: Literal["units", "processing"] = "units", | ||
units_name: str = "units", | ||
units_description: str = "Autogenerated by neuroconv.", | ||
): | ||
|
||
super().add_to_nwbfile( | ||
nwbfile=nwbfile, | ||
metadata=metadata, | ||
stub_test=stub_test, | ||
write_ecephys_metadata=write_ecephys_metadata, | ||
write_as=write_as, | ||
units_name=units_name, | ||
units_description=units_description, | ||
) | ||
|
||
max_channel = self.get_max_channel() | ||
nwbfile.units.add_column(name='max_channel', description='Channel with maximum amplitude', data=max_channel) | ||
|
||
return nwbfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring? It would be useful here to describe some of the Phy charateristics. Like, I read from the code below that the templates are stored unwithened, the axis operation would be clearer if you wrote the template shape somewhere (I think its shape is
(num_templates, num_samples, num_channels)
, right? Plus, the definition of cluster id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this could use a docstring