@@ -30,6 +30,9 @@ class OpenEphysBinaryRawIO(BaseRawIO):
3030 ----------
3131 dirname : str
3232 Path to Open Ephys directory
33+ load_sync_channel : bool
34+ If False (default) and a SYNC channel is present (e.g. Neuropixels), this is not loaded.
35+ If True, the SYNC channel is loaded and can be accessed in the analog signals.
3336 experiment_names : str or list or None
3437 If multiple experiments are available, this argument allows users to select one
3538 or more experiments. If None, all experiements are loaded as blocks.
@@ -54,13 +57,14 @@ class OpenEphysBinaryRawIO(BaseRawIO):
5457 extensions = []
5558 rawmode = 'one-dir'
5659
57- def __init__ (self , dirname = '' , experiment_names = None ):
60+ def __init__ (self , dirname = '' , load_sync_channel = False , experiment_names = None ):
5861 BaseRawIO .__init__ (self )
5962 self .dirname = dirname
6063 if experiment_names is not None :
6164 if isinstance (experiment_names , str ):
6265 experiment_names = [experiment_names ]
6366 self .experiment_names = experiment_names
67+ self .load_sync_channel = load_sync_channel
6468 self .folder_structure = None
6569
6670 def _source_name (self ):
@@ -104,6 +108,8 @@ def _parse_header(self):
104108 new_channels = []
105109 for chan_info in d ['channels' ]:
106110 chan_id = chan_info ['channel_name' ]
111+ if "SYNC" in chan_id and not self .load_sync_channel :
112+ continue
107113 if chan_info ["units" ] == "" :
108114 # in some cases for some OE version the unit is "", but the gain is to "uV"
109115 units = "uV"
@@ -127,9 +133,25 @@ def _parse_header(self):
127133 for stream_index , d in self ._sig_streams [block_index ][seg_index ].items ():
128134 num_channels = len (d ['channels' ])
129135 memmap_sigs = np .memmap (d ['raw_filename' ], d ['dtype' ],
130- order = 'C' , mode = 'r' ).reshape (- 1 , num_channels )
136+ order = 'C' , mode = 'r' ).reshape (- 1 , num_channels )
137+ channel_names = [ch ["channel_name" ] for ch in d ["channels" ]]
138+ # if there is a sync channel and it should not be loaded,
139+ # find the right channel index and slice the memmap
140+ if any (["SYNC" in ch for ch in channel_names ]) and \
141+ not self .load_sync_channel :
142+ sync_channel_name = [ch for ch in channel_names if "SYNC" in ch ][0 ]
143+ sync_channel_index = channel_names .index (sync_channel_name )
144+
145+ # only sync channel in last position is supported to keep memmap
146+ if sync_channel_index == num_channels - 1 :
147+ memmap_sigs = memmap_sigs [:, :- 1 ]
148+ else :
149+ raise NotImplementedError ("SYNC channel removal is only supported "
150+ "when the sync channel is in the last "
151+ "position" )
131152 d ['memmap' ] = memmap_sigs
132153
154+
133155 # events zone
134156 # channel map: one channel one stream
135157 event_channels = []
0 commit comments