@@ -416,13 +416,17 @@ def epochsamples2times(
416416 samples : np .ndarray ,
417417 ) -> np .ndarray :
418418 """
419- Convert sample indices to time.
419+ Convert 0-based sample indices to time.
420+
421+ Note:
422+ Unlike MATLAB (1-based), Python sample indices are 0-based.
423+ Sample 0 corresponds to time t0 of the epoch.
420424
421425 Args:
422426 channeltype: Channel type(s)
423427 channel: Channel number(s)
424428 epochfiles: Files for this epoch
425- samples: Sample indices (1-indexed )
429+ samples: Sample indices (0-based )
426430
427431 Returns:
428432 Time values
@@ -442,7 +446,7 @@ def epochsamples2times(
442446 t0 = t0t1 [0 ][0 ]
443447
444448 samples = np .asarray (samples )
445- t = t0 + ( samples - 1 ) / sr
449+ t = t0 + samples / sr
446450
447451 # Handle infinite values
448452 if np .any (np .isinf (samples )):
@@ -458,7 +462,11 @@ def epochtimes2samples(
458462 times : np .ndarray ,
459463 ) -> np .ndarray :
460464 """
461- Convert time to sample indices.
465+ Convert time to 0-based sample indices.
466+
467+ Note:
468+ Unlike MATLAB (1-based), Python sample indices are 0-based.
469+ Sample 0 corresponds to time t0 of the epoch.
462470
463471 Args:
464472 channeltype: Channel type(s)
@@ -467,7 +475,7 @@ def epochtimes2samples(
467475 times: Time values
468476
469477 Returns:
470- Sample indices (1-indexed )
478+ Sample indices (0-based )
471479 """
472480 if isinstance (channel , int ):
473481 channel = [channel ]
@@ -484,11 +492,11 @@ def epochtimes2samples(
484492 t0 = t0t1 [0 ][0 ]
485493
486494 times = np .asarray (times )
487- s = 1 + np .round ((times - t0 ) * sr ).astype (int )
495+ s = np .round ((times - t0 ) * sr ).astype (int )
488496
489497 # Handle infinite values
490498 if np .any (np .isinf (times )):
491- s [np .isinf (times ) & (times < 0 )] = 1
499+ s [np .isinf (times ) & (times < 0 )] = 0
492500
493501 return s
494502
@@ -656,9 +664,9 @@ def readchannels_epochsamples_ingested(
656664 channeltype , channel , epochfiles , np .array (t0_t1 [0 ]), session
657665 )
658666 if np .isinf (s0 ):
659- s0 = int (abs_s [0 ]) - 1 # Convert 1-based to 0-based
667+ s0 = int (abs_s [0 ])
660668 if np .isinf (s1 ):
661- s1 = int (abs_s [1 ]) - 1 # Convert 1-based to 0-based
669+ s1 = int (abs_s [1 ])
662670
663671 # Get channel info for group decoding
664672 full_channel_info = self .getchannelsepoch_ingested (epochfiles , session )
@@ -967,13 +975,17 @@ def epochsamples2times_ingested(
967975 session : Any ,
968976 ) -> np .ndarray :
969977 """
970- Convert sample indices to time for an ingested epoch.
978+ Convert 0-based sample indices to time for an ingested epoch.
979+
980+ Note:
981+ Unlike MATLAB (1-based), Python sample indices are 0-based.
982+ Sample 0 corresponds to time t0 of the epoch.
971983
972984 Args:
973985 channeltype: Channel type(s)
974986 channel: Channel number(s)
975987 epochfiles: Files for this epoch (starting with epochid://)
976- samples: Sample indices (1-indexed )
988+ samples: Sample indices (0-based )
977989 session: ndi_session object with database access
978990
979991 Returns:
@@ -994,7 +1006,7 @@ def epochsamples2times_ingested(
9941006 t0 = t0t1 [0 ][0 ]
9951007
9961008 samples = np .asarray (samples )
997- t = t0 + ( samples - 1 ) / sr
1009+ t = t0 + samples / sr
9981010
9991011 if np .any (np .isinf (samples )):
10001012 t [np .isinf (samples ) & (samples < 0 )] = t0
@@ -1010,7 +1022,11 @@ def epochtimes2samples_ingested(
10101022 session : Any ,
10111023 ) -> np .ndarray :
10121024 """
1013- Convert time to sample indices for an ingested epoch.
1025+ Convert time to 0-based sample indices for an ingested epoch.
1026+
1027+ Note:
1028+ Unlike MATLAB (1-based), Python sample indices are 0-based.
1029+ Sample 0 corresponds to time t0 of the epoch.
10141030
10151031 Args:
10161032 channeltype: Channel type(s)
@@ -1020,7 +1036,7 @@ def epochtimes2samples_ingested(
10201036 session: ndi_session object with database access
10211037
10221038 Returns:
1023- Sample indices (1-indexed )
1039+ Sample indices (0-based )
10241040 """
10251041 if isinstance (channel , int ):
10261042 channel = [channel ]
@@ -1037,9 +1053,9 @@ def epochtimes2samples_ingested(
10371053 t0 = t0t1 [0 ][0 ]
10381054
10391055 times = np .asarray (times )
1040- s = 1 + np .round ((times - t0 ) * sr ).astype (int )
1056+ s = np .round ((times - t0 ) * sr ).astype (int )
10411057
10421058 if np .any (np .isinf (times )):
1043- s [np .isinf (times ) & (times < 0 )] = 1
1059+ s [np .isinf (times ) & (times < 0 )] = 0
10441060
10451061 return s
0 commit comments