-
Notifications
You must be signed in to change notification settings - Fork 530
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
adding spectral methods to trace object #837
base: master
Are you sure you want to change the base?
Conversation
👍 on this. I developed a code for source parameters estimation from spectral inversion, and I needed to build a custom spectral object to deal with spectra. I don't feel like sharing the code here, since it is an horrible hack created from subclassing a I think that a proper implementation of spectral methods would benefit a significant class of applications. |
Talked with @jwassermann a bit about it.. while I'd propose adding a class Comments? There's a lot to be thought through properly here... |
Good idea. The Just some ideas on how this could work: import obspy
tr = obspy.read()[0]
# Go to frequency domain, maybe with other methods/options as well.
f_tr = tr.fft()
# data and freqs are stored here.
f_tr.data
f_tr.freqs
# Frequency domain taper, e.g. some filter.
f_tr.taper(...)
f_tr.plot()
...
# Go back to time domain. For that to be possible the starttime
# must also be stored for the frequeny domain trace.
tr = f_tr.ifft() |
|
Other thoughts: I would like to have What about streams? Could a |
There should be I agree with I don't really get the |
|
👍 we can't allow to mix both types.
👍 for storing data as complex. talked with @jwassermann about it, we will need to define properties
absolutely. we should probably store this in |
That proposal appears to coincide with some thoughts on #617, I think? |
Hi guys, |
If it's gonna be in separate files as @krischer proposed, the only way is to do the |
I moved the FrequencyDomainTrace to the frequency_domain_trace.py like @krischer recommended. Additionally, I built in the numpy rfft, irfft and fftfreq , because of the return type of the scipy version. The fft is now attached to the TimeSeriesTrace with an differentiation of Trace and TimeSeriesTrace. I also started to build up the TimeSeriesFrequencyDomainTrace, that has currently just the ifft implemented. |
data2 = tr2.data | ||
data2_conj = np.conj(data2) | ||
cross_spectrum = data2_conj*data1 | ||
coherence = (cross_spectrum)**2/(np.abs(data1)*np.abs(data2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fstettner, smoothing of spectra is missing here..
In the long run I would propose adding a method to FFTTrace, e.g. def smoothed(self, window, npts)
(or width given in Hz).
For now you could just hardcode some fixed window from scipy, see http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.get_window.html#scipy.signal.get_window. For orientation, Poupinet 1984 used a five point triangular window for 100Hz sampled data.
CC @jwassermann
I implemented the conjugate method. The coherence-method also should work now (with hanning). |
yf = self.data | ||
xf = np.linspace(0.0, 1.0/(2.0*T), N/2) | ||
fig, ax = plt.subplots() | ||
ax.plot(xf, 2.0/N * np.abs(yf[:N/2])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just use the self.frequencies()
method which would me much easier.
👍 to get this done asap! |
This was done as a student project and likely needs more work.. :-/ |
This pull request has been mentioned on ObsPy Forum. There might be relevant details there: https://discourse.obspy.org/t/trace-remove-response-outputting-disp-or-acc/1259/6 |
Coming from the 'old school' interactive side, I dearly miss spectral methods attached directly to a trace object. While the spectrogram, which to me is a more sophisticated method is already available as a method, the direct estimation of psd/multi-taper and fft is not available. Certainly this can be done by modules of scipy or mlab BUT what I'm thinking of is to return a complex trace (resulting from a fft), manipulate it and possibly transfer it back to time domain. This means that all trace.stats information should be kept while the sampling or delta needs to be modified to frequency domain (i.e. 1/(time window). This would open up the world of trace manipulation in frequency domain, easy cross-spectral estimates, sub-sample shifts etc AND of course an easy and fast way of displaying the frequency content. Possibly this would result in a new 'trace object' and therefore needs a re-definition of the Trace object itself.
What is the opinion of the developers?
Cheers Jo