Skip to content
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

Party.relative_magnitude or Party.lag_calc(relative_magnitude=True) broken in 0.4.x #385

Closed
ikahbasi opened this issue Apr 20, 2020 · 7 comments
Labels
bug core.lag_calc utils.mag_calc Associated with magnitude calculation issues
Milestone

Comments

@ikahbasi
Copy link
Collaborator

ikahbasi commented Apr 20, 2020

What do you need help with?

when I use lag_calc method on 'eqcorrscan.core.match_filter.party.Party' object and set relative_magnitude to True
This error occurs:
ValueError: zero-size array to reduction operation maximum which has no identity

in addition when I set signal_window
This error occurs:
relative_magnitude() got multiple values for keyword argument 'signal_window'
so can't I change it?

for example:
I used 24-hour data of a station and made a tribe with one event in this data.
And used the tribe in the same data to make a self detection.
In all steps everything is ok, except when I set relative_magnitude to True.

Provide an example so that we can reproduce your problem

problem 1

kwargs = {'noise_window': (-20, -1), 'min_snr': 1.0}
cat_cc = party.lag_calc(stream=st, pre_processed=False,
                                shift_len=0.5, min_cc=0.5,
                                horizontal_chans=['E', 'N', '1', '2'],
                                vertical_chans=['Z'], cores=cores,
                                interpolate=False, plot=plot,
                                plotdir=join(output, 'lag-plot'),
                                parallel=parallel, process_cores=cores,
                                ignore_bad_data=False,
                                relative_magnitudes=relative_magnitudes,
                                `**kwargs)

error is:

Traceback (most recent call last):
  File "3-lag_calc.py", line 78, in <module>
    **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/party.py", line 868, in lag_calc
    relative_magnitudes=relative_magnitudes, **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/family.py", line 609, in lag_calc
    **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/family.py", line 682, in relative_magnitudes
    signal_window=signal_window, **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/utils/mag_calc.py", line 584, in relative_magnitude
    min_snr=min_snr, use_s_picks=use_s_picks)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/utils/mag_calc.py", line 485, in relative_amplitude
    seed_id=seed_id)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/utils/mag_calc.py", line 429, in _get_signal_and_noise
    return noise_amp, signal.max(), signal.std()
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/numpy/core/_methods.py", line 30, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity

problem2

kwargs = {'noise_window': (-20, -1),
                  'signal_window': (-0.5, 20),
                  'min_snr': 1.0}

error is:

Traceback (most recent call last):
  File "3-lag_calc.py", line 78, in <module>
    **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/party.py", line 868, in lag_calc
    relative_magnitudes=relative_magnitudes, **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/family.py", line 609, in lag_calc
    **kwargs)
  File "/home/imon/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/core/match_filter/family.py", line 682, in relative_magnitudes
    signal_window=signal_window, **kwargs)
TypeError: relative_magnitude() got multiple values for keyword argument 'signal_window'

What help would you like?

what is the solution?

What is your setup? (please complete the following information):**

  • Operating System:
    ubuntu 18.04
  • Python version:
    Python 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
    [GCC 7.3.0] :: Anaconda, Inc. on linux
  • EQcorrscan version:
    0.4.0
@calum-chamberlain
Copy link
Member

Morning @imankahbasi. Please see issue #353: at the moment relative magnitudes from lag_calc is not working. I had hoped to fix this for 0.4.1, but did not get around to it.

You can use the relative_magnitude function directly in the meantime.

The fundamental reason that the party.relative_magnitude method does not work is because the template does not include sufficient pre-template noise to calculate the SNR. This is what results in the first error you are getting. The solution to this from my end isn't obvious; either we:

  1. include pre-template noise in the template, making the template object heavier (not keen on this)
  2. include the snr in the template (this is my preferred option, and wouldn't require much code because SNR is already calculated when generating templates, but would mean that old templates would not be compatible with relative_magnitudes - a warning could be raised for this)
  3. require users to provide pre-template noise when calling the relative_magnitude method (not keen on this either because it would be hard to do on the user end).

The other error is my bad on documentation. Internally the signal-window is set to the length of the template; this should be the default, but should be ignored if the user provides a signal window.

I'm going to leave this issue open to remind me to fix or remove the method. Of the fixes I prefer option 2, but this will require a new major version (0.5.0) because it will change the way that template objects work.

To-Do

  • Fix or remove relative_magnitude method on Party and Family to use SNR
  • Allow signal_window to be passed properly.

@calum-chamberlain calum-chamberlain changed the title [HELP] use lag_calc when set relative_magnitude to True Party.relative_magnitude or Party.lag_calc(relative_magnitude=True) broken in 0.4.x Apr 20, 2020
@calum-chamberlain calum-chamberlain added bug core.lag_calc utils.mag_calc Associated with magnitude calculation issues labels Apr 20, 2020
@calum-chamberlain calum-chamberlain added this to the future milestone Apr 20, 2020
@ikahbasi
Copy link
Collaborator Author

Morinig @calum-chamberlain .
Yes, I think the solution number 2 is good. It's easy and simple.
Although it will be also good if the output of Party.lag_calc() becomes an object like Party(), including re-picked phases, correlation coefficient of each phases and ... (or directly change Party()).
Then we can have rethreshold and other methods same as Party() for future investigations.
And we can use these correlation coefficients in relative_magnitude function as input.

@calum-chamberlain
Copy link
Member

calum-chamberlain commented Apr 21, 2020 via email

@ikahbasi
Copy link
Collaborator Author

Yes, but we can't access to the correlation coefficients in distinct stations and channels after implement lag_calc method.
My point is that we can access to them in all channel-stations that we use.

@calum-chamberlain
Copy link
Member

calum-chamberlain commented Apr 21, 2020 via email

@ikahbasi
Copy link
Collaborator Author

ikahbasi commented Apr 21, 2020

Oooo, thank you. :)
I didn't know that.
Now I can pass them to relative_magnitude function. 👍

It will be also good if these correlation-coefficients be inheritance of the
class eqcorrscan.core.match_filter.detection.Detection.

@calum-chamberlain
Copy link
Member

Closed by #412 - this issue requires more work changing Template objects and will (hopefully) be rekindled when I have the time, or someone else wants to chip in.

calum-chamberlain added a commit that referenced this issue Mar 14, 2022
* Start an FAQ

* Remove relative magnitude methods for now, see issue #385

* Add SAC question.

* implement magnitude-bias correction as in Schaff & Richards 2014

* add change-comment

* stickler

* syntax

* fix L2-norm SNR

* fix signal norm normalization (now RMS amplitude)

* add python version to conda environment creation

* Update installation.rst

Simplify install and let conda work out Python versions.

* Update faq.rst

* Bump obspy version to 1.3.0 (#486)

* Bump obspy version to 1.3.0

* Test on py 3.9, 3.10

* Encapsulate python versions in quotes

* Remove future use

* Temporarally pin pyfftw version

* Use pip for pyfftw

* Don't pin pyproj

* Try using micromamba

* Try using mamba

* underscore

* update maco env

* update slow tests

* Force h5py version to avoid dependency conflict

* Debug macos omp linking error

* Use conda

* Add back in condarc

* Don't run on 3.10 for now - macos requirements are not there

Co-authored-by: flixha <felix.halpaap@uib.no>
Co-authored-by: Tyler Newton <tjnewton.uni@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core.lag_calc utils.mag_calc Associated with magnitude calculation issues
Projects
None yet
Development

No branches or pull requests

2 participants