eqcorrscan / EQcorrscan

Earthquake detection and analysis in Python.
https://eqcorrscan.readthedocs.io/en/latest/
Other
164 stars 86 forks source link

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

Closed ikahbasi closed 4 years ago

ikahbasi commented 4 years ago

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):**

calum-chamberlain commented 4 years ago

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

ikahbasi commented 4 years ago

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 commented 4 years ago

Correlation coefficients from lag calc are used by relative_magnitude when called from lag calc. Party.lag_calc updates the event object of each detection, so I think everything else you ask for is already implemented.

CJ Chamberlain, out of office


From: iman kahbasi notifications@github.com Sent: Tuesday, April 21, 2020 7:08:58 PM To: eqcorrscan/EQcorrscan EQcorrscan@noreply.github.com Cc: Calum Chamberlain calum.chamberlain@vuw.ac.nz; Mention mention@noreply.github.com Subject: Re: [eqcorrscan/EQcorrscan] Party.relative_magnitude or Party.lag_calc(relative_magnitude=True) broken in 0.4.x (#385)

Morinig @calum-chamberlainhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcalum-chamberlain&data=02%7C01%7Ccalum.chamberlain%40vuw.ac.nz%7C91b40d9449ef450c5e5808d7e5c2ddae%7Ccfe63e236951427e8683bb84dcf1d20c%7C0%7C0%7C637230497464365156&sdata=q7kzXJBCmRaOZEVqSlr7yzIV8Bi40KeuIq53Wr7pULg%3D&reserved=0 . 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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feqcorrscan%2FEQcorrscan%2Fissues%2F385%23issuecomment-616996282&data=02%7C01%7Ccalum.chamberlain%40vuw.ac.nz%7C91b40d9449ef450c5e5808d7e5c2ddae%7Ccfe63e236951427e8683bb84dcf1d20c%7C0%7C0%7C637230497464375158&sdata=dfVLsPMZwHU4Fg8S5KosbIVwicpuNJrdhuj%2BjH6BULE%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACTIM476UKPRUOJCR55C5R3RNVBAVANCNFSM4MMVU7MQ&data=02%7C01%7Ccalum.chamberlain%40vuw.ac.nz%7C91b40d9449ef450c5e5808d7e5c2ddae%7Ccfe63e236951427e8683bb84dcf1d20c%7C0%7C0%7C637230497464375158&sdata=58a8FI2Kd%2BqsMoLss6qj%2FfgfOh%2B%2BwGspjAXbdEk4hiA%3D&reserved=0.

ikahbasi commented 4 years ago

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 commented 4 years ago

You can, they are in comments on the picks.

CJ Chamberlain, out of office


From: iman kahbasi notifications@github.com Sent: Tuesday, April 21, 2020 9:44:53 PM To: eqcorrscan/EQcorrscan EQcorrscan@noreply.github.com Cc: Calum Chamberlain calum.chamberlain@vuw.ac.nz; Mention mention@noreply.github.com Subject: Re: [eqcorrscan/EQcorrscan] Party.relative_magnitude or Party.lag_calc(relative_magnitude=True) broken in 0.4.x (#385)

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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feqcorrscan%2FEQcorrscan%2Fissues%2F385%23issuecomment-617073602&data=02%7C01%7Ccalum.chamberlain%40vuw.ac.nz%7Ca2ce01d2566d4b69523208d7e5d8a60e%7Ccfe63e236951427e8683bb84dcf1d20c%7C0%7C0%7C637230591050118195&sdata=bMKP05tEfrLxNdiIPvB91JtxzPLGmx5bqrQZJDr%2F8Ds%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACTIM45MPAXBI27CFNODLO3RNVTJLANCNFSM4MMVU7MQ&data=02%7C01%7Ccalum.chamberlain%40vuw.ac.nz%7Ca2ce01d2566d4b69523208d7e5d8a60e%7Ccfe63e236951427e8683bb84dcf1d20c%7C0%7C0%7C637230591050128189&sdata=l%2BPB6Pue4GR231joVtoBbUN7FweMy8aQkS6lLEMnTyw%3D&reserved=0.

ikahbasi commented 4 years ago

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

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

calum-chamberlain commented 4 years ago

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.