Receiver functions stored in hdf5 format#
If you saved your receiver functions in hdf5 format, you can use the
RFDataBase
class to access and manipulate
your database.
Note
Accessing receiver functions in hdf5 format works similarly to accessing raw waveform data.
As a user, you will only ever be calling the
RFDataBase
class. The only function of this
class is to return a DBHandler
, which hold
all the “useful” functions. To call
RFDataBase
, use a context manager like so:
>>> from pyglimer.database.rfh5 import RFDataBase
>>> with RFDataBase('/path/to/myfile.h5') as rfdb:
>>> type(rfdb) # This is a DBHandler
<class 'pyglimer.database.rfh5.DBHandler'>
Warning
Do not call DBHandler
directly! This
might lead to unexpected behaviour or even dataloss due to corrupted hdf5
files.
Warning
If you should for some reason decide to not use the context manager, you
will have to close the hdf5 file with
_close()
to avoid corrupting
your files!
DBHandler
has the following public methods:
|
Reading data#
The most common usecase is probably that you will want to access receiver
functions that PyGLImER computed for you (as shown earlier). To do so, you
can use the get_data()
method:
>>> from pyglimer.database.rfh5 import RFDataBase
>>> with RFDataBase('/path/to/myfile.h5') as rfdb:
>>> rfst = rfdb.get_data(
>>> tag='rf', network='IU', station='*', phase='P', evt_time='*', pol='v')
>>> # rfst is a RFStream object on that we can use methods (more later)
>>> print(type(cst))
<class 'pyglimer.rf.create.CorrStream'>
>>> #rfst.count()
289
As you can see, we use seed station codes to identify data. All arguments accept
wildcards. The data we are loading are receiver functions from waveforms
recorded at every station of the IU network caused by events with any origin
time (evt_time='*'
).
See also
If you want to create your own function to
walk()
might come in handy.
Getting an overview over available data#
You can Access the DBHandler like a dictionary: Just like in h5py, it is
possible to access the DBHandler
like a
dictionary. The logic works as follows:
dbh[tag][network][station][phase][pol][evt_time]
Following the logic of the structure above, we can get a list of all available tags as follows:
>>> print(list(dbh.keys()))
['rf', 'rf_with_my_funny_processing_idea']
Writing data to hdf5#
If you postprocess your receiver functions (e.g., stacking), you might want to save the data afterwards. You can do that like below:
1from pyglimer.database.rfh5 import RFDataBase
2
3# Suppose you have a RFStream or RFTrace object rf
4# that has a header with all the station information
5
6with RFDataBase('/path/to/myfile.h5') as rfdb:
7 rfst = rfdb.add_rf(
8 rf, tag='rf_with_my_funny_processing_idea')
We can retrieve the RFStream
as shown above.
Network, station, and channel information are determined automatically from the
header and used to identify and locate the data.