utiasSTARS / pykitti

Python tools for working with KITTI data.
MIT License
1.15k stars 239 forks source link

raw time stamp parsing error #30

Closed walchko closed 6 years ago

walchko commented 6 years ago

I don't think you are parsing the raw time stamps correctly in raw.py. When I try to do this in python 3.7 on macOS, I get the same as when I ignore the fractional seconds:

>>> s = '2011-09-28 12:26:18.089952593'
>>> time.mktime(datetime.datetime.strptime(s[:-4], "%Y-%m-%d %I:%M:%S.%f").timetuple())
1317191178.0
>>> time.mktime(datetime.datetime.strptime(s[:-10], "%Y-%m-%d %I:%M:%S").timetuple())
1317191178.0

They are the same!

However, if I just turn the fractional part into a float and add it, I get (I think) the correct answer:

>>> time.mktime(datetime.datetime.strptime(s[:-10], "%Y-%m-%d %I:%M:%S").timetuple()) + float(s[-11:])
1317191186.0899527

Looking at the time stamp, I think (with this fractional part) is correct.

leeclemnet commented 6 years ago

The problem is that .timetuple() only works with second-level precision. To keep the microsecond precision, use .timestamp().

>>> s = '2011-09-28 12:26:18.089952593'
>>> t = datetime.datetime.strptime(s[:-4], "%Y-%m-%d %I:%M:%S.%f")
>>> t
datetime.datetime(2011, 9, 28, 0, 26, 18, 89950)
>>> t.timetuple()
time.struct_time(tm_year=2011, tm_mon=9, tm_mday=28, tm_hour=0, tm_min=26, tm_sec=18, tm_wday=2, tm_yday=271, tm_isdst=-1)
>>> time.mktime(t.timetuple())
1317183978.0
>>> t.timestamp()
1317183978.08995