def track_gen(track_points): n_streams = 0 iflogger.info('Reading tracks...') while True: n_pts = track_points[n_streams] pts_str = fileobj.read(n_pts * bytesize) nan_str = fileobj.read(bytesize) if len(pts_str) < (n_pts * bytesize): if not n_streams == stream_count: raise HeaderError('Expecting %s points, found only %s' % (stream_count, n_streams)) iflogger.error('Expecting %s points, found only %s' % (stream_count, n_streams)) break pts = np.ndarray(shape=(n_pts, pt_cols), dtype=f4dt, buffer=pts_str) nan_pt = np.ndarray(shape=(1, pt_cols), dtype=f4dt, buffer=nan_str) if np.isfinite(nan_pt[0][0]): raise ValueError break xyz = pts[:, :3] yield xyz n_streams += 1 if n_streams == stream_count: iflogger.info('100% : {n} tracks read'.format(n=n_streams)) raise StopIteration if n_streams % (float(stream_count) / 100) == 0: percent = int(float(n_streams) / float(stream_count) * 100) iflogger.info('{p}% : {n} tracks read'.format(p=percent, n=n_streams))
def track_gen(track_points): n_streams = 0 iflogger.info('Reading tracks...') while True: try: n_pts = track_points[n_streams] except IndexError: break pts_str = fileobj.read(n_pts * bytesize) nan_str = fileobj.read(bytesize) if len(pts_str) < (n_pts * bytesize): if not n_streams == stream_count: raise HeaderError('Expecting %s points, found only %s' % (stream_count, n_streams)) iflogger.error('Expecting %s points, found only %s', stream_count, n_streams) break pts = np.ndarray(shape=(n_pts, pt_cols), dtype=f4dt, buffer=pts_str) nan_pt = np.ndarray(shape=(1, pt_cols), dtype=f4dt, buffer=nan_str) if np.isfinite(nan_pt[0][0]): raise ValueError break xyz = pts[:, :3] yield xyz n_streams += 1 if n_streams == stream_count: iflogger.info('100%% : %i tracks read', n_streams) raise StopIteration try: if n_streams % int(stream_count / 100) == 0: percent = int(float(n_streams) / float(stream_count) * 100) iflogger.info('%i%% : %i tracks read', percent, n_streams) except ZeroDivisionError: iflogger.info('%i stream read out of %i', n_streams, stream_count)