@@ -1375,7 +1375,6 @@ def _get_analogsignal_buffer_description(self, block_index, seg_index, buffer_id
13751375 raise (NotImplementedError )
13761376
13771377
1378-
13791378class BaseRawWithBufferApiIO (BaseRawIO ):
13801379 """
13811380 Generic class for reader that support "buffer api".
@@ -1402,7 +1401,7 @@ def _get_signal_size(self, block_index, seg_index, stream_index):
14021401 buffer_desc = self .get_analogsignal_buffer_description (block_index , seg_index , buffer_id )
14031402 # some hdf5 revert teh buffer
14041403 time_axis = buffer_desc .get ("time_axis" , 0 )
1405- return buffer_desc [' shape' ][time_axis ]
1404+ return buffer_desc [" shape" ][time_axis ]
14061405
14071406 def _get_analogsignal_chunk (
14081407 self ,
@@ -1413,57 +1412,63 @@ def _get_analogsignal_chunk(
14131412 stream_index : int ,
14141413 channel_indexes : list [int ] | None ,
14151414 ):
1416-
1415+
14171416 stream_id = self .header ["signal_streams" ][stream_index ]["id" ]
14181417 buffer_id = self .header ["signal_streams" ][stream_index ]["buffer_id" ]
1419-
1420- buffer_slice = self ._stream_buffer_slice [stream_id ]
14211418
1419+ buffer_slice = self ._stream_buffer_slice [stream_id ]
14221420
14231421 buffer_desc = self .get_analogsignal_buffer_description (block_index , seg_index , buffer_id )
14241422
14251423 i_start = i_start or 0
1426- i_stop = i_stop or buffer_desc [' shape' ][0 ]
1424+ i_stop = i_stop or buffer_desc [" shape" ][0 ]
14271425
1428- if buffer_desc [' type' ] == "raw" :
1426+ if buffer_desc [" type" ] == "raw" :
14291427
1430- # open files on demand and keep reference to opened file
1431- if not hasattr (self , ' _memmap_analogsignal_buffers' ):
1428+ # open files on demand and keep reference to opened file
1429+ if not hasattr (self , " _memmap_analogsignal_buffers" ):
14321430 self ._memmap_analogsignal_buffers = {}
14331431 if block_index not in self ._memmap_analogsignal_buffers :
14341432 self ._memmap_analogsignal_buffers [block_index ] = {}
14351433 if seg_index not in self ._memmap_analogsignal_buffers [block_index ]:
14361434 self ._memmap_analogsignal_buffers [block_index ][seg_index ] = {}
14371435 if buffer_id not in self ._memmap_analogsignal_buffers [block_index ][seg_index ]:
1438- fid = open (buffer_desc [' file_path' ], mode = 'rb' )
1436+ fid = open (buffer_desc [" file_path" ], mode = "rb" )
14391437 self ._memmap_analogsignal_buffers [block_index ][seg_index ][buffer_id ] = fid
14401438 else :
14411439 fid = self ._memmap_analogsignal_buffers [block_index ][seg_index ][buffer_id ]
1442-
1443- num_channels = buffer_desc ['shape' ][1 ]
1444-
1445- raw_sigs = get_memmap_chunk_from_opened_file (fid , num_channels , i_start , i_stop , np .dtype (buffer_desc ['dtype' ]), file_offset = buffer_desc ['file_offset' ])
14461440
1447-
1448- elif buffer_desc ['type' ] == 'hdf5' :
1441+ num_channels = buffer_desc ["shape" ][1 ]
1442+
1443+ raw_sigs = get_memmap_chunk_from_opened_file (
1444+ fid ,
1445+ num_channels ,
1446+ i_start ,
1447+ i_stop ,
1448+ np .dtype (buffer_desc ["dtype" ]),
1449+ file_offset = buffer_desc ["file_offset" ],
1450+ )
1451+
1452+ elif buffer_desc ["type" ] == "hdf5" :
14491453
1450- # open files on demand and keep reference to opened file
1451- if not hasattr (self , ' _hdf5_analogsignal_buffers' ):
1454+ # open files on demand and keep reference to opened file
1455+ if not hasattr (self , " _hdf5_analogsignal_buffers" ):
14521456 self ._hdf5_analogsignal_buffers = {}
14531457 if block_index not in self ._hdf5_analogsignal_buffers :
14541458 self ._hdf5_analogsignal_buffers [block_index ] = {}
14551459 if seg_index not in self ._hdf5_analogsignal_buffers [block_index ]:
14561460 self ._hdf5_analogsignal_buffers [block_index ][seg_index ] = {}
14571461 if buffer_id not in self ._hdf5_analogsignal_buffers [block_index ][seg_index ]:
14581462 import h5py
1459- h5file = h5py .File (buffer_desc ['file_path' ], mode = "r" )
1463+
1464+ h5file = h5py .File (buffer_desc ["file_path" ], mode = "r" )
14601465 self ._hdf5_analogsignal_buffers [block_index ][seg_index ][buffer_id ] = h5file
14611466 else :
14621467 h5file = self ._hdf5_analogsignal_buffers [block_index ][seg_index ][buffer_id ]
14631468
14641469 hdf5_path = buffer_desc ["hdf5_path" ]
14651470 full_raw_sigs = h5file [hdf5_path ]
1466-
1471+
14671472 time_axis = buffer_desc .get ("time_axis" , 0 )
14681473 if time_axis == 0 :
14691474 raw_sigs = full_raw_sigs [i_start :i_stop , :]
@@ -1475,31 +1480,28 @@ def _get_analogsignal_chunk(
14751480 if buffer_slice is not None :
14761481 raw_sigs = raw_sigs [:, buffer_slice ]
14771482
1478-
1479-
14801483 else :
14811484 raise NotImplementedError ()
14821485
14831486 # this is a pre slicing when the stream do not contain all channels (for instance spikeglx when load_sync_channel=False)
14841487 if buffer_slice is not None :
14851488 raw_sigs = raw_sigs [:, buffer_slice ]
1486-
1489+
14871490 # channel slice requested
14881491 if channel_indexes is not None :
14891492 raw_sigs = raw_sigs [:, channel_indexes ]
14901493
1491-
14921494 return raw_sigs
14931495
14941496 def __del__ (self ):
1495- if hasattr (self , ' _memmap_analogsignal_buffers' ):
1497+ if hasattr (self , " _memmap_analogsignal_buffers" ):
14961498 for block_index in self ._memmap_analogsignal_buffers .keys ():
14971499 for seg_index in self ._memmap_analogsignal_buffers [block_index ].keys ():
14981500 for buffer_id , fid in self ._memmap_analogsignal_buffers [block_index ][seg_index ].items ():
14991501 fid .close ()
15001502 del self ._memmap_analogsignal_buffers
15011503
1502- if hasattr (self , ' _hdf5_analogsignal_buffers' ):
1504+ if hasattr (self , " _hdf5_analogsignal_buffers" ):
15031505 for block_index in self ._hdf5_analogsignal_buffers .keys ():
15041506 for seg_index in self ._hdf5_analogsignal_buffers [block_index ].keys ():
15051507 for buffer_id , h5_file in self ._hdf5_analogsignal_buffers [block_index ][seg_index ].items ():
0 commit comments