Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mtuq/graphics/uq/omega.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def plot_pdf(filename, df, var, m0=None, nbins=50, normalized=False, **kwargs):



def plot_cdf(filename, df, var, nbins=50, normalized=False, **kwargs):
def plot_cdf(filename, df, var, m0=None, nbins=50, normalized=False, **kwargs):
""" Plots cumulative distribution function over angular distance

.. rubric :: Input arguments
Expand Down
57 changes: 43 additions & 14 deletions mtuq/graphics/waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def plot_waveforms1(
normalize='maximum_amplitude',
trace_label_writer=trace_label_writer,
station_label_writer=station_label_writer,
dat_kwargs={},
syn_kwargs={},
):

""" Creates data/synthetics comparison figure with 3 columns (Z, R, T)
Expand Down Expand Up @@ -80,7 +82,8 @@ def plot_waveforms1(
# plot traces
_plot_stream(axes[ir], [1,2,3], ['Z','R','T'],
data[_i], synthetics[_i],
normalize, factor, trace_label_writer, total_misfit)
normalize, factor, trace_label_writer, total_misfit,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

ir += 1

Expand All @@ -103,6 +106,8 @@ def plot_waveforms2(
normalize='maximum_amplitude',
trace_label_writer=trace_label_writer,
station_label_writer=station_label_writer,
dat_kwargs={},
syn_kwargs={},
):


Expand Down Expand Up @@ -161,12 +166,14 @@ def plot_waveforms2(
# plot body wave traces
_plot_stream(axes[ir], [1,2], ['Z','R'],
data_bw[_i], synthetics_bw[_i],
normalize, factor_bw, trace_label_writer, total_misfit_bw)
normalize, factor_bw, trace_label_writer, total_misfit_bw,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

# plot surface wave traces
_plot_stream(axes[ir], [3,4,5], ['Z','R','T'],
data_sw[_i], synthetics_sw[_i],
normalize, factor_sw, trace_label_writer, total_misfit_sw)
normalize, factor_sw, trace_label_writer, total_misfit_sw,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

ir += 1

Expand All @@ -191,6 +198,8 @@ def plot_waveforms3(
normalize='maximum_amplitude',
trace_label_writer=trace_label_writer,
station_label_writer=station_label_writer,
dat_kwargs={},
syn_kwargs={},
):

""" Creates data/synthetics comparison figure with 5 columns
Expand Down Expand Up @@ -261,17 +270,20 @@ def plot_waveforms3(
# plot body waves
_plot_stream(axes[ir], [1,2], ['Z','R'],
data_bw[_i], synthetics_bw[_i],
normalize, factor_bw, trace_label_writer, total_misfit_bw)
normalize, factor_bw, trace_label_writer, total_misfit_bw,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

# plot Rayleigh waves
_plot_stream(axes[ir], [3,4], ['Z','R'],
data_rayl[_i], synthetics_rayl[_i],
normalize, factor_rayl, trace_label_writer, total_misfit_rayl)
normalize, factor_rayl, trace_label_writer, total_misfit_rayl,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

# plot Love waves
_plot_stream(axes[ir], [5], ['T'],
data_love[_i], synthetics_love[_i],
normalize, factor_love, trace_label_writer, total_misfit_love)
normalize, factor_love, trace_label_writer, total_misfit_love,
dat_kwargs=dat_kwargs, syn_kwargs=syn_kwargs)

ir += 1

Expand Down Expand Up @@ -534,7 +546,9 @@ def _plot_stream(
normalize='maximum_amplitude',
amplitude_factor=None,
trace_label_writer=None,
total_misfit=1.
total_misfit=1.,
dat_kwargs={},
syn_kwargs={},
):

if normalize in [
Expand Down Expand Up @@ -580,7 +594,7 @@ def _plot_stream(
elif amplitude_factor:
ylim = [-amplitude_factor, +amplitude_factor]

_plot_trace(axis, dat, syn)
_plot_trace(axis, dat, syn, dat_update=dat_kwargs, syn_update=syn_kwargs)

try:
axis.set_ylim(*ylim)
Expand All @@ -593,18 +607,35 @@ def _plot_stream(
pass


def _plot_trace(axis, dat, syn, label=None):
def _plot_trace(axis, dat, syn, dat_update={}, syn_update={}):
""" Plots data and synthetics time series on current axes
"""
if dat is None and syn is None:
# nothing to plot
return

dat_kwargs = {
'color': 'black',
'linewidth': 1.5,
'clip_on': True,
'zorder': 10,
}

syn_kwargs = {
'color': 'red',
'linewidth': 1.25,
'clip_on': True,
'zorder': 10,
}

dat_kwargs.update(dat_update)
syn_kwargs.update(syn_update)


if dat:
t,d = _time_series(dat)

axis.plot(t, d, 'k', linewidth=1.5,
clip_on=True, zorder=10)
axis.plot(t, d, **dat_kwargs)

if syn:
# which start and stop indices will correctly align synthetics?
Expand All @@ -613,9 +644,7 @@ def _plot_trace(axis, dat, syn, label=None):

t,s = _time_series(syn)

axis.plot(t[:stop-start], s[start:stop], 'r', linewidth=1.25,
clip_on=True, zorder=10)

axis.plot(t[:stop-start], s[start:stop], **syn_kwargs)


def _add_component_labels1(axes, body_wave_labels=True, surface_wave_labels=True):
Expand Down
4 changes: 2 additions & 2 deletions mtuq/grid_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def grid_search(data, greens, misfit, origins, sources,
# print debugging information
if verbose>0 and _is_mpi_env() and iproc==0:
try:
print(misfit.description())
print(misfit._description())
except:
pass

Expand All @@ -111,7 +111,7 @@ def grid_search(data, greens, misfit, origins, sources,

elif verbose>0 and not _is_mpi_env():
try:
print(misfit.description())
print(misfit._description())
except:
pass

Expand Down
8 changes: 4 additions & 4 deletions mtuq/misfit/polarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def collect_attributes(self, data, greens):
return attrs_list


def description(self):
_description = '\n'.join([
def _description(self):
lines = [
f' Misfit function type:\n {type(self).__name__}\n',
f' Misfit function method:\n {self.method}\n',
])
return _description
]
return '\n'.join(lines)



Expand Down
18 changes: 9 additions & 9 deletions mtuq/misfit/waveform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WaveformMisfit(object):
Evaluating misfit is a two-step procedure.

First, the user supplies parameters such as the type of norm (see below for
detailed argument descriptions):
detailed argument description):

.. code::

Expand Down Expand Up @@ -319,8 +319,8 @@ def collect_synthetics(self, data, greens, source, normalize=False, mode=2):
return deepcopy(synthetics)


def description(self):
_description = ''
def _description(self):
_string = ''

if self.verbose > 1:
if self.norm=='L1':
Expand All @@ -344,7 +344,7 @@ def description(self):
elif self.norm=='hybrid':
NF = 'Σ √(∫ |d(t)|² dt)'

_description += \
_string += \
f"""\
Misfit function evaluates
{formula}
Expand All @@ -358,14 +358,14 @@ def description(self):
"""

if self.time_shift_min != self.time_shift_max:
_description +=\
_string +=\
f' t_s is a cross-correlation time shift\n'

if self.normalize:
_description +=\
_string +=\
f' NF = {NF} is a normalization factor\n'

_description += '\n'
_string += '\n'


_type = type(self).__name__
Expand All @@ -376,12 +376,12 @@ def description(self):
3: 'Cython [deprecated]',
}[self.level]

_description += '\n'.join([
_string += '\n'.join([
f' Misfit function type:\n {_type}\n',
f' Misfit function implementation:\n {_level}\n',
])

return _description
return _string



Expand Down