Skip to content

Commit d86928b

Browse files
committed
fix: bugfix inserting ElectrodeConfig
1 parent 1819cbc commit d86928b

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

element_array_ephys/ephys_no_curation.py

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -371,31 +371,30 @@ def make(self, key):
371371
probe_type, electrode_group_members
372372
)
373373

374-
self.insert1(
375-
{
376-
**key,
377-
"electrode_config_hash": econfig_entry["electrode_config_hash"],
378-
"acq_software": acq_software,
379-
"sampling_rate": spikeglx_meta.meta["imSampRate"],
380-
"recording_datetime": spikeglx_meta.recording_time,
381-
"recording_duration": (
382-
spikeglx_meta.recording_duration
383-
or spikeglx.retrieve_recording_duration(spikeglx_meta_filepath)
384-
),
385-
}
386-
)
374+
ephys_recording_entry = {
375+
**key,
376+
"electrode_config_hash": econfig_entry["electrode_config_hash"],
377+
"acq_software": acq_software,
378+
"sampling_rate": spikeglx_meta.meta["imSampRate"],
379+
"recording_datetime": spikeglx_meta.recording_time,
380+
"recording_duration": (
381+
spikeglx_meta.recording_duration
382+
or spikeglx.retrieve_recording_duration(spikeglx_meta_filepath)
383+
),
384+
}
387385

388386
root_dir = find_root_directory(
389387
get_ephys_root_data_dir(), spikeglx_meta_filepath
390388
)
391-
self.EphysFile.insert1(
389+
390+
ephys_file_entries = [
392391
{
393392
**key,
394393
"file_path": spikeglx_meta_filepath.relative_to(
395394
root_dir
396395
).as_posix(),
397396
}
398-
)
397+
]
399398

400399
# Insert channel information
401400
# Get channel and electrode-site mapping
@@ -417,13 +416,11 @@ def make(self, key):
417416
spikeglx_meta.shankmap["data"]
418417
)
419418
}
420-
self.Channel.insert(
421-
[
422-
{**key, "channel_idx": channel_idx, **channel_info}
423-
for channel_idx, channel_info in channel2electrode_map.items()
424-
]
425-
)
426419

420+
ephys_channel_entries = [
421+
{**key, "channel_idx": channel_idx, **channel_info}
422+
for channel_idx, channel_info in channel2electrode_map.items()
423+
]
427424
elif acq_software == "Open Ephys":
428425
dataset = openephys.OpenEphys(session_dir)
429426
for serial_number, probe_data in dataset.probes.items():
@@ -460,31 +457,29 @@ def make(self, key):
460457
probe_type, electrode_group_members
461458
)
462459

463-
self.insert1(
464-
{
465-
**key,
466-
"electrode_config_hash": econfig_entry["electrode_config_hash"],
467-
"acq_software": acq_software,
468-
"sampling_rate": probe_data.ap_meta["sample_rate"],
469-
"recording_datetime": probe_data.recording_info[
470-
"recording_datetimes"
471-
][0],
472-
"recording_duration": np.sum(
473-
probe_data.recording_info["recording_durations"]
474-
),
475-
}
476-
)
460+
ephys_recording_entry = {
461+
**key,
462+
"electrode_config_hash": econfig_entry["electrode_config_hash"],
463+
"acq_software": acq_software,
464+
"sampling_rate": probe_data.ap_meta["sample_rate"],
465+
"recording_datetime": probe_data.recording_info["recording_datetimes"][
466+
0
467+
],
468+
"recording_duration": np.sum(
469+
probe_data.recording_info["recording_durations"]
470+
),
471+
}
477472

478473
root_dir = find_root_directory(
479474
get_ephys_root_data_dir(),
480475
probe_data.recording_info["recording_files"][0],
481476
)
482-
self.EphysFile.insert(
483-
[
484-
{**key, "file_path": fp.relative_to(root_dir).as_posix()}
485-
for fp in probe_data.recording_info["recording_files"]
486-
]
487-
)
477+
478+
ephys_file_entries = [
479+
{**key, "file_path": fp.relative_to(root_dir).as_posix()}
480+
for fp in probe_data.recording_info["recording_files"]
481+
]
482+
488483
# Explicitly garbage collect "dataset" as these may have large memory footprint and may not be cleared fast enough
489484
del probe_data, dataset
490485
gc.collect()
@@ -503,11 +498,14 @@ def make(self, key):
503498
channel_idx: probe_electrodes[channel_idx]
504499
for channel_idx in probe_dataset.ap_meta["channels_indices"]
505500
}
506-
self.Channel.insert(
507-
[
508-
{**key, "channel_idx": channel_idx, **channel_info}
509-
for channel_idx, channel_info in channel2electrode_map.items()
510-
]
501+
502+
ephys_channel_entries = [
503+
{**key, "channel_idx": channel_idx, **channel_info}
504+
for channel_idx, channel_info in channel2electrode_map.items()
505+
]
506+
else:
507+
raise NotImplementedError(
508+
f"Processing ephys files from acquisition software of type {acq_software} is not yet implemented."
511509
)
512510

513511
# Insert into probe.ElectrodeConfig (recording configuration)
@@ -517,6 +515,10 @@ def make(self, key):
517515
probe.ElectrodeConfig.insert1(econfig_entry)
518516
probe.ElectrodeConfig.Electrode.insert(econfig_electrodes)
519517

518+
self.insert1(ephys_recording_entry)
519+
self.EphysFile.insert(ephys_file_entries)
520+
self.Channel.insert(ephys_channel_entries)
521+
520522

521523
@schema
522524
class LFP(dj.Imported):

0 commit comments

Comments
 (0)