本文整理汇总了Python中obspy.signal.spectral_estimation.PPSD.plot方法的典型用法代码示例。如果您正苦于以下问题:Python PPSD.plot方法的具体用法?Python PPSD.plot怎么用?Python PPSD.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.signal.spectral_estimation.PPSD
的用法示例。
在下文中一共展示了PPSD.plot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ppsd_restricted_stacks
# 需要导入模块: from obspy.signal.spectral_estimation import PPSD [as 别名]
# 或者: from obspy.signal.spectral_estimation.PPSD import plot [as 别名]
def test_ppsd_restricted_stacks(self):
"""
Test PPSD.calculate_histogram() with restrictions to what data should
be stacked. Also includes image tests.
"""
# set up a bogus PPSD, with fixed random psds but with real start times
# of psd pieces, to facilitate testing the stack selection.
ppsd = PPSD(stats=Stats(dict(sampling_rate=150)), metadata=None,
db_bins=(-200, -50, 20.), period_step_octaves=1.4)
ppsd._times_processed = np.load(
os.path.join(self.path, "ppsd_times_processed.npy")).tolist()
np.random.seed(1234)
ppsd._binned_psds = [
arr for arr in np.random.uniform(
-200, -50,
(len(ppsd._times_processed), len(ppsd.period_bin_centers)))]
# Test callback function that selects a fixed random set of the
# timestamps. Also checks that we get passed the type we expect,
# which is 1D numpy ndarray of float type.
def callback(t_array):
self.assertIsInstance(t_array, np.ndarray)
self.assertEqual(t_array.shape, (len(ppsd._times_processed),))
self.assertEqual(t_array.dtype, np.float64)
np.random.seed(1234)
res = np.random.randint(0, 2, len(t_array)).astype(np.bool)
return res
# test several different sets of stack criteria, should cover
# everything, even with lots of combined criteria
stack_criteria_list = [
dict(starttime=UTCDateTime(2015, 3, 8), month=[2, 3, 5, 7, 8]),
dict(endtime=UTCDateTime(2015, 6, 7), year=[2015],
time_of_weekday=[(1, 0, 24), (2, 0, 24), (-1, 0, 11)]),
dict(year=[2013, 2014, 2016, 2017], month=[2, 3, 4]),
dict(month=[1, 2, 5, 6, 8], year=2015),
dict(isoweek=[4, 5, 6, 13, 22, 23, 24, 44, 45]),
dict(time_of_weekday=[(5, 22, 24), (6, 0, 2), (6, 22, 24)]),
dict(callback=callback, month=[1, 3, 5, 7]),
dict(callback=callback)]
expected_selections = np.load(
os.path.join(self.path, "ppsd_stack_selections.npy"))
# test every set of criteria
for stack_criteria, expected_selection in zip(
stack_criteria_list, expected_selections):
selection_got = ppsd._stack_selection(**stack_criteria)
np.testing.assert_array_equal(selection_got, expected_selection)
# test one particular selection as an image test
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:
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
# OK) test by changing the left x limit a bit further out (by two
# days, axis is in mpl days). See e.g.
# https://tests.obspy.org/30657/#1
fig.axes[1].set_xlim(left=fig.axes[1].get_xlim()[0] - 2)
with np.errstate(under='ignore'):
fig.savefig(ic.name)
# test it again, checking that updating an existing plot with different
# stack selection works..
# a) we start with the stack for the expected image and test that it
# matches (like above):
ppsd.calculate_histogram(**stack_criteria_list[1])
with ImageComparison(self.path_images,
'ppsd_restricted_stack.png', reltol=1.5,
plt_close_all_exit=False) 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
# OK) test by changing the left x limit a bit further out (by two
# days, axis is in mpl days). See e.g.
# https://tests.obspy.org/30657/#1
fig.axes[1].set_xlim(left=fig.axes[1].get_xlim()[0] - 2)
with np.errstate(under='ignore'):
fig.savefig(ic.name)
# b) now reuse figure and set the histogram with a different stack,
# image test should fail:
ppsd.calculate_histogram(**stack_criteria_list[3])
try:
with ImageComparison(self.path_images,
'ppsd_restricted_stack.png',
adjust_tolerance=False,
plt_close_all_enter=False,
plt_close_all_exit=False) as ic:
# rms of the valid comparison above is ~31,
# rms of the invalid comparison we test here is ~36
if MATPLOTLIB_VERSION == [1, 1, 1]:
ic.tol = 33
ppsd._plot_histogram(fig=fig, draw=True)
with np.errstate(under='ignore'):
fig.savefig(ic.name)
except ImageComparisonException:
pass
#.........这里部分代码省略.........