@@ -78,6 +78,18 @@ def main():
7878 help = "Exclude days with wear time below threshold. Pass values as strings, e.g.: '12H', '30min'. Default: None (no exclusion)" ,
7979 type = str ,
8080 default = None )
81+ parser .add_argument (
82+ "--csvStartRow" ,
83+ help = "Row number to start reading a CSV file. Default: 0" ,
84+ type = int ,
85+ default = 0 ,
86+ )
87+ parser .add_argument ("--txyz" ,
88+ help = ("Use this option to specify the column names for time, x, y, z "
89+ "in the input file, in that order. Use a comma-separated string. "
90+ "Only needed for CSV files, can be ignored for other file types. "
91+ "Default: 'time,x,y,z'" ),
92+ type = str , default = "time,x,y,z" )
8193 parser .add_argument (
8294 "--plot-activity" ,
8395 "-p" ,
@@ -129,6 +141,8 @@ def main():
129141 # Load file
130142 data , info_read = read (
131143 args .filepath ,
144+ args .txyz ,
145+ args .csvStartRow - 1 , # -1 to convert to zero-based index
132146 resample_hz = None ,
133147 sample_rate = args .sample_rate ,
134148 verbose = verbose ,
@@ -258,27 +272,33 @@ def main():
258272
259273
260274def read (
261- filepath , resample_hz = "uniform" , sample_rate = None , lowpass_hz = None , verbose = True
275+ filepath , usecols , skipRows = 0 , resample_hz = "uniform" ,
276+ sample_rate = None , lowpass_hz = None , verbose = True
262277):
263278
264279 p = pathlib .Path (filepath )
265280 ftype = p .suffixes [0 ].lower ()
266281 fsize = round (p .stat ().st_size / (1024 * 1024 ), 1 )
267282
268283 if ftype in (".csv" , ".pkl" ):
269-
270284 if ftype == ".csv" :
285+ tcol , xcol , ycol , zcol = usecols .split (',' )
286+
271287 data = pd .read_csv (
272288 filepath ,
273- usecols = ["time" , "x" , "y" , "z" ],
274- parse_dates = ["time" ],
275- index_col = "time" ,
276- dtype = {"x" : "f4" , "y" : "f4" , "z" : "f4" },
289+ usecols = [tcol , xcol , ycol , zcol ],
290+ parse_dates = [tcol ],
291+ index_col = tcol ,
292+ dtype = {xcol : "f4" , ycol : "f4" , zcol : "f4" },
293+ skiprows = skipRows ,
277294 )
295+
296+ # rename to standard names
297+ data = data .rename (columns = {xcol : 'x' , ycol : 'y' , zcol : 'z' })
298+ data .index .name = 'time'
299+
278300 elif ftype == ".pkl" :
279301 data = pd .read_pickle (filepath )
280- else :
281- raise ValueError (f"Unknown file format: { ftype } " )
282302
283303 if sample_rate in (None , False ):
284304 freq = infer_freq (data .index )
@@ -319,6 +339,9 @@ def read(
319339 verbose = verbose ,
320340 )
321341
342+ else :
343+ raise ValueError (f"Unknown file format: { ftype } " )
344+
322345 if "ResampleRate" not in info :
323346 info ["ResampleRate" ] = info ["SampleRate" ]
324347
0 commit comments