From 81e34875b94170631b34a9fbf002d4fea1c3a977 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 9 Oct 2024 16:59:12 +0200 Subject: [PATCH] [update] small changes increasing code robustness --- PyLoT.py | 6 +++++- pylot/core/util/dataprocessing.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) mode change 100644 => 100755 PyLoT.py diff --git a/PyLoT.py b/PyLoT.py old mode 100644 new mode 100755 index dc465395..ef666719 --- a/PyLoT.py +++ b/PyLoT.py @@ -3590,7 +3590,7 @@ class MainWindow(QMainWindow): def calc_magnitude(self): self.init_metadata() if not self.metadata: - return None + return [] wf_copy = self.get_data().getWFData().copy() @@ -3599,6 +3599,10 @@ class MainWindow(QMainWindow): for station in np.unique(list(self.getPicks('manual').keys()) + list(self.getPicks('auto').keys())): wf_select += wf_copy.select(station=station) + if not wf_select: + logging.warning('Empty Stream in calc_magnitude. Return.') + return [] + corr_wf = restitute_data(wf_select, self.metadata) # calculate moment magnitude moment_mag = MomentMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('vp'), diff --git a/pylot/core/util/dataprocessing.py b/pylot/core/util/dataprocessing.py index af75bdcf..178f4175 100644 --- a/pylot/core/util/dataprocessing.py +++ b/pylot/core/util/dataprocessing.py @@ -654,6 +654,8 @@ def restitute_data(data, metadata, unit='VEL', force=False, ncores=0): """ # data = remove_underscores(data) + if not data: + return # loop over traces input_tuples = [] @@ -661,9 +663,14 @@ def restitute_data(data, metadata, unit='VEL', force=False, ncores=0): input_tuples.append((tr, metadata, unit, force)) data.remove(tr) - pool = gen_Pool(ncores) - result = pool.imap_unordered(restitute_trace, input_tuples) - pool.close() + if ncores == 0: + result = [] + for input_tuple in input_tuples: + result.append(restitute_trace(input_tuple)) + else: + pool = gen_Pool(ncores) + result = pool.imap_unordered(restitute_trace, input_tuples) + pool.close() for tr, remove_trace in result: if not remove_trace: