对obspy的hdf5写/读支持
obspyh5的Python项目详细描述
保存obspy流并将其写入hdf5文件。 如果stats属性是数字、字符串, utcdatetime对象或numpy数组。 它可以作为obspy的read函数的插件来读取整个hdf5文件。 或者,您可以使用iterh5在hdf5文件中迭代跟踪。 功能。
安装
安装h5py和obspy。之后,使用pip by安装obspyh5:
pip install obspyh5
或者,您也可以通过下载源代码和 跑步:
python setup.py install
使用conda,您可以使用以下命令安装到自由环境中:
conda config --add channels conda-forge conda create -n obsh5 numpy obspy h5py conda activate obsh5 conda install obspyh5
用法
使用obspy插件的基本示例:
>>> from obspy import read >>> stream = read() # load example stream >>> print(stream) ..3 Trace(s) in Stream: BW.RJOB..EHZ | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples BW.RJOB..EHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples BW.RJOB..EHE | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples >>> stream.write('test.h5', 'H5') # declare 'H5' as format >>> print(read('test.h5')) # Order is not preserved! 3 Trace(s) in Stream: BW.RJOB..EHZ | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples BW.RJOB..EHE | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples BW.RJOB..EHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples
在一个巨大的hdf5文件中遍历跟踪的示例。每次迭代后 trace不保存在内存中,因此可以处理一个巨大的hdf5 在电脑上存档没有问题。
>>> from obspyh5 import iterh5 >>> for trace in iterh5('huge_in.h5') trace.do_something() trace.write('huge_out.h5', 'H5', mode='a') # append mode to write into file
< H2>替代索引< /H2>
OBSPYH5支持交替索引。
>>> from obspy import read >>> import obspyh5 >>> print(obspyh5._INDEX) # default index waveforms/{network}.{station}/{location}.{channel}/{starttime.datetime:%Y-%m-%dT%H:%M:%S}_{endtime.datetime:%Y-%m-%dT%H:%M:%S}
在写入跟踪时,该索引由stats对象填充,例如
>>> stats = read()[0].stats >>> print(obspyh5._INDEX.format(**stats)) 'waveforms/BW.RJOB/.EHZ/2009-08-24T00:20:03_2009-08-24T00:20:32'
要更改索引,请使用set_index。
>>> obspyh5.set_index('xcorr') # xcorr indexing >>> obspyh5.set_index('waveforms/{network}.{station}/{distance}') # custom indexing
当使用“XCORR”标引统计信息时需要条目“NETWork1”、“Stand 1”, “位置1”、“通道1”、“网络2”、“站点2”、“位置2”和“通道2” 第一站和第二站。例如:
>>> from obspy import read >>> import obspyh5 >>> obspyh5.set_index('xcorr') # activate xcorr indexing >>> stream = read() >>> for i, tr in enumerate(stream): # manipulate stats object station1, station2 = 'ST1', 'ST%d' % i channel1, channel2 = 'HHZ', 'HHN' s = tr.stats # we manipulate seed id so that important information gets # printed by obspy s.network, s.station = s.station1, s.channel1 = station1, channel1 s.location, s.channel = s.station2, s.channel2 = station2, channel2 s.network1 = s.network2 = 'BW' s.location1 = s.location2 = '' >>> print(stream) ST1.HHZ.ST0.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples ST1.HHZ.ST1.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples ST1.HHZ.ST2.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples >>> stream.write('test_xcorr.h5', 'H5') >>> print(read('test_xcorr.h5')) ST1.HHZ.ST0.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples ST1.HHZ.ST1.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples ST1.HHZ.ST2.HHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples