Skip to content

Commit

Permalink
Implement optional sorting of streams by name
Browse files Browse the repository at this point in the history
Addresses sccn#35 but note:
apparently, one should not count on a specific order of streams (it can be
arbitrary). I am still not sure if this warning concerns the StreamId as well.
  • Loading branch information
dojeda committed Feb 26, 2019
1 parent 52596b3 commit 32d2548
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Python/pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def load_xdf(filename,
clock_reset_threshold_offset_seconds=1,
clock_reset_threshold_offset_stds=10,
winsor_threshold=0.0001,
sort_streams=True,
headers_only=False):
"""Import an XDF file.
Expand Down Expand Up @@ -99,6 +100,9 @@ def load_xdf(filename,
headers_only: Read only the file and stream header. No stream data will
be decoded. (default: False)
sort_streams: Sort the streams by their names, as present in their
stream headers. (default: True)
Parameters for jitter removal in the presence of data breaks:
jitter_break_threshold_seconds : An interruption in a regularly-sampled
Expand Down Expand Up @@ -390,8 +394,9 @@ def __init__(self, xml):
stream['time_stamps'] = tmp.time_stamps

streams = [s for s in streams.values()]
sort_data = [s['info']['name'][0] for s in streams]
streams = [x for _, x in sorted(zip(sort_data, streams))]
if sort_streams:
streams.sort(key=lambda s: s['info']['name'])

return streams, fileheader


Expand Down

0 comments on commit 32d2548

Please sign in to comment.