@@ -71,7 +71,7 @@ def load_xdf(filename,
7171 synchronize_clocks = True ,
7272 handle_clock_resets = True ,
7373 dejitter_timestamps = True ,
74- sync_timestamps = False ,
74+ sync_timestamps = False ,
7575 overlap_timestamps = False ,
7676 jitter_break_threshold_seconds = 1 ,
7777 jitter_break_threshold_samples = 500 ,
@@ -388,12 +388,10 @@ def load_xdf(filename,
388388 logger .warning ('sync_timestamps defaults to "linear"' )
389389 streams = _sync_timestamps (streams , kind = sync_timestamps )
390390
391-
392- # limit streams to their overlapping periods
391+ # limit streams to their overlapping periods
393392 if overlap_timestamps :
394393 streams = _limit_streams_to_overlap (streams )
395394
396-
397395 streams = [s for s in streams .values ()]
398396 return streams , fileheader
399397
@@ -784,17 +782,17 @@ def _parse_streamheader(xml):
784782 return {el .tag : el .text for el in xml if el .tag != "desc" }
785783
786784
787- def _interpolate (x :np .ndarray , y :np .ndarray , new_x :np .ndarray ,
785+ def _interpolate (x : np .ndarray , y : np .ndarray , new_x : np .ndarray ,
788786 kind = 'linear' ) -> np .ndarray :
789787 '''Perform interpolation for _sync_timestamps
790788
791789 If scipy is not installed, the method falls back to numpy, and then only
792- support linear interpolation.
790+ supports linear interpolation.
793791 '''
794792 try :
795793 from scipy .interpolate import interp1d
796794 f = interp1d (x , y , kind = kind , axis = 0 ,
797- assume_sorted = True , # speed up
795+ assume_sorted = True , # speed up
798796 bounds_error = False )
799797 return f (new_x )
800798 except ImportError as e :
@@ -803,9 +801,9 @@ def _interpolate(x:np.ndarray, y:np.ndarray, new_x:np.ndarray,
803801 else :
804802 return np .interp (new_x , xp = x , fp = y , left = np .NaN , right = np .NaN )
805803
804+
806805def _sync_timestamps (streams , kind = 'linear' ):
807- '''syncs all streams to the fastest sampling rate by shifting or
808- upsampling
806+ '''Sync all streams to the fastest sampling rate by shifting or upsampling.
809807
810808 Depending on a streams channel-format, extrapolation is performed using
811809 with NaNs (numerical formats) or with [''] (string format).
@@ -828,7 +826,7 @@ def _sync_timestamps(streams, kind='linear'):
828826 srates = [stream ['info' ][srate_key ] for stream in streams .values ()]
829827 max_fs = max (srates , default = 0 )
830828
831- if max_fs == 0 : # either no valid stream or all streams are async
829+ if max_fs == 0 : # either no valid stream or all streams are async
832830 return streams
833831 if srates .count (max_fs ) > 1 :
834832 # highly unlikely, with floating point precision and sampling noise
@@ -863,8 +861,7 @@ def _sync_timestamps(streams, kind='linear'):
863861 for stream in streams .values ():
864862 channel_format = stream ['info' ]['channel_format' ][0 ]
865863
866- if ( (channel_format == 'string' ) and
867- (stream ['info' ][srate_key ]== 0 ) ):
864+ if ((channel_format == 'string' ) and (stream ['info' ][srate_key ] == 0 )):
868865 # you can't really interpolate strings; and streams with srate=0
869866 # don't have a real sampling rate. One approach to sync them is to
870867 # shift their events to the nearest timestamp of the new
@@ -902,12 +899,10 @@ def _sync_timestamps(streams, kind='linear'):
902899 # i am stuck with float64s, as integers have no nans
903900 # therefore i round to the nearest integer instead
904901 stream ['time_series' ] = np .around (stream ['time_series' ], 0 )
905-
906-
907902 else :
908- raise NotImplementedError ("Don't know how to sync sampling for " +
909- ' channel_format={}' . format (
910- channel_format ))
903+ raise NotImplementedError ("Don't know how to sync sampling for "
904+ " channel_format="
905+ "{}" . format ( channel_format ))
911906 stream ['info' ]['effective_srate' ] = max_fs
912907
913908 return streams
@@ -928,7 +923,7 @@ def _limit_streams_to_overlap(streams):
928923 # skip streams with fs=0 or if they send strings, because they might
929924 # just not yet have send anything on purpose (i.e. markers)
930925 # while other data was already being recorded.
931- if (stream ['info' ]['effective_srate' ] != 0 and
926+ if (stream ['info' ]['effective_srate' ] != 0 and
932927 stream ['info' ]['channel_format' ][0 ] != 'string' ):
933928 # extrapolation in _sync_timestamps is done with NaNs
934929 not_extrapolated = np .where (~ np .isnan (stream ['time_series' ]))[0 ]
@@ -940,9 +935,9 @@ def _limit_streams_to_overlap(streams):
940935 for stream in streams .values ():
941936 # use np.around to prevent floating point hickups
942937 around = np .around (stream ['time_stamps' ], 15 )
943- a = np .where (around >= ts_first )[0 ]
944- b = np .where (around <= ts_last )[0 ]
945- select = np .intersect1d (a ,b )
938+ a = np .where (around >= ts_first )[0 ]
939+ b = np .where (around <= ts_last )[0 ]
940+ select = np .intersect1d (a , b )
946941 if type (stream ['time_stamps' ]) is list :
947942 stream ['time_stamps' ] = [stream ['time_stamps' ][s ] for s in select ]
948943 else :
@@ -954,5 +949,3 @@ def _limit_streams_to_overlap(streams):
954949 stream ['time_series' ] = stream ['time_series' ][select ]
955950
956951 return streams
957-
958-
0 commit comments