diff --git a/mtuq/dataset.py b/mtuq/dataset.py index 7c7c775ed..c2c1a2b88 100644 --- a/mtuq/dataset.py +++ b/mtuq/dataset.py @@ -207,6 +207,23 @@ def get_stations(self): return stations + def get_stats(self): + """ Returns trace metadata in nested lists + + .. note :: + + For Datasets created using ``mtuq.io.readers``, SAC header metadata + is used to populate the Station attributes + + """ + stats = [] + for stream in self: + stats += [[]] + for trace in stream: + stats[-1] += [trace.stats] + return stats + + def get_origins(self): """ Returns origin metadata from all streams as a `list` of `mtuq.event.Origin` objects @@ -270,7 +287,7 @@ def __copy__(self): def copy(self): - return __copy__(self) + return self.__copy__() def write(self, path, format='sac'): diff --git a/mtuq/greens_tensor/base.py b/mtuq/greens_tensor/base.py index ac56d1d1f..4c933b878 100644 --- a/mtuq/greens_tensor/base.py +++ b/mtuq/greens_tensor/base.py @@ -142,24 +142,27 @@ def _get_shape(self): return nc, nr, nt - def _allocate_stream(self): + def _allocate_stream(self, stats=None): """ Allocates ObsPy stream used by `get_synthetics` """ nc, nr, nt = self._get_shape() + if not stats: + stats = [] + for component in self.components: + stats += [self[0].stats.copy()] + stats[-1].update({'npts': nt, 'channel': component}) + stream = Stream() - for component in self.components: - # add stats object - stats = self.station.copy() - stats.update({'npts': nt, 'channel': component}) + for _i, component in enumerate(self.components): # add trace object - stream += Trace(np.zeros(nt), stats) + stream += Trace(np.zeros(nt), stats[_i]) return stream - def get_synthetics(self, source, components=None, inplace=False): + def get_synthetics(self, source, components=None, stats=None, inplace=False): """ Generates synthetics through a linear combination of time series Returns an ObsPy stream @@ -190,7 +193,7 @@ def get_synthetics(self, source, components=None, inplace=False): if inplace: synthetics = self._synthetics else: - synthetics = self._allocate_stream() + synthetics = self._allocate_stream(stats) for _i, component in enumerate(self.components): # Even with careful attention to index order, np.dot is very slow. @@ -284,7 +287,7 @@ def select(self, selector): return selected - def get_synthetics(self, source, components=None, mode='apply', **kwargs): + def get_synthetics(self, source, components=None, stats=None, mode='apply', **kwargs): """ Generates synthetics through a linear combination of time series Returns an MTUQ `Dataset` @@ -487,7 +490,7 @@ def __copy__(self): def copy(self): - return __copy__(self) + return self.__copy__() def write(self, filename):