Skip to content

Commit

Permalink
Updated data containers
Browse files Browse the repository at this point in the history
  • Loading branch information
rmodrak committed Feb 2, 2024
1 parent 40cd6ea commit 7e65ed3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
19 changes: 18 additions & 1 deletion mtuq/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -270,7 +287,7 @@ def __copy__(self):


def copy(self):
return __copy__(self)
return self.__copy__()


def write(self, path, format='sac'):
Expand Down
23 changes: 13 additions & 10 deletions mtuq/greens_tensor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -487,7 +490,7 @@ def __copy__(self):


def copy(self):
return __copy__(self)
return self.__copy__()


def write(self, filename):
Expand Down

0 comments on commit 7e65ed3

Please sign in to comment.