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

speed up electrodes import #1125

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dj.FreeTable(dj.conn(), "common_session.session_group").drop()
- Common

- Drop `SessionGroup` table #1106
- Improve electrodes import efficiency #1125

- Decoding

Expand Down
14 changes: 11 additions & 3 deletions src/spyglass/common/common_ephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,23 @@ def make(self, key):

electrode_inserts = []
electrodes = nwbf.electrodes.to_dataframe()

# Keep a dict of region IDs to avoid multiple fetches
region_ids_dict = dict()

for elect_id, elect_data in electrodes.iterrows():
region_name = elect_data.group.location
if region_name not in region_ids_dict:
# Only fetch if not already fetched
region_ids_dict[region_name] = BrainRegion.fetch_add(
region_name=region_name
)
key.update(
{
"electrode_id": elect_id,
"name": str(elect_id),
"electrode_group_name": elect_data.group_name,
"region_id": BrainRegion.fetch_add(
region_name=elect_data.group.location
),
"region_id": region_ids_dict[region_name],
"x": elect_data.get("x"),
"y": elect_data.get("y"),
"z": elect_data.get("z"),
Expand Down
Loading