Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPSD: fix period_lim with xaxis_frequency=True #2246

Merged
merged 3 commits into from
Mar 15, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ master:
(see #2045)
* Fixed the check for new PSD slices whether they should be added or whether
they would add unwanted duplicated data (see #2229)
* Fix `period_lim` option when `xaxis_frequency=True` (see #2246)
- obspy.signal.cross_correlation:
* Add new `correlate_template()` function with 'full' normalization option,
required for correlations in template-matching
Expand Down
Binary file modified obspy/imaging/tests/images/ppsd_freq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions obspy/imaging/tests/test_ppsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import matplotlib.pyplot as plt
import numpy as np

from obspy.core.util.testing import ImageComparison
from obspy.core.util.testing import ImageComparison, MATPLOTLIB_VERSION
from obspy.signal.tests.test_spectral_estimation import _get_ppsd


Expand Down Expand Up @@ -47,9 +47,15 @@ def test_ppsd_plot_frequency(self):
"""
Test plot of ppsd example data, normal (non-cumulative) style.
"""
# mpl < 2.2 has slightly offset ticks/ticklabels, so needs a higher
# tolerance (see e.g. http://tests.obspy.org/102260)
reltol = 2
if MATPLOTLIB_VERSION < [2, 2]:
reltol = 4
# Catch underflow warnings due to plotting on log-scale.
with np.errstate(all='ignore'):
with ImageComparison(self.path, 'ppsd_freq.png', reltol=2.0) as ic:
with ImageComparison(self.path, 'ppsd_freq.png',
reltol=reltol) as ic:
self.ppsd.plot(
show=False, show_coverage=False, show_histogram=True,
show_percentiles=True, percentiles=[20, 40],
Expand Down
4 changes: 1 addition & 3 deletions obspy/signal/spectral_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,13 +1841,11 @@ def plot(self, filename=None, show_coverage=True, show_histogram=True,

ax.semilogx()
if xaxis_frequency:
xlim = map(lambda x: 1.0 / x, period_lim)
ax.set_xlabel('Frequency [Hz]')
ax.invert_xaxis()
else:
xlim = period_lim
ax.set_xlabel('Period [s]')
ax.set_xlim(sorted(xlim))
ax.set_xlim(period_lim)
ax.set_ylim(self.db_bin_edges[0], self.db_bin_edges[-1])
if self.special_handling is None:
ax.set_ylabel('Amplitude [$m^2/s^4/Hz$] [dB]')
Expand Down
Binary file modified obspy/signal/tests/images/ppsd_restricted_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions obspy/signal/tests/test_spectral_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,16 @@ def callback(t_array):
np.testing.assert_array_equal(selection_got, expected_selection)

# test one particular selection as an image test
# mpl < 2.2 has slightly offset ticks/ticklabels, so needs a higher
# tolerance (see e.g. http://tests.obspy.org/102260)
reltol = 1.5
if MATPLOTLIB_VERSION < [2, 2]:
reltol = 5
plot_kwargs = dict(max_percentage=15, xaxis_frequency=True,
period_lim=(0.01, 50))
ppsd.calculate_histogram(**stack_criteria_list[1])
with ImageComparison(self.path_images,
'ppsd_restricted_stack.png', reltol=1.5) as ic:
'ppsd_restricted_stack.png', reltol=reltol) as ic:
fig = ppsd.plot(show=False, **plot_kwargs)
# some matplotlib/Python version combinations lack the left-most
# tick/label "Jan 2015". Try to circumvent and get the (otherwise
Expand All @@ -491,7 +496,7 @@ def callback(t_array):
# matches (like above):
ppsd.calculate_histogram(**stack_criteria_list[1])
with ImageComparison(self.path_images,
'ppsd_restricted_stack.png', reltol=1.5,
'ppsd_restricted_stack.png', reltol=reltol,
plt_close_all_exit=False) as ic:
fig = ppsd.plot(show=False, **plot_kwargs)
# some matplotlib/Python version combinations lack the left-most
Expand Down Expand Up @@ -527,7 +532,7 @@ def callback(t_array):
# image test should pass agin:
ppsd.calculate_histogram(**stack_criteria_list[1])
with ImageComparison(self.path_images,
'ppsd_restricted_stack.png', reltol=1.5,
'ppsd_restricted_stack.png', reltol=reltol,
plt_close_all_enter=False) as ic:
ppsd._plot_histogram(fig=fig, draw=True)
with np.errstate(under='ignore'):
Expand Down