1+ """TSV file reader for time-series data with real-time playback support.
2+
3+ This module provides a specialized TSV reader for motion capture and sensor data
4+ files, supporting multiple reading modes including real-time playback simulation.
5+ """
6+
17import numpy as np
28import time
39
410class TSVReader :
11+ """TSV file reader with multiple reading modes for time-series data.
12+
13+ Provides three reading modes:
14+ 1. Block reading: Read fixed-size chunks of data
15+ 2. Time-based access: Get data at specific time points
16+ 3. Real-time iteration: Simulate real-time playback with timing delays
17+
18+ Parameters
19+ ----------
20+ time_col : str, optional
21+ Name of the column containing time values (default: "Time").
22+ """
23+
524 def __init__ (self , time_col = "Time" ):
625 self .time_col = time_col
726 self .headers = []
@@ -47,17 +66,19 @@ def _set_use_time_and_speed(self, factor=1.0):
4766 self .time_value = None
4867 self .n = None
4968
50- # ------------------- LOAD FILE -------------------
5169 def _load_file (self ):
52- """Carica il file TSV velocemente usando np.loadtxt."""
70+ """Load TSV file quickly using np.loadtxt.
71+
72+ Expects a TSV file with a header line starting with 'Frame'.
73+ """
5374 with open (self .filename , "r" ) as f :
5475 for i , line in enumerate (f ):
5576 if line .startswith ("Frame" ):
5677 header_idx = i
5778 self .headers = line .strip ().split ("\t " )
5879 break
5980 else :
60- raise ValueError ("Header 'Frame...' non trovato " )
81+ raise ValueError ("Header 'Frame...' not found " )
6182
6283 self .data = np .loadtxt (self .filename , delimiter = "\t " , skiprows = header_idx + 1 , dtype = float )
6384 if self .data .ndim == 1 :
@@ -66,7 +87,7 @@ def _load_file(self):
6687 try :
6788 time_idx = self .headers .index (self .time_col )
6889 except ValueError :
69- raise ValueError (f"Colonna '{ self .time_col } ' non trovata negli header " )
90+ raise ValueError (f"Column '{ self .time_col } ' not found in headers " )
7091
7192 self .time_data = self .data [:, time_idx ]
7293
0 commit comments