本文整理汇总了Python中obspy.signal.spectral_estimation.PPSD.save方法的典型用法代码示例。如果您正苦于以下问题:Python PPSD.save方法的具体用法?Python PPSD.save怎么用?Python PPSD.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.signal.spectral_estimation.PPSD
的用法示例。
在下文中一共展示了PPSD.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_PPSD
# 需要导入模块: from obspy.signal.spectral_estimation import PPSD [as 别名]
# 或者: from obspy.signal.spectral_estimation.PPSD import save [as 别名]
def test_PPSD(self):
"""
Test PPSD routine with some real data. Data was downsampled to 100Hz
so the ppsd is a bit distorted which does not matter for the purpose
of testing.
"""
# load test file
file_data = os.path.join(
self.path, 'BW.KW1._.EHZ.D.2011.090_downsampled.asc.gz')
file_histogram = os.path.join(
self.path,
'BW.KW1._.EHZ.D.2011.090_downsampled__ppsd_hist_stack.npy')
file_binning = os.path.join(
self.path, 'BW.KW1._.EHZ.D.2011.090_downsampled__ppsd_mixed.npz')
# parameters for the test
data = np.loadtxt(file_data)
stats = {'_format': 'MSEED',
'calib': 1.0,
'channel': 'EHZ',
'delta': 0.01,
'endtime': UTCDateTime(2011, 3, 31, 2, 36, 0, 180000),
'location': '',
'mseed': {'dataquality': 'D', 'record_length': 512,
'encoding': 'STEIM2', 'byteorder': '>'},
'network': 'BW',
'npts': 936001,
'sampling_rate': 100.0,
'starttime': UTCDateTime(2011, 3, 31, 0, 0, 0, 180000),
'station': 'KW1'}
tr = Trace(data, stats)
st = Stream([tr])
paz = {'gain': 60077000.0,
'poles': [(-0.037004 + 0.037016j), (-0.037004 - 0.037016j),
(-251.33 + 0j), (-131.04 - 467.29j),
(-131.04 + 467.29j)],
'sensitivity': 2516778400.0,
'zeros': [0j, 0j]}
ppsd = PPSD(tr.stats, paz)
ppsd.add(st)
# read results and compare
result_hist = np.load(file_histogram)
self.assertEqual(len(ppsd.times), 4)
self.assertEqual(ppsd.nfft, 65536)
self.assertEqual(ppsd.nlap, 49152)
np.testing.assert_array_equal(ppsd.hist_stack, result_hist)
# add the same data a second time (which should do nothing at all) and
# test again - but it will raise UserWarnings, which we omit for now
with warnings.catch_warnings(record=True):
warnings.simplefilter('ignore', UserWarning)
ppsd.add(st)
np.testing.assert_array_equal(ppsd.hist_stack, result_hist)
# test the binning arrays
binning = np.load(file_binning)
np.testing.assert_array_equal(ppsd.spec_bins, binning['spec_bins'])
np.testing.assert_array_equal(ppsd.period_bins, binning['period_bins'])
# test saving and loading of the PPSD (using a temporary file)
with NamedTemporaryFile() as tf:
filename = tf.name
# test saving and loading an uncompressed file
ppsd.save(filename, compress=False)
ppsd_loaded = PPSD.load(filename)
self.assertEqual(len(ppsd_loaded.times), 4)
self.assertEqual(ppsd_loaded.nfft, 65536)
self.assertEqual(ppsd_loaded.nlap, 49152)
np.testing.assert_array_equal(ppsd_loaded.hist_stack, result_hist)
np.testing.assert_array_equal(ppsd_loaded.spec_bins,
binning['spec_bins'])
np.testing.assert_array_equal(ppsd_loaded.period_bins,
binning['period_bins'])
# test saving and loading a compressed file
ppsd.save(filename, compress=True)
ppsd_loaded = PPSD.load(filename)
self.assertEqual(len(ppsd_loaded.times), 4)
self.assertEqual(ppsd_loaded.nfft, 65536)
self.assertEqual(ppsd_loaded.nlap, 49152)
np.testing.assert_array_equal(ppsd_loaded.hist_stack, result_hist)
np.testing.assert_array_equal(ppsd_loaded.spec_bins,
binning['spec_bins'])
np.testing.assert_array_equal(ppsd_loaded.period_bins,
binning['period_bins'])