aboutsummaryrefslogtreecommitdiff
path: root/qolab/file_utils
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-20 22:49:36 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-20 22:50:13 -0400
commit9e9bde6c54fec0a3143be2062453611d3ad955e7 (patch)
tree3c8609a48e2a028e5d8b2e2bcae12804262749b8 /qolab/file_utils
parentd8b4e87f3185c2cc99dd1171bdff1c169ceb2c83 (diff)
downloadqolab-9e9bde6c54fec0a3143be2062453611d3ad955e7.tar.gz
qolab-9e9bde6c54fec0a3143be2062453611d3ad955e7.zip
separate infer_compression method
Diffstat (limited to 'qolab/file_utils')
-rw-r--r--qolab/file_utils/__init__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/qolab/file_utils/__init__.py b/qolab/file_utils/__init__.py
index e61811e..bcc0824 100644
--- a/qolab/file_utils/__init__.py
+++ b/qolab/file_utils/__init__.py
@@ -69,6 +69,16 @@ def get_next_data_file(prefix, savepath, run_number=None, datestr=None, date_for
fname = os.path.join(savepath, f'{prefix}_{datestr}_{run_number:05d}.{extension}')
return(fname)
+def infer_compression(fname):
+ """Infers compression algorithm from filename extension"""
+ compression = None # usual suspect
+ b, fext = os.path.splitext(fname)
+ if fext == '.gz':
+ compression = 'gzip'
+ elif ( fext == '.bz') or (fext == '.bz2'):
+ compression = 'bzip'
+ return compression
+
def save_table_with_header(fname, data, header='', comment_symbol='%', skip_headers_if_file_exist=False, item_format='e', item_separator='\t', compressionmethod=None, compresslevel=9):
"""Saves output to CSV or TSV file with specially formatted header.