Skip to content

Commit 365b43b

Browse files
committed
add optional session keys to ecephys_session_to_nwb
1 parent d1f3dab commit 365b43b

File tree

1 file changed

+32
-15
lines changed
  • element_array_ephys/export/nwb

1 file changed

+32
-15
lines changed

element_array_ephys/export/nwb/nwb.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -500,23 +500,23 @@ def add_ephys_lfp_from_source_to_nwb(
500500

501501

502502
def ecephys_session_to_nwb(
503-
session_key,
504-
session_identifier=str(uuid4()),
505-
session_start_time=datetime.datetime.now(),
506-
subject_id=None,
507-
raw=True,
508-
spikes=True,
509-
lfp="source",
510-
end_frame=None,
503+
session_key,
504+
subject_id=None,
505+
raw=True,
506+
spikes=True,
507+
lfp="source",
508+
end_frame=None,
509+
lab_key=None,
510+
project_key=None,
511+
protocol_key=None,
512+
nwbfile_kwargs=None,
511513
):
512514
"""
513515
Main function for converting ephys data to NWB
514516
515517
Parameters
516518
----------
517519
session_key: dict
518-
session_identifier: str, optional
519-
session_start_time: datetime.datetime, optional
520520
subject_id: str
521521
subject_id, used if it cannot be automatically inferred
522522
raw: bool
@@ -529,15 +529,31 @@ def ecephys_session_to_nwb(
529529
False - do not convert LFP
530530
end_frame: int, optional
531531
Used to create small test conversions where large datasets are truncated.
532+
lab_key, project_key, and protocol_key: dictionaries used to look up optional additional metadata
533+
nwbfile_kwargs: dict, optional
534+
- If element-session is not being used, this argument is required and must be a dictionary containing
535+
'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime),
536+
the minimal data for instantiating an NWBFile object.
537+
538+
- If element-session is being used, this argument can optionally be used to add over overwrite NWBFile fields.
532539
"""
533540

534541
if session.schema.is_activated():
535-
nwbfile = session.export.nwb.session_to_nwb(session_key, subject_id=subject_id)
536-
else:
537-
nwbfile = pynwb.NWBFile(
538-
"automatically generated", session_identifier, session_start_time
542+
nwbfile = session_to_nwb(
543+
session_key,
544+
subject_id=subject_id,
545+
lab_key=lab_key,
546+
project_key=project_key,
547+
protocol_key=protocol_key,
548+
additional_nwbfile_kwargs=nwbfile_kwargs,
539549
)
540-
nwbfile.subject = pynwb.file.Subject(subject_id=subject_id)
550+
else:
551+
if not isinstance(nwbfile_kwargs, dict) and {'session_description', 'identifier', 'session_start_time'}.issubset(nwbfile_kwargs):
552+
raise ValueError(
553+
"If element-session is not activated, you must include nwbfile_kwargs as a dictionary."
554+
"Required fields are 'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime)"
555+
)
556+
nwbfile = pynwb.NWBFile(**nwbfile_kwargs)
541557

542558
if raw:
543559
add_ephys_recording_to_nwb(session_key, nwbfile, end_frame=end_frame)
@@ -554,6 +570,7 @@ def ecephys_session_to_nwb(
554570
return nwbfile
555571

556572

573+
557574
def write_nwb(nwbfile, fname, check_read=True):
558575
"""
559576
Export NWBFile

0 commit comments

Comments
 (0)