def amp_pick_event(event, st, respdir, chans=['<STR_LIT>'], var_wintype=True,<EOL>winlen=<NUM_LIT>, pre_pick=<NUM_LIT>, pre_filt=True, lowcut=<NUM_LIT:1.0>,<EOL>highcut=<NUM_LIT>, corners=<NUM_LIT:4>, min_snr=<NUM_LIT:1.0>, plot=False,<EOL>remove_old=False, ps_multiplier=<NUM_LIT>, velocity=False):
<EOL>stations = []  <EOL>channels = []  <EOL>picktimes = []  <EOL>picktypes = []  <EOL>picks_out = []<EOL>try:<EOL><INDENT>depth = _get_origin(event).depth<EOL><DEDENT>except MatchFilterError:<EOL><INDENT>depth = <NUM_LIT:0><EOL><DEDENT>if remove_old and event.amplitudes:<EOL><INDENT>for amp in event.amplitudes:<EOL><INDENT>pick = [p for p in event.picks if p.resource_id == amp.pick_id][<NUM_LIT:0>]<EOL>event.picks.remove(pick)<EOL><DEDENT>event.amplitudes = []<EOL><DEDENT>for pick in event.picks:<EOL><INDENT>if pick.phase_hint in ['<STR_LIT:P>', '<STR_LIT:S>']:<EOL><INDENT>picks_out.append(pick)  <EOL>stations.append(pick.waveform_id.station_code)<EOL>channels.append(pick.waveform_id.channel_code)<EOL>picktimes.append(pick.time)<EOL>picktypes.append(pick.phase_hint)<EOL><DEDENT><DEDENT>if len(picktypes) == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL><DEDENT>st.merge()  <EOL>uniq_stas = list(set(stations))<EOL>for sta in uniq_stas:<EOL><INDENT>for chan in chans:<EOL><INDENT>print('<STR_LIT>' + sta + '<STR_LIT:U+0020>' + chan)<EOL>tr = st.select(station=sta, channel='<STR_LIT:*>' + chan)<EOL>if not tr:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>')<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>tr = tr[<NUM_LIT:0>]<EOL><DEDENT>if pre_filt:<EOL><INDENT>try:<EOL><INDENT>tr.split().detrend('<STR_LIT>').merge(fill_value=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>print('<STR_LIT>')<EOL>dummy = tr.split()<EOL>dummy.detrend('<STR_LIT>')<EOL>tr = dummy.merge(fill_value=<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>tr.filter('<STR_LIT>', freqmin=lowcut, freqmax=highcut,<EOL>corners=corners)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>print('<STR_LIT>')<EOL>print(tr)<EOL>continue<EOL><DEDENT><DEDENT>resp_info = _find_resp(<EOL>tr.stats.station, tr.stats.channel, tr.stats.network,<EOL>tr.stats.starttime, tr.stats.delta, respdir)<EOL>PAZ = []<EOL>seedresp = []<EOL>if resp_info and '<STR_LIT>' in resp_info:<EOL><INDENT>PAZ = resp_info<EOL><DEDENT>elif resp_info:<EOL><INDENT>seedresp = resp_info<EOL><DEDENT>if PAZ and len(tr.data) > <NUM_LIT:10>:<EOL><INDENT>tr = _sim_WA(tr, PAZ, None, <NUM_LIT:10>, velocity=velocity)<EOL><DEDENT>elif seedresp and len(tr.data) > <NUM_LIT:10>:<EOL><INDENT>tr = _sim_WA(tr, None, seedresp, <NUM_LIT:10>, velocity=velocity)<EOL><DEDENT>elif len(tr.data) > <NUM_LIT:10>:<EOL><INDENT>warnings.warn('<STR_LIT>' + tr.stats.station + '<STR_LIT:U+0020>' +<EOL>tr.stats.channel + '<STR_LIT>' +<EOL>str(tr.stats.starttime))<EOL>continue<EOL><DEDENT>sta_picks = [i for i in range(len(stations))<EOL>if stations[i] == sta]<EOL>pick_id = event.picks[sta_picks[<NUM_LIT:0>]].resource_id<EOL>arrival = [arrival for arrival in event.origins[<NUM_LIT:0>].arrivals<EOL>if arrival.pick_id == pick_id][<NUM_LIT:0>]<EOL>hypo_dist = np.sqrt(<EOL>np.square(degrees2kilometers(arrival.distance)) +<EOL>np.square(depth / <NUM_LIT:1000>))<EOL>if var_wintype and hypo_dist:<EOL><INDENT>if '<STR_LIT:S>' in [picktypes[i] for i in sta_picks] and'<STR_LIT:P>' in [picktypes[i] for i in sta_picks]:<EOL><INDENT>s_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:S>']<EOL>s_pick = min(s_pick)<EOL>p_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:P>']<EOL>p_pick = min(p_pick)<EOL>try:<EOL><INDENT>tr.trim(starttime=s_pick - pre_pick,<EOL>endtime=s_pick + (s_pick - p_pick) * winlen)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>elif '<STR_LIT:S>' in [picktypes[i] for i in sta_picks]:<EOL><INDENT>s_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:S>']<EOL>s_pick = min(s_pick)<EOL>p_modelled = s_pick - (hypo_dist * ps_multiplier)<EOL>try:<EOL><INDENT>tr.trim(starttime=s_pick - pre_pick,<EOL>endtime=s_pick + (s_pick - p_modelled) *<EOL>winlen)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>p_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:P>']<EOL>p_pick = min(p_pick)<EOL>s_modelled = p_pick + (hypo_dist * ps_multiplier)<EOL>print('<STR_LIT>' % str(p_pick))<EOL>print('<STR_LIT>' % str(hypo_dist))<EOL>print('<STR_LIT>' % str(s_modelled))<EOL>try:<EOL><INDENT>tr.trim(starttime=s_modelled - pre_pick,<EOL>endtime=s_modelled + (s_modelled - p_pick) *<EOL>winlen)<EOL>print(tr)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT>elif '<STR_LIT:S>' in [picktypes[i] for i in sta_picks]:<EOL><INDENT>s_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:S>']<EOL>s_pick = min(s_pick)<EOL>try:<EOL><INDENT>tr.trim(starttime=s_pick - pre_pick,<EOL>endtime=s_pick + winlen)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>p_pick = [picktimes[i] for i in sta_picks<EOL>if picktypes[i] == '<STR_LIT:P>']<EOL>print(picktimes)<EOL>p_pick = min(p_pick)<EOL>s_modelled = p_pick + hypo_dist * ps_multiplier<EOL>try:<EOL><INDENT>tr.trim(starttime=s_modelled - pre_pick,<EOL>endtime=s_modelled + winlen)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(tr.data) <= <NUM_LIT:10>:<EOL><INDENT>warnings.warn('<STR_LIT>' + tr.stats.station)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>amplitude, period, delay = _max_p2t(tr.data, tr.stats.delta)<EOL><DEDENT>except ValueError:<EOL><INDENT>print('<STR_LIT>' % str(tr))<EOL>continue<EOL><DEDENT>noise_amplitude = np.sqrt(np.mean(np.square(tr.data)))<EOL>if amplitude == <NUM_LIT:0.0>:<EOL><INDENT>continue<EOL><DEDENT>if amplitude / noise_amplitude < min_snr:<EOL><INDENT>print('<STR_LIT>' %<EOL>(amplitude / noise_amplitude))<EOL>continue<EOL><DEDENT>if plot:<EOL><INDENT>plt.plot(np.arange(len(tr.data)), tr.data, '<STR_LIT:k>')<EOL>plt.scatter(tr.stats.sampling_rate * delay, amplitude / <NUM_LIT:2>)<EOL>plt.scatter(tr.stats.sampling_rate * (delay + period),<EOL>-amplitude / <NUM_LIT:2>)<EOL>plt.show()<EOL><DEDENT>print('<STR_LIT>' + str(amplitude))<EOL>print('<STR_LIT>' %<EOL>(amplitude / noise_amplitude))<EOL>if pre_filt:<EOL><INDENT>z, p, k = iirfilter(<EOL>corners, [lowcut / (<NUM_LIT:0.5> * tr.stats.sampling_rate),<EOL>highcut / (<NUM_LIT:0.5> * tr.stats.sampling_rate)],<EOL>btype='<STR_LIT>', ftype='<STR_LIT>', output='<STR_LIT>')<EOL>filt_paz = {'<STR_LIT>': list(p), '<STR_LIT>': list(z), '<STR_LIT>': k,<EOL>'<STR_LIT>': <NUM_LIT:1.0>}<EOL>amplitude /= (paz_2_amplitude_value_of_freq_resp(<EOL>filt_paz, <NUM_LIT:1> / period) * filt_paz['<STR_LIT>'])<EOL><DEDENT>if PAZ:<EOL><INDENT>amplitude /= <NUM_LIT:1000><EOL><DEDENT>if seedresp:  <EOL><INDENT>amplitude *= <NUM_LIT><EOL><DEDENT>amplitude *= <NUM_LIT:0.5><EOL>_waveform_id = WaveformStreamID(<EOL>station_code=tr.stats.station, channel_code=tr.stats.channel,<EOL>network_code=tr.stats.network)<EOL>pick_ind = len(event.picks)<EOL>event.picks.append(Pick(<EOL>waveform_id=_waveform_id, phase_hint='<STR_LIT>',<EOL>polarity='<STR_LIT>', time=tr.stats.starttime + delay,<EOL>evaluation_mode='<STR_LIT>'))<EOL>if not velocity:<EOL><INDENT>event.amplitudes.append(Amplitude(<EOL>generic_amplitude=amplitude / <NUM_LIT>, period=period,<EOL>pick_id=event.picks[pick_ind].resource_id,<EOL>waveform_id=event.picks[pick_ind].waveform_id, unit='<STR_LIT:m>',<EOL>magnitude_hint='<STR_LIT>', type='<STR_LIT>', category='<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>event.amplitudes.append(Amplitude(<EOL>generic_amplitude=amplitude / <NUM_LIT>, period=period,<EOL>pick_id=event.picks[pick_ind].resource_id,<EOL>waveform_id=event.picks[pick_ind].waveform_id, unit='<STR_LIT>',<EOL>magnitude_hint='<STR_LIT>', type='<STR_LIT>', category='<STR_LIT>'))<EOL><DEDENT><DEDENT><DEDENT>return event<EOL>
Pick amplitudes for local magnitude for a single event.

Looks for maximum peak-to-trough amplitude for a channel in a stream, and
picks this amplitude and period.  There are a few things it does
internally to stabilise the result:

    1. Applies a given filter to the data - very necessary for small
    magnitude earthquakes;

    2. Keeps track of the poles and zeros of this filter and removes them
    from the picked amplitude;

    3. Picks the peak-to-trough amplitude, but records half of this: the
    specification for the local magnitude is to use a peak amplitude on
    a horizontal, however, with modern digital seismometers, the peak
    amplitude often has an additional, DC-shift applied to it, to
    stabilise this, and to remove possible issues with de-meaning data
    recorded during the wave-train of an event (e.g. the mean may not be
    the same as it would be for longer durations), we use half the
    peak-to-trough amplitude;

    4. Despite the original definition of local magnitude requiring the
    use of a horizontal channel, more recent work has shown that the
    vertical channels give more consistent magnitude estimations between
    stations, due to a reduction in site-amplification effects, we
    therefore use the vertical channels by default, but allow the user
    to chose which channels they deem appropriate;

    5. We do not specify that the maximum amplitude should be the
    S-phase: The original definition holds that the maximum body-wave
    amplitude should be used - while this is often the S-phase, we do not
    discriminate against the P-phase.  We do note that, unless the user
    takes care when assigning winlen and filters, they may end up with
    amplitude picks for surface waves;

    6. We use a variable window-length by default that takes into account
    P-S times if available, this is in an effort to include only the
    body waves.  When P-S times are not available we us the ps_multiplier
    variable, which defaults to 0.34 x hypocentral distance.

:type event: obspy.core.event.event.Event
:param event: Event to pick
:type st: obspy.core.stream.Stream
:param st: Stream associated with event
:type respdir: str
:param respdir: Path to the response information directory
:type chans: list
:param chans:
    List of the channels to pick on, defaults to ['Z'] - should just be
    the orientations, e.g. Z, 1, 2, N, E
:type var_wintype: bool
:param var_wintype:
    If True, the winlen will be multiplied by the P-S time if both P and
    S picks are available, otherwise it will be multiplied by the
    hypocentral distance*ps_multiplier, defaults to True
:type winlen: float
:param winlen:
    Length of window, see above parameter, if var_wintype is False then
    this will be in seconds, otherwise it is the multiplier to the
    p-s time, defaults to 0.9.
:type pre_pick: float
:param pre_pick:
    Time before the s-pick to start the cut window, defaults to 0.2.
:type pre_filt: bool
:param pre_filt: To apply a pre-filter or not, defaults to True
:type lowcut: float
:param lowcut: Lowcut in Hz for the pre-filter, defaults to 1.0
:type highcut: float
:param highcut: Highcut in Hz for the pre-filter, defaults to 20.0
:type corners: int
:param corners: Number of corners to use in the pre-filter
:type min_snr: float
:param min_snr:
    Minimum signal-to-noise ratio to allow a pick - see note below on
    signal-to-noise ratio calculation.
:type plot: bool
:param plot: Turn plotting on or off.
:type remove_old: bool
:param remove_old:
    If True, will remove old amplitude picks from event and overwrite
    with new picks. Defaults to False.
:type ps_multiplier: float
:param ps_multiplier:
    A p-s time multiplier of hypocentral distance - defaults to 0.34,
    based on p-s ratio of 1.68 and an S-velocity 0f 1.5km/s, deliberately
    chosen to be quite slow.
:type velocity: bool
:param velocity:
    Whether to make the pick in velocity space or not. Original definition
    of local magnitude used displacement of Wood-Anderson, MLv in seiscomp
    and Antelope uses a velocity measurement.

:returns: Picked event
:rtype: :class:`obspy.core.event.Event`

.. Note::
    Signal-to-noise ratio is calculated using the filtered data by
    dividing the maximum amplitude in the signal window (pick window)
    by the normalized noise amplitude (taken from the whole window
    supplied).

.. Warning::
    Works in place on data - will filter and remove response from data,
    you are recommended to give this function a copy of the data if you
    are using it in a loop.