aboutsummaryrefslogtreecommitdiff
path: root/qolab/file_utils/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/file_utils/__init__.py')
-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.