13
13
from spikeinterface import extractors
14
14
from tqdm import tqdm
15
15
16
+ from .. import probe , ephys
17
+
18
+ assert probe .schema .is_activated () and ephys .schema .is_activated ()
19
+
16
20
17
21
class DecimalEncoder (json .JSONEncoder ):
18
22
def default (self , o ):
@@ -502,23 +506,14 @@ def add_ephys_lfp_from_source_to_nwb(
502
506
503
507
def ecephys_session_to_nwb (
504
508
session_key ,
505
- subject_id = None ,
506
509
raw = True ,
507
510
spikes = True ,
508
511
lfp = "source" ,
509
512
end_frame = None ,
510
513
lab_key = None ,
511
514
project_key = None ,
512
515
protocol_key = None ,
513
- nwbfile_kwargs = None ,
514
- # workflow_module='workflow_array_ephys.pipeline',
515
- # skull_reference='',
516
- lab_schema_name = (dj .config ['custom' ]['database.prefix' ]+ 'lab' ),
517
- subject_schema_name = (dj .config ['custom' ]['database.prefix' ]+ 'subject' ),
518
- session_schema_name = (dj .config ['custom' ]['database.prefix' ]+ 'session' ),
519
- ephys_schema_name = (dj .config ['custom' ]['database.prefix' ]+ 'ephys' ),
520
- probe_schema_name = (dj .config ['custom' ]['database.prefix' ]+ 'probe' ),
521
- ephys_root_data_dir = (dj .config .get ('custom' , {}).get ('ephys_root_data_dir' , None ))):
516
+ nwbfile_kwargs = None ):
522
517
"""
523
518
Main function for converting ephys data to NWB
524
519
@@ -546,43 +541,28 @@ def ecephys_session_to_nwb(
546
541
- If element-session is being used, this argument can optionally be used to add over overwrite NWBFile fields.
547
542
"""
548
543
549
- global ephys , probe
550
- ephys = dj .create_virtual_module ('ephys' ,ephys_schema_name )
551
- probe = dj .create_virtual_module ('probe' ,probe_schema_name )
552
-
553
544
try :
554
- import element_session
555
- from element_session import session
556
- from element_session . export . nwb import session_to_nwb
557
- if not element_session . session . schema . is_activated ():
558
- session = dj . create_virtual_module ( 'session' , session_schema_name )
559
- HAVE_ELEMENT_SESSION = True
560
- except ModuleNotFoundError :
561
- HAVE_ELEMENT_SESSION = False
562
-
563
- if HAVE_ELEMENT_SESSION :
545
+ session_to_nwb = getattr ( ephys . _linking_module , 'session_to_nwb' )
546
+ except AttributeError :
547
+ if not (
548
+ isinstance ( nwbfile_kwargs , dict )
549
+ and { "session_description" , "identifier" , "session_start_time" }. issubset ( nwbfile_kwargs )):
550
+ raise ValueError (
551
+ "If session_to_nwb is not provided, you must include nwbfile_kwargs as a dictionary."
552
+ "Required fields are 'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime)" )
553
+ nwbfile = pynwb . NWBFile ( ** nwbfile_kwargs )
554
+ else :
564
555
nwbfile = session_to_nwb (
565
556
session_key ,
566
- lab_schema_name = lab_schema_name ,
567
- subject_schema_name = subject_schema_name ,
568
- session_schema_name = session_schema_name ,
569
- subject_id = subject_id ,
570
557
lab_key = lab_key ,
571
558
project_key = project_key ,
572
559
protocol_key = protocol_key ,
573
560
additional_nwbfile_kwargs = nwbfile_kwargs ,
574
561
)
575
- else :
576
- if not (
577
- isinstance (nwbfile_kwargs , dict )
578
- and {"session_description" , "identifier" , "session_start_time" }.issubset (nwbfile_kwargs )):
579
- raise ValueError (
580
- "If element-session is not activated, you must include nwbfile_kwargs as a dictionary."
581
- "Required fields are 'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime)" )
582
- nwbfile = pynwb .NWBFile (** nwbfile_kwargs )
562
+
563
+ ephys_root_data_dir = ephys .get_ephys_root_data_dir ()
583
564
584
565
if raw :
585
- assert ephys_root_data_dir , 'Need to supply root directory for retrieving raw files'
586
566
add_ephys_recording_to_nwb (session_key , ephys_root_data_dir = ephys_root_data_dir ,
587
567
nwbfile = nwbfile , end_frame = end_frame )
588
568
@@ -593,7 +573,6 @@ def ecephys_session_to_nwb(
593
573
add_ephys_lfp_from_dj_to_nwb (session_key , nwbfile )
594
574
595
575
if lfp == "source" :
596
- assert ephys_root_data_dir , 'Need to supply root directory for retrieving raw files'
597
576
add_ephys_lfp_from_source_to_nwb (session_key , ephys_root_data_dir = ephys_root_data_dir ,
598
577
nwbfile = nwbfile , end_frame = end_frame )
599
578
0 commit comments