@@ -500,23 +500,23 @@ def add_ephys_lfp_from_source_to_nwb(
500
500
501
501
502
502
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 ,
511
513
):
512
514
"""
513
515
Main function for converting ephys data to NWB
514
516
515
517
Parameters
516
518
----------
517
519
session_key: dict
518
- session_identifier: str, optional
519
- session_start_time: datetime.datetime, optional
520
520
subject_id: str
521
521
subject_id, used if it cannot be automatically inferred
522
522
raw: bool
@@ -529,15 +529,31 @@ def ecephys_session_to_nwb(
529
529
False - do not convert LFP
530
530
end_frame: int, optional
531
531
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.
532
539
"""
533
540
534
541
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 ,
539
549
)
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 )
541
557
542
558
if raw :
543
559
add_ephys_recording_to_nwb (session_key , nwbfile , end_frame = end_frame )
@@ -554,6 +570,7 @@ def ecephys_session_to_nwb(
554
570
return nwbfile
555
571
556
572
573
+
557
574
def write_nwb (nwbfile , fname , check_read = True ):
558
575
"""
559
576
Export NWBFile
0 commit comments