Skip to content

Commit

Permalink
Implement quick read of file by reading headers and ignoring data
Browse files Browse the repository at this point in the history
This is the approach presented in sccn#37
  • Loading branch information
dojeda committed Feb 26, 2019
1 parent e4ee0be commit e209638
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Python/pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def load_xdf(filename,
clock_reset_threshold_stds=5,
clock_reset_threshold_offset_seconds=1,
clock_reset_threshold_offset_stds=10,
winsor_threshold=0.0001):
winsor_threshold=0.0001,
headers_only=False):
"""Import an XDF file.
This is an importer for multi-stream XDF (Extensible Data Format)
Expand Down Expand Up @@ -94,6 +95,9 @@ def load_xdf(filename,
will be treated robustly (i.e., like outliers), in seconds
(default: 0.0001)
headers_only: Read only the file and stream header. No stream data will
be decoded. (default: False)
Parameters for jitter removal in the presence of data breaks:
jitter_break_threshold_seconds : An interruption in a regularly-sampled
Expand Down Expand Up @@ -246,6 +250,17 @@ def __init__(self, xml):

logger.debug(log_str)

# Quick read of header only: when the chunk if not a header, move
# the file pointer to the beginning of the next chunk
if headers_only and tag not in (1, 2):
offset = 2 # We already read 2 bytes for the tag
if tag in (2, 3, 4, 6):
# In these cases, we already read 4 bytes!
offset += 4
# Move n=chunklen-offset bytes forward, relative to current position (whence=1)
f.seek(chunklen - offset, 1)
continue

# read the chunk's [Content]...
if tag == 1:
# read [FileHeader] chunk
Expand Down

0 comments on commit e209638

Please sign in to comment.