14
14
from spikeinterface import extractors
15
15
from tqdm import tqdm
16
16
import warnings
17
- from ... import probe , ephys_no_curation
17
+ from ... import probe
18
+ from ... import ephys_no_curation as ephys
18
19
19
- assert probe .schema .is_activated (), 'probe not yet activated'
20
20
21
- assert ephys_no_curation .schema .is_activated , \
22
- "The ephys module must be activated before export."
21
+ ephys_mode = os .getenv ('EPHYS_MODE' , dj .config ['custom' ].get ('ephys_mode' , 'acute' ))
22
+ if ephys_mode != 'no-curation' :
23
+ raise NotImplementedError ('This export function is designed for the no_curation '
24
+ + 'schema' )
23
25
24
26
25
27
class DecimalEncoder (json .JSONEncoder ):
@@ -41,14 +43,15 @@ def __init__(self, lfp_electrodes_query, chunk_length: int = 10000):
41
43
----------
42
44
lfp_electrodes_query: element_array_ephys.ephys.LFP.Electrode
43
45
chunk_length: int, optional
44
- Chunks are blocks of disk space where data are stored contiguously and compressed
46
+ Chunks are blocks of disk space where data are stored contiguously
47
+ and compressed
45
48
"""
46
49
self .lfp_electrodes_query = lfp_electrodes_query
47
50
self .electrodes = self .lfp_electrodes_query .fetch ("electrode" )
48
51
49
52
first_record = (
50
53
self .lfp_electrodes_query & dict (electrode = self .electrodes [0 ])
51
- ).fetch1 (as_dict = True )
54
+ ).fetch1 ()
52
55
53
56
self .n_channels = len (self .electrodes )
54
57
self .n_tt = len (first_record ["lfp" ])
@@ -166,7 +169,8 @@ def create_units_table(
166
169
nwbfile : pynwb .NWBFile ,
167
170
paramset_record ,
168
171
name = "units" ,
169
- desc = "data on spiking units" ):
172
+ desc = "data on spiking units"
173
+ ):
170
174
"""
171
175
172
176
ephys.CuratedClustering.Unit::unit -> units.id
@@ -215,7 +219,8 @@ def create_units_table(
215
219
ephys .ProbeInsertion
216
220
* ephys .CuratedClustering .Unit
217
221
* probe .ProbeType .Electrode
218
- & unit
222
+ & dict ((k , unit [k ]) for k in unit .keys () # excess keys caused errs
223
+ if k not in ['spike_times' , 'spike_sites' , 'spike_depths' ])
219
224
).fetch1 ("probe" , "shank" )
220
225
221
226
waveform_mean = (
@@ -302,8 +307,8 @@ def add_ephys_units_to_nwb(
302
307
def get_electrodes_mapping (electrodes ):
303
308
"""
304
309
Create a mapping from the probe and electrode id to the row number of the electrodes
305
- table. This is used in the construction of the DynamicTableRegion that indicates what rows of the electrodes
306
- table correspond to the data in an ElectricalSeries.
310
+ table. This is used in the construction of the DynamicTableRegion that indicates
311
+ what rows of the electrodes table correspond to the data in an ElectricalSeries.
307
312
308
313
Parameters
309
314
----------
@@ -356,18 +361,17 @@ def add_ephys_recording_to_nwb(
356
361
end_frame : int = None ,
357
362
):
358
363
"""
359
- Read voltage data directly from source files and iteratively transfer them to the NWB file. Automatically
360
- applies lossless compression to the data, so the final file might be smaller than the original, without
361
- data loss. Currently supports Neuropixels data acquired with SpikeGLX or Open Ephys, and relies on SpikeInterface to read the data.
364
+ Read voltage data directly from source files and iteratively transfer them to the
365
+ NWB file. Automatically applies lossless compression to the data, so the final file
366
+ might be smaller than the original, without data loss. Currently supports
367
+ Neuropixels data acquired with SpikeGLX or Open Ephys, and relies on SpikeInterface
368
+ to read the data.
362
369
363
370
source data -> acquisition["ElectricalSeries"]
364
371
365
372
Parameters
366
373
----------
367
- session_key: dict
368
- ephys_root_data_dir: str
369
- nwbfile: NWBFile
370
- end_frame: int, optional
374
+ session_key: dict ephys_root_data_dir: str nwbfile: NWBFile end_frame: int, optional
371
375
Used for small test conversions
372
376
"""
373
377
@@ -429,8 +433,12 @@ def add_ephys_lfp_from_dj_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
429
433
"""
430
434
Read LFP data from the data in element-aray-ephys
431
435
432
- ephys.LFP.Electrode::lfp -> processing["ecephys"].lfp.electrical_series["ElectricalSeries{insertion_number}"].data
433
- ephys.LFP::lfp_time_stamps -> processing["ecephys"].lfp.electrical_series["ElectricalSeries{insertion_number}"].timestamps
436
+ ephys.LFP.Electrode::lfp ->
437
+ processing["ecephys"].lfp.electrical_series["ElectricalSeries{insertion_number}"
438
+ ].data
439
+ ephys.LFP::lfp_time_stamps ->
440
+ processing["ecephys"].lfp.electrical_series["ElectricalSeries{insertion_number}"
441
+ ].timestamps
434
442
435
443
Parameters
436
444
----------
@@ -475,7 +483,7 @@ def add_ephys_lfp_from_dj_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
475
483
def add_ephys_lfp_from_source_to_nwb (
476
484
session_key : dict , ephys_root_data_dir , nwbfile : pynwb .NWBFile , end_frame = None ):
477
485
"""
478
- Read the LFP data directly from the source file. Currently, only works for SpikeGLX data.
486
+ Read the LFP data from the source file. Currently, only works for SpikeGLX data.
479
487
480
488
ephys.EphysRecording::recording_datetime -> acquisition
481
489
@@ -514,7 +522,8 @@ def add_ephys_lfp_from_source_to_nwb(
514
522
extractor = extractors .read_spikeglx (os .path .split (file_path )[0 ], "imec.lf" )
515
523
else :
516
524
raise ValueError (
517
- f"unsupported acq_software type: { ephys_recording_record ['acq_software' ]} "
525
+ "unsupported acq_software type:" +
526
+ f"{ ephys_recording_record ['acq_software' ]} "
518
527
)
519
528
520
529
if end_frame is not None :
@@ -564,7 +573,7 @@ def ecephys_session_to_nwb(
564
573
----------
565
574
session_key: dict
566
575
raw: bool
567
- Whether to include the raw data from source. SpikeGLX and OpenEphys are supported
576
+ Whether to include the raw data from source. SpikeGLX & OpenEphys are supported
568
577
spikes: bool
569
578
Whether to include CuratedClustering
570
579
lfp:
@@ -573,13 +582,14 @@ def ecephys_session_to_nwb(
573
582
False - do not convert LFP
574
583
end_frame: int, optional
575
584
Used to create small test conversions where large datasets are truncated.
576
- lab_key, project_key, and protocol_key: dictionaries used to look up optional additional metadata
585
+ lab_key, project_key, and protocol_key: dictionaries to look up optional metadata
577
586
nwbfile_kwargs: dict, optional
578
- - If element-session is not being used, this argument is required and must be a dictionary containing
579
- 'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime),
580
- the minimal data for instantiating an NWBFile object.
581
-
582
- - If element-session is being used, this argument can optionally be used to add over overwrite NWBFile fields.
587
+ - If element-session is not being used, this argument is required and must be a
588
+ dictionary containing 'session_description' (str), 'identifier' (str), and
589
+ 'session_start_time' (datetime), the required minimal data for instantiating
590
+ an NWBFile object.
591
+ - If element-session is being used, this argument can optionally be used to
592
+ overwrite NWBFile fields.
583
593
"""
584
594
585
595
session_to_nwb = getattr (ephys ._linking_module , 'session_to_nwb' , False )
@@ -608,7 +618,8 @@ def ecephys_session_to_nwb(
608
618
add_ephys_lfp_from_dj_to_nwb (session_key , nwbfile )
609
619
610
620
if lfp == "source" :
611
- add_ephys_lfp_from_source_to_nwb (session_key , ephys_root_data_dir = ephys_root_data_dir ,
621
+ add_ephys_lfp_from_source_to_nwb (session_key ,
622
+ ephys_root_data_dir = ephys_root_data_dir ,
612
623
nwbfile = nwbfile , end_frame = end_frame )
613
624
614
625
return nwbfile
0 commit comments