aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-19 23:34:01 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-19 23:34:01 -0400
commitbbdf264d26f3e633997b71340292759ff012f5cd (patch)
treec0f2866c53820a618044617a6cebcd21c92f7db8 /qolab
parent93f893f3cd58549e7127c1ef9a2a6f1064b459bc (diff)
downloadqolab-bbdf264d26f3e633997b71340292759ff012f5cd.tar.gz
qolab-bbdf264d26f3e633997b71340292759ff012f5cd.zip
added bzip compression reading for traces
Diffstat (limited to 'qolab')
-rw-r--r--qolab/data/trace.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/qolab/data/trace.py b/qolab/data/trace.py
index 674922a..bda4da5 100644
--- a/qolab/data/trace.py
+++ b/qolab/data/trace.py
@@ -24,14 +24,29 @@ def loadTraceRawHeaderAndData(fname, tryCompressedIfMissing=True):
# this option is mainly for compatibility with old scripts which are not aware of compressed files
headerstr=[]
data = None
- if (not os.path.exists(fname)) and tryCompressedIfMissing and os.path.exists(fname+'.gz'):
- fname += '.gz'
+ if (not os.path.exists(fname)) and tryCompressedIfMissing:
+ if os.path.exists(fname+'.gz'):
+ fname += '.gz'
+ if os.path.exists(fname+'.bz'):
+ fname += '.bz'
+ if os.path.exists(fname+'.bz2'):
+ fname += '.bz2'
# we will try to guess if the file compressed
_open = open
- if fname[-3:] == '.gz':
- # TODO improve detection: gzip files have first 2 bytes set to b'\x1f\x8b'
- import gzip
- _open = gzip.open
+ for ext in ['gz', 'bz', 'bz2']:
+ b, fext = os.path.splitext(fname)
+ if fext != '.'+ext:
+ continue
+ if fext == '.gz':
+ # TODO improve detection: gzip files have first 2 bytes set to b'\x1f\x8b'
+ import gzip
+ _open = gzip.open
+ break
+ if ( fext == '.bz') or (fext == '.bz2'):
+ # TODO improve detection: bzip files have first 2 bytes set to b'BZ'
+ import bz2
+ _open = bz2.open
+ break
with _open(fname, mode='rb') as tracefile:
# Reading yaml header prefixed by '% '
# It sits at the top and below is just data in TSV format