-
Notifications
You must be signed in to change notification settings - Fork 86
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
Implement relative magnitude bias correction as in Schaff & Richards 2014 #461
Implement relative magnitude bias correction as in Schaff & Richards 2014 #461
Conversation
Hey Felix, thanks for taking the time to do this! I agree that the weight_by_correlation version (equation 4) doesn't seem like it is likely to give reliable (or meaningful) results in most circumstances. I was using it specifically for repeating earthquakes, with very high correlations (cc >.9 on all channels and very similar amplitudes), so the impact was pretty minimal. I also agree that, on further reading, it looks like the authors didn't make use of equation 4, except on their way to later equations. You might want to check that SNR is calculated in the same way as Schaff and Richards do, and ensure that if SNR drops to 1, then a warning is given and/or the relative magnitude is not returned (which probably should have been in there anyway to avoid spurious results) |
Oh! some of the tests actually completed! By the way, if you want us to make a new release with this in it next week I would be keen to get it out - it isn't that much work to push out a new release, and I think it would be good to get this correction out into user-land (and remove the old, not particularly useful version!). |
Yeah, sometimes in a lucky moment the web services return the data as expected! Thanks for the comment on the SNR - you're right, this was good to check again. The paper computes the SNR from the ratio of L2-norms of signal and noise. Compared to the original SNR that is commonly used in EQcorrscan ( max(singal)/rms(noise) ), the L2-norm SNR has a smaller value, commonly smaller by a factor of 3-10. In
Let me know whether it's ok for you to replace current functionality as in the points above, or whether you prefer new functions in addition to the old ones!: |
Great, thanks! Some thoughts on your thoughts:
I think it might be worth changing the function name to something like |
|
Cool - if you are happy I think we can go ahead and merge this. |
Yes, I'm happy with this! Thanks a lot for reviewing, and I'm happy to have it merged now. |
Hi @flixha, I have been using relative_magnitudes as well and I think what you've suggested here is great. I was looking through your commits in your PR and I have a question about the output derived from this part of your commit:
After following the conversation on #455, I was wondering if this new rel_mag output you are suggesting is still weighted by cc, since you are opting to remove the Perhaps the function description could use a weighted / non-weighted specification when describing the dictionary being returned? I was using the Also, on a side note, if |
Hi @darren-tpk! There was never a weighting implemented in the sense of EQcorrscan/eqcorrscan/utils/mag_calc.py Line 636 in 168eba4
So new_mag = reference_mag + np.sum(rel_mags) / len(rel_mags) is the way to calculate it now and before. You can of course try a weighting like you thought was included (with the returned CC-values) in addition to the magnitude-bias-correction (which is quite important if you have noisy traces which lead to CC~< 0.95 or so.
|
What does this PR do?
For
utils.mag_calc.relative_magnitude
, this PR implements equation 10 of Schaff & Richards 2014. This corrects the bias in the relative magnitude due tocc < 1
andSNR < ∞
.Why was it initiated? Any relevant Issues?
See #455. I opened that issue because I couldn't seem to get reasonable magnitudes estimated with the current implementation of
relative_magnitude
, as demonstrated in the figure below:Figure 1: Comparison of local and relative magnitude estimations for different equations. Left: previous implementation in EQcorrscan. Middle: relative magnitudes standard L2-norm, i.e., no bias-correction for CC or SNR. Right: implementation in this PR according to equation 10 in Schaff & Richards 2014. Note how the relation on the left seems to be quite wrong, while for the others the trend is alright. Low precision is due to I/O from Nordic format.
Compared to the previous implementation, this PR implements equation 10 rather than equation 4 from the paper. Now that I got to read the paper thoroughly, how I understand it is that this is the equation that the authors actually use to determine corrected delta-magnitudes. That equation includes correcting the bias that CC<1 and noise introduce. I'm not exactly sure when equation 4 produces reasonable results, but I think that would be limited to some rather specific cases (see how it doesn't work in the figure above).
weight_by_correlation
tocorrect_mag_bias
.relative_amplitude
now returns dicts of SNRs to which equation 10 needs accessweight_by_correlation=False
returns the standard L2-norm relative magnitudes from the figure in the middlePR Checklist
develop
base branch selected?CHANGES.md
.[ ] First time contributors have added your name toCONTRIBUTORS.md
.