jlblancoc commited on
Commit
cd92717
·
verified ·
1 Parent(s): bce7482

Plain-text copy: format description and NumPy reader

Browse files
Files changed (2) hide show
  1. text/README.md +49 -0
  2. text/mvsim_lio_text.py +131 -0
text/README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MVSim-LIO: plain-text copy
2
+
3
+ The same data as the `.rawlog` files, in plain-text tables compressed with xz
4
+ (read by Python's standard `lzma` module, `xz -d`, 7-Zip and most archivers).
5
+ `mvsim_lio_text.py` reads them with Python 3 and NumPy only.
6
+
7
+ One folder per sequence variant, `text/<world>/<trajectory>/<variant>/`, and
8
+ the 200 Hz ground truth of each sequence, `text/<world>/<trajectory>/gt_200hz.tum.xz`.
9
+
10
+ | file | content |
11
+ |---|---|
12
+ | `lidar.txt.xz` | one LiDAR point per line: `t_ns x y z ring label instance` |
13
+ | `sweeps.txt.xz` | one sweep per line: `sweep stamp_s num_points` |
14
+ | `imu.txt.xz` | `stamp_s wx wy wz ax ay az` |
15
+ | `odometry.txt.xz` | `stamp_s x y yaw vx vy omega` |
16
+ | `extrinsics.yaml` | poses of the LiDAR and the IMU in `base_link` |
17
+ | `gt.tum`, `lidar1.gt.tum` | ground truth of `base_link` and of the LiDAR at the sweep stamps (TUM: `stamp_s x y z qx qy qz qw`) |
18
+ | `errors.json` | parameters of the LiDAR error model drawn for this sequence (`real` variants) |
19
+ | `counts.json` | numbers of sweeps, points, IMU and odometry readings |
20
+
21
+ Conventions:
22
+
23
+ - `lidar.txt` lists the sweeps one after another, in the order of
24
+ `sweeps.txt`; sweep `k` has `num_points` lines. The first line of every
25
+ table is a `#` header.
26
+ - Point coordinates are in meters, rounded to 1 mm, in the LiDAR frame at the
27
+ point's own firing time `stamp_s + t_ns * 1e-9` (rolling shutter: `t_ns`
28
+ grows with the column; global shutter: `t_ns = 0`). `ring` is the beam
29
+ index, `label` the semantic class and `instance` the object
30
+ instance (0: none), as in the rawlogs.
31
+ - `stamp_s`: seconds, 7 decimals, on the single clock of the simulation.
32
+ - IMU: angular velocity [rad/s] and specific force [m/s^2] in the IMU frame
33
+ (at rest, `az` is about +9.8).
34
+ - Odometry: planar pose and velocity of `base_link` derived from the ground
35
+ truth; meaningful only for wheeled carriers.
36
+
37
+ Differences from the rawlogs: point coordinates are rounded to 1 mm (0.3 mm
38
+ RMS) and `t_ns` to 1 ns; everything else is printed with at least 9
39
+ significant digits.
40
+
41
+ ```python
42
+ import numpy as np
43
+ import mvsim_lio_text as m
44
+ d = 'text/office/spins/os1_32-real-rolling'
45
+ for k, stamp, pts in m.iter_sweeps(d): # pts: structured array, one sweep
46
+ xyz = np.c_[pts['x'], pts['y'], pts['z']]
47
+ imu = m.read_imu(d)
48
+ gt = m.read_tum(d + '/gt.tum')
49
+ ```
text/mvsim_lio_text.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reader for the plain-text copy of MVSim-LIO. Needs only Python 3 and NumPy.
3
+
4
+ Each sequence variant is a folder `<world>/<trajectory>/<variant>/` with:
5
+
6
+ lidar.txt.xz t_ns x y z ring label instance (one point per line, sweep after sweep)
7
+ sweeps.txt.xz sweep stamp_s num_points
8
+ imu.txt.xz stamp_s wx wy wz ax ay az
9
+ odometry.txt.xz stamp_s x y yaw vx vy omega
10
+ extrinsics.yaml LiDAR and IMU poses in base_link
11
+
12
+ Usage as a script: mvsim_lio_text.py <variant folder> (prints a summary)
13
+ """
14
+ import bz2
15
+ import gzip
16
+ import io
17
+ import itertools
18
+ import lzma
19
+ import sys
20
+ from pathlib import Path
21
+
22
+ import numpy as np
23
+
24
+ LIDAR_DTYPE = np.dtype([('t_ns', np.int64), ('x', np.float32),
25
+ ('y', np.float32), ('z', np.float32), ('ring', np.uint16),
26
+ ('label', np.uint16), ('instance', np.uint16)])
27
+ SWEEP_DTYPE = np.dtype([('sweep', np.int32), ('stamp', np.float64), ('num_points', np.int64)])
28
+ IMU_DTYPE = np.dtype([('stamp', np.float64), ('wx', np.float64), ('wy', np.float64),
29
+ ('wz', np.float64), ('ax', np.float64), ('ay', np.float64),
30
+ ('az', np.float64)])
31
+ ODOM_DTYPE = np.dtype([('stamp', np.float64), ('x', np.float64), ('y', np.float64),
32
+ ('yaw', np.float64), ('vx', np.float64), ('vy', np.float64),
33
+ ('omega', np.float64)])
34
+
35
+
36
+ def _open(folder, name):
37
+ """Opens `name` in `folder`, compressed (.xz, .bz2, .gz) or not, as text."""
38
+ folder = Path(folder)
39
+ for ext, opener in (('.xz', lzma.open), ('.bz2', bz2.open), ('.gz', gzip.open),
40
+ ('', open)):
41
+ p = folder / (name + ext)
42
+ if p.exists():
43
+ return io.TextIOWrapper(opener(p, 'rb'), encoding='ascii') if ext else open(p)
44
+ raise FileNotFoundError(folder / name)
45
+
46
+
47
+ def _table(folder, name, dtype, max_rows=None):
48
+ with _open(folder, name) as f:
49
+ a = np.loadtxt(f, dtype=dtype, comments='#', max_rows=max_rows, ndmin=1)
50
+ return a
51
+
52
+
53
+ def read_sweeps(folder):
54
+ return _table(folder, 'sweeps.txt', SWEEP_DTYPE)
55
+
56
+
57
+ def read_imu(folder):
58
+ return _table(folder, 'imu.txt', IMU_DTYPE)
59
+
60
+
61
+ def read_odometry(folder):
62
+ return _table(folder, 'odometry.txt', ODOM_DTYPE)
63
+
64
+
65
+ def read_lidar(folder, max_points=None):
66
+ """All points as one structured array (t_ns, x, y, z, ring, label, instance), and the
67
+ sweep index of each point."""
68
+ pts = _table(folder, 'lidar.txt', LIDAR_DTYPE, max_rows=max_points)
69
+ sw = read_sweeps(folder)
70
+ sweep = np.repeat(sw['sweep'], sw['num_points'])[:len(pts)]
71
+ return pts, sweep
72
+
73
+
74
+ def iter_sweeps(folder):
75
+ """Yields (sweep index, stamp [s], points) one sweep at a time, in bounded memory.
76
+
77
+ Point `i` was measured at stamp + t_ns[i] * 1e-9 and is expressed in the LiDAR frame
78
+ at that instant.
79
+ """
80
+ sweeps = read_sweeps(folder)
81
+ with _open(folder, 'lidar.txt') as f:
82
+ header = f.readline()
83
+ if not header.startswith('#'):
84
+ raise ValueError('lidar.txt: missing header line')
85
+ for s in sweeps:
86
+ n = int(s['num_points'])
87
+ # Exactly n lines: loadtxt alone may read ahead from a shared handle.
88
+ pts = np.loadtxt(itertools.islice(f, n), dtype=LIDAR_DTYPE, ndmin=1)
89
+ if len(pts) != n:
90
+ raise ValueError(f'sweep {s["sweep"]}: {len(pts)} points, expected {n}')
91
+ yield int(s['sweep']), float(s['stamp']), pts
92
+
93
+
94
+ def read_extrinsics(folder):
95
+ """The two sensor poses: {'lidar': {...}, 'imu': {...}} (a minimal YAML subset parser)."""
96
+ out = {}
97
+ cur = None
98
+ for line in (Path(folder) / 'extrinsics.yaml').read_text().splitlines():
99
+ if not line.strip():
100
+ continue
101
+ if not line.startswith(' '):
102
+ cur = out.setdefault(line.rstrip(':'), {})
103
+ continue
104
+ key, val = (s.strip() for s in line.split(':', 1))
105
+ if val.startswith('['):
106
+ cur[key] = [float(v) for v in val.strip('[]').split(',')]
107
+ else:
108
+ cur[key] = val
109
+ return out
110
+
111
+
112
+ def read_tum(path):
113
+ """A TUM trajectory: stamp_s x y z qx qy qz qw, as an (N, 8) array."""
114
+ return np.loadtxt(path, comments='#', ndmin=2)
115
+
116
+
117
+ def main():
118
+ folder = Path(sys.argv[1])
119
+ print('extrinsics:', read_extrinsics(folder))
120
+ sw = read_sweeps(folder)
121
+ print(f'{len(sw)} sweeps, {sw["num_points"].sum()} points, '
122
+ f'{sw["stamp"][0]:.3f} to {sw["stamp"][-1]:.3f} s')
123
+ imu = read_imu(folder)
124
+ print(f'{len(imu)} IMU readings, mean acc {imu["az"].mean():.3f} m/s^2 (z)')
125
+ _, stamp, pts = next(iter_sweeps(folder))
126
+ print(f'first sweep at {stamp:.3f} s: {len(pts)} points, '
127
+ f'range {np.hypot(pts["x"], pts["y"]).max():.1f} m')
128
+
129
+
130
+ if __name__ == '__main__':
131
+ main()