From 41bca624dd835682633e5224cf99b1502fce97cd Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Tue, 14 Apr 2026 10:44:11 +1200 Subject: [PATCH] Set default threading state for Client downloads --- geonet_obspy_utils/clients/aws/client.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/geonet_obspy_utils/clients/aws/client.py b/geonet_obspy_utils/clients/aws/client.py index 431a93f..c1c4ddf 100644 --- a/geonet_obspy_utils/clients/aws/client.py +++ b/geonet_obspy_utils/clients/aws/client.py @@ -30,7 +30,7 @@ class Client(object): (only for GeoNet) data. """ - def __init__(self, client_name="GEONET"): + def __init__(self, client_name="GEONET", max_threads=1): """ Initialize the client with the configuration loaded from a YAML file. @@ -44,6 +44,9 @@ def __init__(self, client_name="GEONET"): :type client_name: str :param client_name: Name of the client to initialize. Must match a key in the YAML config file. + :type max_threads: int + :param max_threads: Number of threads to use for downloads. Can be + overloaded later in individual argument calls. """ @@ -64,6 +67,7 @@ def __init__(self, client_name="GEONET"): self.waveform_dir = self.config["waveform_dir"] self.year_day_format = self.config["year_day_format"] self.mseed_file_format = self.config["mseed_file_format"] + self.max_threads = max_threads @property def _s3(self): @@ -116,7 +120,7 @@ def _list_available_files(self, prefix): return file_list def get_waveforms(self, network, station, location, channel, starttime, - endtime, filename=None, max_threads=1): + endtime, filename=None, max_threads=None): """ Fetch MiniSEED waveform data from AWS S3 bucket. @@ -165,7 +169,10 @@ def get_waveforms(self, network, station, location, channel, starttime, instead of being parsed to an ObsPy object. Thus it will contain the raw data from the webservices. """ - + # If max_threads is not set at calltime, then default to the + # objects default threading state. + max_threads = max_threads or self.max_threads + if (not isinstance(starttime, UTCDateTime) or not isinstance(endtime, UTCDateTime)): raise ValueError("starttime and endtime must be" + @@ -267,7 +274,7 @@ def get_events(self, starttime=None, endtime=None, minlatitude=None, maxlatitude=None, minlongitude=None, maxlongitude=None, mindepth=None, maxdepth=None, minmagnitude=None, maxmagnitude=None, eventid=None, filename=None, - max_threads=1, **kwargs): + max_threads=None, **kwargs): """ Get event information from GeoNet AWS S3 bucket. @@ -323,6 +330,10 @@ def get_events(self, starttime=None, endtime=None, minlatitude=None, instead of being parsed to an ObsPy object. Thus it will contain the raw data from the webservices. """ + # If max_threads is not set at calltime, then default to the + # objects default threading state. + max_threads = max_threads or self.max_threads + if eventid: try: bin_obj = self._s3_event.Object(eventid+".xml") \