From 89948910e6a966cd0853e4f34d54268cb895f5e8 Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Fri, 17 May 2024 15:51:33 -0600 Subject: [PATCH 1/7] Updated docs --- docs/install/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/install/index.rst b/docs/install/index.rst index 324d206ce..8dd0863cc 100644 --- a/docs/install/index.rst +++ b/docs/install/index.rst @@ -32,7 +32,7 @@ Unpack seismic waveforms used by examples: .. code:: bash ./data/examples/unpack.bash - bash ./data/tests/unpack.bash + bash ./data/tests/download.bash Finally, install PyGMT: From cf18cf617490486d5da2d14a34236df2f5492001 Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Fri, 17 May 2024 15:51:53 -0600 Subject: [PATCH 2/7] Even more prominent CPS warning --- mtuq/io/clients/CPS_SAC.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mtuq/io/clients/CPS_SAC.py b/mtuq/io/clients/CPS_SAC.py index c03671f7b..d54f9e4da 100644 --- a/mtuq/io/clients/CPS_SAC.py +++ b/mtuq/io/clients/CPS_SAC.py @@ -22,8 +22,8 @@ ] -# disply prominent warning -print('CPS client still under testing') +# display prominent warning +print('WARNING: CPS client still under testing...\n') class Client(ClientBase): From 76688989e1f33357de2cd16a01a3117dba04c3c9 Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Thu, 14 Nov 2024 15:27:25 -0700 Subject: [PATCH 3/7] By default, station metadata now gets passed to get_synthetics() --- mtuq/greens_tensor/base.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mtuq/greens_tensor/base.py b/mtuq/greens_tensor/base.py index baace937d..4e3cdb2cf 100644 --- a/mtuq/greens_tensor/base.py +++ b/mtuq/greens_tensor/base.py @@ -148,10 +148,10 @@ def _allocate_stream(self, stats=None): """ nc, nr, nt = self._get_shape() - if not stats: - stats = [] + if stats is None: + stats = list() for component in self.components: - stats += [self[0].stats.copy()] + stats.append(deepcopy(self.station)) stats[-1].update({'npts': nt, 'channel': component}) stream = Stream() @@ -291,7 +291,7 @@ def select(self, selector): return selected - def get_synthetics(self, source, components=None, stats=None, mode='apply', **kwargs): + def get_synthetics(self, source, components=['Z','R','T'], stats=None, mode='apply', **kwargs): """ Generates synthetics through a linear combination of time series Returns an MTUQ `Dataset` @@ -307,6 +307,7 @@ def get_synthetics(self, source, components=None, stats=None, mode='apply', **kw ``stats`` (`obspy.Trace.Stats` object): ObsPy Stats object that will be attached to the synthetics + (Defaults to `GreensTesnor` `station` attributes.) """ if mode=='map': @@ -322,6 +323,12 @@ def get_synthetics(self, source, components=None, stats=None, mode='apply', **kw return synthetics elif mode=='apply': + if stats is not None: + print("get_synthetics() stats keyword argument can only be " + "used with mode='apply'") + + warnings.warn("Ignoring stats keyword argument.") + synthetics = Dataset() for tensor in self: synthetics.append(tensor.get_synthetics( From ba68bfac7f046bb195624fbc2629c4e8296f285b Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Thu, 14 Nov 2024 15:28:02 -0700 Subject: [PATCH 4/7] Tweaked SAC reader --- mtuq/io/readers/SAC.py | 58 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/mtuq/io/readers/SAC.py b/mtuq/io/readers/SAC.py index 350c13cad..269b57ff5 100644 --- a/mtuq/io/readers/SAC.py +++ b/mtuq/io/readers/SAC.py @@ -68,8 +68,11 @@ def read(filenames, station_id_list=None, event_id=None, tags=[]): for station_id in data_sorted: streams += [data_sorted[station_id]] - # check for duplicate components for stream in streams: + # check for duplicate components + check_components(stream) + + # check for that all traces have same time sampling check_components(stream) # collect event metadata @@ -81,7 +84,7 @@ def read(filenames, station_id_list=None, event_id=None, tags=[]): # collect station metadata for stream in streams: - stream.station = _get_station(stream, preliminary_origin) + stream.station = _get_station(stream) # create MTUQ Dataset return Dataset(streams, id=event_id, tags=tags) @@ -133,7 +136,7 @@ def _get_origin(stream, event_id): }) -def _get_station(stream, origin, attach_sac_headers=True): +def _get_station(stream, attach_sac_headers=False): """ Extracts station metadata from SAC headers """ # @@ -182,6 +185,55 @@ def _get_station(stream, origin, attach_sac_headers=True): return station +def _get_station(stream): + """ Extracts station metadata from SAC headers + """ + stats = stream[0].stats + sac_headers = stream[0].stats.sac + + # + # populate station object + # + station = Station() + + station.update({ + 'network': stream[0].stats.network, + 'station': stream[0].stats.station, + 'location': stream[0].stats.location, + 'sampling_rate': stream[0].stats.sampling_rate, + 'npts': stream[0].stats.npts, + 'delta': stream[0].stats.delta, + 'starttime': stream[0].stats.starttime, + 'endtime': stream[0].stats.endtime, + }) + + station.update({ + 'id': '.'.join([ + stream[0].stats.network, + stream[0].stats.station, + stream[0].stats.location])}) + + try: + station_latitude = sac_headers.stla + station_longitude = sac_headers.stlo + station.update({ + 'latitude': station_latitude, + 'longitude': station_longitude}) + except: + raise Exception( + "Could not determine station location from SAC headers.") + + try: + station.update({ + 'station_elevation_in_m': sac_headers.stel, + 'station_depth_in_m': sac_headers.stdp}) + except: + pass + + return station + + + def _glob(filenames): # glob any wildcards _list = list() From c6ae335ab5f3a01b2ccc1e53ac95081e9e31c89a Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Thu, 14 Nov 2024 15:30:28 -0700 Subject: [PATCH 5/7] Removed CPS warning --- mtuq/io/clients/CPS_SAC.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mtuq/io/clients/CPS_SAC.py b/mtuq/io/clients/CPS_SAC.py index d54f9e4da..130b33b33 100644 --- a/mtuq/io/clients/CPS_SAC.py +++ b/mtuq/io/clients/CPS_SAC.py @@ -22,10 +22,6 @@ ] -# display prominent warning -print('WARNING: CPS client still under testing...\n') - - class Client(ClientBase): """ CPS database client From b65e6fd0a75d9e602abc312a8db7fb5068356553 Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Thu, 14 Nov 2024 15:38:56 -0700 Subject: [PATCH 6/7] Tweaked SAC reader --- mtuq/io/readers/SAC.py | 49 ------------------------------------------ 1 file changed, 49 deletions(-) diff --git a/mtuq/io/readers/SAC.py b/mtuq/io/readers/SAC.py index 269b57ff5..9ae93c7ac 100644 --- a/mtuq/io/readers/SAC.py +++ b/mtuq/io/readers/SAC.py @@ -136,55 +136,6 @@ def _get_origin(stream, event_id): }) -def _get_station(stream, attach_sac_headers=False): - """ Extracts station metadata from SAC headers - """ - # - # extract metadata from ObsPy structures - # - meta = deepcopy(stream[0].meta.__dict__) - - sac_headers = meta.pop('sac') - - # remove channel-specific attributes - for attr in ['channel', 'component']: - if attr in meta: - meta.pop(attr) - - # - # populate station object - # - station = Station(meta) - - station.update({ - 'id': '.'.join([ - stream[0].stats.network, - stream[0].stats.station, - stream[0].stats.location])}) - - try: - station_latitude = sac_headers.stla - station_longitude = sac_headers.stlo - station.update({ - 'latitude': station_latitude, - 'longitude': station_longitude}) - except: - raise Exception( - "Could not determine station location from SAC headers.") - - try: - station.update({ - 'station_elevation_in_m': sac_headers.stel, - 'station_depth_in_m': sac_headers.stdp}) - except: - pass - - if attach_sac_headers: - station.sac = sac_headers - - return station - - def _get_station(stream): """ Extracts station metadata from SAC headers """ From 3b4d9d9485655077f3beacd7eec0cffbdd5901e3 Mon Sep 17 00:00:00 2001 From: Ryan Modrak Date: Thu, 14 Nov 2024 17:13:23 -0700 Subject: [PATCH 7/7] More comments about in-place operations --- mtuq/greens_tensor/base.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mtuq/greens_tensor/base.py b/mtuq/greens_tensor/base.py index 4e3cdb2cf..9208d939a 100644 --- a/mtuq/greens_tensor/base.py +++ b/mtuq/greens_tensor/base.py @@ -24,7 +24,8 @@ class GreensTensor(Stream): `ObsPy documentation `_ for more information. - """ +""" + def __init__(self, traces=None, station=None, @@ -102,13 +103,6 @@ def _set_components(self, components): def _preallocate(self): """ Preallocates structures used by `get_synthetics` - - .. note: - - Every time ``get_synthetics(inplace=True)`` is called, the numeric - trace data get overwritten. Every time ``_set_components`` is - called, the traces get overwritten. The stream itself never gets - overwritten. """ nc, nr, nt = self._get_shape() @@ -307,8 +301,25 @@ def get_synthetics(self, source, components=['Z','R','T'], stats=None, mode='app ``stats`` (`obspy.Trace.Stats` object): ObsPy Stats object that will be attached to the synthetics - (Defaults to `GreensTesnor` `station` attributes.) - + (Defaults to `GreensTensor` `station` attributes.) + + + .. note:: + + Different ways of generating synthetics are possible (including in-place + methods suitable for use in mtuq/grid_search.py): + + - When ``get_synthetics(inplace=True)`` is called, the existing + stream and trace objects are reused, and only the numeric trace + data gets overwritten + + - When ``get_synthetics(inplace=False)`` is called, new stream and trace + objects are allocated + + - When ``_set_components()`` is called prior to + ``get_synthetics(inplace=True)``, the existing stream is reused but + new trace objects are allocated + """ if mode=='map': if components is None: