From 32d2548af8532be9ef0ef9e9917357d15cd1a60e Mon Sep 17 00:00:00 2001 From: David Ojeda Date: Tue, 26 Feb 2019 16:23:57 +0100 Subject: [PATCH] Implement optional sorting of streams by name Addresses https://github.com/sccn/xdf/issues/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. --- Python/pyxdf/pyxdf.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Python/pyxdf/pyxdf.py b/Python/pyxdf/pyxdf.py index 6cf5f49..d0483cb 100644 --- a/Python/pyxdf/pyxdf.py +++ b/Python/pyxdf/pyxdf.py @@ -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. @@ -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 @@ -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