From 076f9767a4f7f21cb91c3501c8544122334e238a Mon Sep 17 00:00:00 2001 From: Luca Scarabello <luca.scarabello@sed.ethz.ch> Date: Wed, 5 Apr 2017 15:18:22 +0200 Subject: [PATCH] Added backward compatibility of chunk/template file names --- TM/io.py | 38 ++++++++++++++++++++++++++------------ TM/setupclass.py | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/TM/io.py b/TM/io.py index 4b24e1a..e773b5e 100644 --- a/TM/io.py +++ b/TM/io.py @@ -1278,19 +1278,25 @@ def is_chunk_preloaded(chunkId, chunkTime, chunkLength, raw=True, processed=True basefilename = "chunk_%d_%s_%d" % (chunkId, chunkTime.strftime("%Y-%m-%dT%H-%M-%S"), chunkLength) basefilename = os.path.join(config.chunkCacheDir, basefilename) + # backward comaptibility (to be removed someday) + backward_fname = os.path.join(config.chunkCacheDir, ("chunk_%d" % chunkId) ) + # 1. the original waveform data (in float32 dtype/encoding) if raw: - if not os.path.isfile(basefilename + "_raw.mseed"): + if not os.path.isfile(basefilename + "_raw.mseed") and \ + not os.path.isfile(backward_fname + "_raw.mseed"): return False # 2. the (processed) waveform data in float32 dtype/encoding) if processed: - if not os.path.isfile(basefilename + "_proc.mseed"): + if not os.path.isfile(basefilename + "_proc.mseed") and \ + not os.path.isfile(backward_fname + "_proc.mseed"): return False # 3. the windowed standard deviation arrays (possibly incl. masks) if stdwin: - if not os.path.isfile(basefilename + "_stdwin.dat"): + if not os.path.isfile(basefilename + "_stdwin.dat") and \ + not os.path.isfile(backward_fname + "_stdwin.dat"): return False return True @@ -1310,7 +1316,7 @@ def read_chunk(chunkId, raw=True, processed=True, stdwin=True): # 1. the original waveform data (in float32 dtype/encoding) if raw: try: - file_list = glob.glob(basefilename + '_*_raw.mseed') + file_list = glob.glob(basefilename + '_*raw.mseed') if len(file_list) != 1: logger.error("Cannot read chunk %d, (files matching the pattern: %s)" % (chunkId, file_list)) @@ -1324,7 +1330,7 @@ def read_chunk(chunkId, raw=True, processed=True, stdwin=True): # 2. the (processed) waveform data (in float32 dtype/encoding) if processed: try: - file_list = glob.glob(basefilename + '_*_proc.mseed') + file_list = glob.glob(basefilename + '_*proc.mseed') if len(file_list) != 1: logger.error("Cannot read chunk %d, (files matching the pattern: %s)" % (chunkId, file_list)) @@ -1338,7 +1344,7 @@ def read_chunk(chunkId, raw=True, processed=True, stdwin=True): # 3. the windowed standard deviation arrays (possibly incl. masks) if stdwin: try: - file_list = glob.glob(basefilename + '_*_stdwin.dat') + file_list = glob.glob(basefilename + '_*stdwin.dat') if len(file_list) != 1: logger.error("Cannot read chunk %d, (files matching the pattern: %s)" % (chunkId, file_list)) @@ -1359,17 +1365,17 @@ def delete_chunk(chunkId): """ basefilename = os.path.join(config.chunkCacheDir, "chunk_%s" % chunkId) try: - for f in glob.glob(basefilename + '_*_raw.mseed'): # there should be just one + for f in glob.glob(basefilename + '_*raw.mseed'): # there should be just one os.remove(f) except: pass try: - for f in glob.glob(basefilename + '_*_proc.mseed'): # there should be just one + for f in glob.glob(basefilename + '_*proc.mseed'): # there should be just one os.remove(f) except: pass try: - for f in glob.glob(basefilename + '_*_stdwin.dat'): # there should be just one + for f in glob.glob(basefilename + '_*stdwin.dat'): # there should be just one os.remove(f) except: pass @@ -1547,7 +1553,15 @@ def is_template_preloaded(templateId, templateTime, templateLength): templateTime.strftime("%Y-%m-%dT%H-%M-%S"), templateLength) filename = os.path.join(dir_tp_mseed, filename) - return os.path.isfile(filename) + if not os.path.isfile(filename): + # + # Backward compatibility(to be removed someday) + # + filename = "template%02d_processed.mseed" % (templateId + 1) + filename = os.path.join(dir_tp_mseed, filename) + return os.path.isfile(filename) + + return True def read_template(templateId): """ @@ -1561,7 +1575,7 @@ def read_template(templateId): try: filename = os.path.join(config.directory, 'templates_mseed', 'template%02d' % (templateId + 1)) - file_list = glob.glob(filename + '_*_processed.mseed') + file_list = glob.glob(filename + '_*processed.mseed') if len(file_list) != 1: logger.error("Cannot read template %d, (files matching the pattern: %s)" % (templateId, file_list)) @@ -1586,7 +1600,7 @@ def delete_template(templateId): filename = os.path.join(config.directory, 'templates_mseed', 'template%02d' % (templateId + 1)) try: - for f in glob.glob(filename + '_*_processed.mseed'): # there should be just one + for f in glob.glob(filename + '_*processed.mseed'): # there should be just one os.remove(f) except: pass diff --git a/TM/setupclass.py b/TM/setupclass.py index 8a8be62..4f0b441 100644 --- a/TM/setupclass.py +++ b/TM/setupclass.py @@ -212,7 +212,7 @@ class Setup: if not self.chunkCacheDir: # (self.directory is already absolute) - self.chunkCacheDir = os.path.join(self.directory, 'chunks' % self.chunk_len) + self.chunkCacheDir = os.path.join(self.directory, 'chunks') else: dirname = os.path.basename(self.directory).replace('results', self.region) self.chunkCacheDir = os.path.join(self.chunkCacheDir, -- GitLab