From d16623084f00cb6b306f62f0ab45251e917cb950 Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Tue, 28 May 2024 13:17:25 +1200 Subject: [PATCH 1/4] Add option to pick from P pick --- eqcorrscan/utils/mag_calc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/eqcorrscan/utils/mag_calc.py b/eqcorrscan/utils/mag_calc.py index cd0a3caa4..6028396bd 100644 --- a/eqcorrscan/utils/mag_calc.py +++ b/eqcorrscan/utils/mag_calc.py @@ -691,7 +691,7 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, winlen=0.9, pre_pick=0.2, pre_filt=True, lowcut=1.0, highcut=20.0, corners=4, min_snr=1.0, plot=False, remove_old=False, ps_multiplier=0.34, velocity=False, - water_level=0, iaspei_standard=False): + water_level=0, iaspei_standard=False, win_from_p=False): """ Pick amplitudes for local magnitude for a single event. @@ -779,6 +779,9 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, static amplification of 1), or AML with wood-anderson static amplification of 2080. Note: Units are SI (and specified in the amplitude) + :type win_from_p: bool + :param win_from_p: + Whether to start the picking window from the P-time or not. :returns: Picked event :rtype: :class:`obspy.core.event.Event` @@ -891,7 +894,10 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, raise NotImplementedError( "No p or s picks - you should not have been able to " "get here") - trim_start = s_time - pre_pick + if win_from_p: + trim_start = p_time - pre_pick + else: + trim_start = s_time - pre_pick trim_end = s_time + (s_time - p_time) * winlen # Work out the window length based on p-s time or distance else: # Fixed window-length @@ -908,7 +914,10 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, "No s-pick or hypocentral distance to predict " f"s-arrival for station {sta}, skipping") continue - trim_start = s_time - pre_pick + if win_from_p: + trim_start = p_time - pre_pick + else: + trim_start = s_time - pre_pick trim_end = s_time + winlen tr = tr.trim(trim_start, trim_end) if len(tr.data) <= 10: From ad1ff188250761174140779200cd628a15a77f0c Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Wed, 19 Jun 2024 13:02:07 +1200 Subject: [PATCH 2/4] Add catch for negative length trimming --- eqcorrscan/utils/mag_calc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eqcorrscan/utils/mag_calc.py b/eqcorrscan/utils/mag_calc.py index 6028396bd..a3a86ebf7 100644 --- a/eqcorrscan/utils/mag_calc.py +++ b/eqcorrscan/utils/mag_calc.py @@ -919,6 +919,9 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, else: trim_start = s_time - pre_pick trim_end = s_time + winlen + if trim_end <= trim_start: + Logger.error(f"Trying to trim to negative length: {trim_start} -- {trim_end}. Skipping") + continue tr = tr.trim(trim_start, trim_end) if len(tr.data) <= 10: Logger.warning(f'Insufficient data for {sta}') From 020e003ff3af2f42d3f3ed1a05cdbc3fbffad3d8 Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Wed, 26 Jun 2024 18:12:57 +1200 Subject: [PATCH 3/4] linter --- eqcorrscan/utils/mag_calc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eqcorrscan/utils/mag_calc.py b/eqcorrscan/utils/mag_calc.py index a3a86ebf7..57445a903 100644 --- a/eqcorrscan/utils/mag_calc.py +++ b/eqcorrscan/utils/mag_calc.py @@ -920,7 +920,9 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, trim_start = s_time - pre_pick trim_end = s_time + winlen if trim_end <= trim_start: - Logger.error(f"Trying to trim to negative length: {trim_start} -- {trim_end}. Skipping") + Logger.error( + f"Trying to trim to negative length: " + f"{trim_start} -- {trim_end}. Skipping") continue tr = tr.trim(trim_start, trim_end) if len(tr.data) <= 10: From 21485f67da0ab0fd9f4f4a95a3b37dc1f33ce0d0 Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Sat, 29 Jun 2024 08:30:02 +1200 Subject: [PATCH 4/4] linter --- eqcorrscan/utils/mag_calc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eqcorrscan/utils/mag_calc.py b/eqcorrscan/utils/mag_calc.py index 57445a903..db6f739fe 100644 --- a/eqcorrscan/utils/mag_calc.py +++ b/eqcorrscan/utils/mag_calc.py @@ -781,7 +781,7 @@ def amp_pick_event(event, st, inventory, chans=('Z',), var_wintype=True, amplitude) :type win_from_p: bool :param win_from_p: - Whether to start the picking window from the P-time or not. + Whether to start the picking window from the P-time or not. :returns: Picked event :rtype: :class:`obspy.core.event.Event`