From a922e7013019d21cf3cf967d41abc7f77217e721 Mon Sep 17 00:00:00 2001 From: Rakib Hassan Date: Tue, 5 Nov 2024 13:31:10 +0800 Subject: [PATCH] Adding Support for Windows Executables * Added support for parallel processing through a .exe file on windows * Swapped out joblib/multiprocessing for 'multiprocess' module in Pathos package --- seismic/ASDFdatabase/utils.py | 2 +- seismic/ASDFdatabase/waveform_analytics.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/seismic/ASDFdatabase/utils.py b/seismic/ASDFdatabase/utils.py index 69dbec70..245f898e 100644 --- a/seismic/ASDFdatabase/utils.py +++ b/seismic/ASDFdatabase/utils.py @@ -221,7 +221,7 @@ def __init__(self, mseed_folder, pattern): # if (i > 0): break # end for - print('\nCreating metadata index for {} mseed files..'.format(len(self.meta_list))) + print('\nCreating metadata index for a total of {} traces found..'.format(len(self.meta_list))) for row in tqdm(self.meta_list): idx, nc, sc, lc, cc, st, et = row diff --git a/seismic/ASDFdatabase/waveform_analytics.py b/seismic/ASDFdatabase/waveform_analytics.py index 95c86316..82bb2b31 100644 --- a/seismic/ASDFdatabase/waveform_analytics.py +++ b/seismic/ASDFdatabase/waveform_analytics.py @@ -22,6 +22,7 @@ import matplotlib from collections import defaultdict from obspy.core.inventory.response import Response +import matplotlib from matplotlib import mlab from obspy.signal.invsim import cosine_taper from obspy.signal.spectral_estimation import get_nlnm, get_nhnm @@ -33,11 +34,14 @@ from seismic.inventory.response import ResponseFactory from tqdm import tqdm from matplotlib.colors import LinearSegmentedColormap -from multiprocessing import Manager from matplotlib.backends.backend_pdf import PdfPages -from joblib import Parallel, delayed import psutil +from pathos.multiprocessing import ProcessingPool as Pool +from multiprocess import Manager, freeze_support + +matplotlib.use('TKAgg') + is_windows = sys.platform.startswith('win') class ProgressTracker(object): @@ -165,11 +169,9 @@ def __init__(self, # launch parallel computations if (1): - Parallel(n_jobs=self.nproc) \ - (delayed(self._generate_psds)(cst_list, cet_list) \ - for cst_list, cet_list in zip(proc_st_list, proc_et_list)) + p = Pool(ncpus=self.nproc) + p.map(self._generate_psds, proc_st_list, proc_et_list) # end if - # end func def _setup_period_bins(self): @@ -225,7 +227,6 @@ def fft_taper(data): """ data *= cosine_taper(len(data), 0.2) return data - # end func for start_time, end_time in zip(start_time_list, end_time_list): @@ -801,5 +802,8 @@ def get_time_range_func(net, sta, loc, cha): groups.add_command(process_asdf) if __name__ == "__main__": + # add support for process-based multiprocessing for a Windows .exe + if(is_windows): freeze_support() + groups() # end func