diff --git a/mtuq/graphics/uq/omega.py b/mtuq/graphics/uq/omega.py index 90629d41..2024d52f 100644 --- a/mtuq/graphics/uq/omega.py +++ b/mtuq/graphics/uq/omega.py @@ -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 diff --git a/mtuq/graphics/waveforms.py b/mtuq/graphics/waveforms.py index 2b5a9ee9..8a768f11 100644 --- a/mtuq/graphics/waveforms.py +++ b/mtuq/graphics/waveforms.py @@ -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) @@ -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 @@ -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={}, ): @@ -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 @@ -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 @@ -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 @@ -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 [ @@ -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) @@ -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? @@ -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): diff --git a/mtuq/grid_search.py b/mtuq/grid_search.py index e9e08658..c1be2a27 100644 --- a/mtuq/grid_search.py +++ b/mtuq/grid_search.py @@ -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 @@ -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 diff --git a/mtuq/misfit/polarity.py b/mtuq/misfit/polarity.py index 5b3d7830..9d17eb93 100644 --- a/mtuq/misfit/polarity.py +++ b/mtuq/misfit/polarity.py @@ -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) diff --git a/mtuq/misfit/waveform/__init__.py b/mtuq/misfit/waveform/__init__.py index 62d0063d..eeb50c0f 100644 --- a/mtuq/misfit/waveform/__init__.py +++ b/mtuq/misfit/waveform/__init__.py @@ -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:: @@ -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': @@ -344,7 +344,7 @@ def description(self): elif self.norm=='hybrid': NF = 'Σ √(∫ |d(t)|² dt)' - _description += \ + _string += \ f"""\ Misfit function evaluates {formula} @@ -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__ @@ -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