-
Notifications
You must be signed in to change notification settings - Fork 12
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
New Spectrum() and SpectrumStream() classes #50
Conversation
Claudio, I have an option to write the processed traces and the spectra (as "auxiliary" data) to an ASDF file (which is based on HDF5). This will need to be revised, but I should not otherwise be affected. I will test this tomorrow or beginning of next week. Actually, it would be nice if obspy itself would support writing to HDF5, including the header information. None of the currently supported formats support preserving the metadata. |
Thanks Kris!
ObsPy A more portable |
bdd5bfe
to
02e346a
Compare
After a clean switch to the
This is very strange, as |
Will look into that on Tuesday! Happy Easter! 🐣 |
I investigated this problem a bit further. It happens for traces with no or too short noise window:
In that case, the spectrum header fields The solution is to either set Happy Easter to you as well! |
A suggestion for writing to HDF5:
|
Hello, this should be fixed with the latest commit. I prefer to use my implementation of Maybe, in the future, I'll use this |
You mean something like:
? What would be the advantage to have this top-level group? Would there be any other group than
The numbering is meant to reflect the order in the |
7e1ec84
to
23d912d
Compare
Force-pushed a better solution. Please verify again 😉 🙏 |
Concerning the suggestions for the HDF5 format:
These are just suggestions, based on my experience with ASDF files. It's of course your decision, but it could promote this HDF5 format as a more general format for seismic data... |
That's nasty! The time window has totally changed! Let's try something first: I'll rebase this branch on |
23d912d
to
5a79749
Compare
Rebased and force-pushed. Could you please force-pull and try again? |
The problem is gone after force-pushing. |
I'm convinced! 👍 See the last commit, where I implemented your idea, with the only difference of using |
@krisvanneste, ok for you to merge? |
Very strange! Spectra are written after all the manipulations and after the inversion (see here). Looking at your figure, I have the impression that you read the |
Claudio, |
OK, got it sorted now. I had to add a line to save the spectra in my wrapper function. |
Sorry for late reply. Yes, there is a new config option called |
Yes, but I also had to call the save_spectra function in my wrapper. |
So, good to merge? 🙃 |
Yes, go ahead! |
Class is redesigned so that it does not inherit anymore from ObsPy's Trace class. This allows to have a more flexible class that can be expanded in the future. Also add a SpectrumStream class to handle a collection of Spectrum objects.
So that they can be serialized to YAML more easily.
Dictionaries are serialized to a string and deserialized using YAML.
…dard floats. This is necessary to avoid issues with the YAML serialization of the metadata objects.
In particular, those with default values.
Also, spectra are now stored in groups named `spectrum_NNNNN_NET.STA.LOC.CHAN`
b072065
to
2678eee
Compare
Merged!!! 🚀 |
Thanks Kris for the review and the suggestions 🙏 |
For an ongoing project, I need to save spectra to the output directory.
This motivated me to tackle the technical debt which was accumulating in the
Spectrum()
class.This is the first class I wrote 12 years ago (!) and at that time I decided that a quick and dirty –yet functional– solution was to make it inherit from ObsPy
Trace()
object.One of the limits of this approach was that there wasn't any easy option (except of using
pickle
) to save spectra to disk.So, I rewrote the
Spectrum()
class from scratch, while trying to keep the same interface of the previous one, with one difference:Spectrum().get_freq()
does not exist anymore: it has been replaced by the class attributeSpectrum().freq
. I chose indeed to store all the frequencies, and not only the starting frequency and the frequency delta. In this way, we have the same interface forSpectrum().freq
andSpectrum().freq_logspaced
.The main improvements are the following:
The new
Spectrum()
class, of course 😄A new
SpectrumStream()
class, similar to ObsPyStream()
, to storeSpectrum()
objects. (Note that ObsPyStream()
will no longer acceptSpectrum()
objects, since they do not inherit anymore fromTrace()
).Both
Spectrum()
andSpectrumStream()
have a.write()
method to save the spectra to disk inHDF5
orTEXT
format. Both formats use YAML for serializing the metadata inSpectrum().stats
.The new
HDF5
format is used for storing spectral residuals (replacing thepickle
format).A new config option
save_spectra
(default:False
) is introduced, to save spectra to the output dir.Finally, I added the function
read_spectra()
(similar to ObsPyread()
) which will read anHDF5
orTEXT
file and return aSpectrumStream()
with one or moreSpectrum()
objects.I thoroughly tested these new classes with my default examples and with many other events: the results are consistent, with some small (~1%) differences arising sometimes, probably because of the different way frequencies are stored.
However, before merging this PR, I'm calling @krisvanneste and @rcabdia to kindly check that the new code does not introduce any regression in your use cases, since you are both using the SourceSpec API.
Thanks!☺️
Claudio