Example #1
0
 def test_pk_baer(self):
     """
     Test pk_baer against implementation for UNESCO short course
     """
     filename = os.path.join(self.path, 'manz_waldk.a01.gz')
     with gzip.open(filename) as f:
         data = np.loadtxt(f, dtype=np.float32)
     df, ntdownmax, ntupevent, thr1, thr2, npreset_len, np_dur = \
         (200.0, 20, 60, 7.0, 12.0, 100, 100)
     nptime, pfm = pk_baer(data, df, ntdownmax, ntupevent,
                           thr1, thr2, npreset_len, np_dur)
     self.assertEqual(nptime, 17545)
     self.assertEqual(pfm, 'IPU0')
def pick_baer(stream, picker_config=None, config=None):
    """Wrapper around the Baer P-phase picker.

    Args:
        stream (StationStream):
            Stream containing waveforms that need to be picked.
        picker_config (dict):
            Dictionary with parameters for Baer P-phase picker. See picker.yml.
        config (dict):
            Configuration dictionary. Key value here is:
                windows:
                    window_checks:
                        min_noise_duration
    Returns:
        tuple:
            - Best estimate for p-wave arrival time (s since start of trace).
            - Mean signal to noise ratio based on the pick.
    """
    if picker_config is None:
        picker_config = get_config(section='pickers')
    if config is None:
        config = get_config()
    min_noise_dur = config['windows']['window_checks']['min_noise_duration']
    params = picker_config['baer']
    locs = []
    for trace in stream:
        pick_sample = pk_baer(trace.data, trace.stats.sampling_rate,
                              **params)[0]
        loc = pick_sample * trace.stats.delta
        locs.append(loc)

    locs = np.array(locs)
    if np.any(locs >= 0):
        minloc = np.min(locs[locs >= 0])
    else:
        minloc = -1
    if minloc < min_noise_dur:
        fmt = 'Noise window (%.1f s) less than minimum (%.1f)'
        tpl = (minloc, min_noise_dur)
        raise ValueError(fmt % tpl)
    mean_snr = calc_snr(stream, minloc)

    return (minloc, mean_snr)
def pick_baer(stream, picker_config=None, config=None):
    """Wrapper around the Baer P-phase picker.

    Args:
        stream (StationStream):
            Stream containing waveforms that need to be picked.
        picker_config (dict):
            Dictionary with parameters for Baer P-phase picker. See picker.yml.
        config (dict):
            Configuration dictionary. Key value here is:
                windows:
                    window_checks:
                        min_noise_duration
    Returns:
        tuple:
            - Best estimate for p-wave arrival time (s since start of trace).
            - Mean signal to noise ratio based on the pick.
    """
    if picker_config is None:
        picker_config = get_config(section='pickers')
    if config is None:
        config = get_config()
    min_noise_dur = config['windows']['window_checks']['min_noise_duration']
    params = picker_config['baer']
    locs = []
    for trace in stream:
        pick_sample = pk_baer(trace.data, trace.stats.sampling_rate,
                              **params)[0]
        loc = pick_sample * trace.stats.delta
        locs.append(loc)

    locs = np.array(locs)
    if np.any(locs >= 0):
        minloc = np.min(locs[locs >= 0])
    else:
        minloc = -1
    if minloc < min_noise_dur:
        fmt = 'Noise window (%.1f s) less than minimum (%.1f)'
        tpl = (minloc, min_noise_dur)
        raise GMProcessException(fmt % tpl)
    mean_snr = calc_snr(stream, minloc)

    return (minloc, mean_snr)
Example #4
0
def _pick(x, args):
    """ picks a single trace with the baer picker """
    # formatting params
    sr, params = args
    tdownmax = int(params["tdownmax"])
    tupevent = int(params["tupevent"])
    thr1 = params["thr1"]
    thr2 = params["thr2"]
    preset_len = int(params["preset_len"])
    p_dur = int(params["p_dur"])
    offset_constant = params["offset_constant"]
    p_ind, _ = pk_baer(
        x,
        sr,
        tdownmax=tdownmax,
        tupevent=tupevent,
        thr1=thr1,
        thr2=thr2,
        preset_len=preset_len,
        p_dur=p_dur,
    )
    return p_ind + offset_constant
Example #5
0
st = st.sort()

# 3) Do the picking
tr1 = st[0]
#print(tr1.stats)
df = tr1.stats.sampling_rate
start_time = tr1.stats['starttime']
# #print(start_time)
# start_time = UTCDateTime(start_time)
# #print(start_time)
# #st.filter("lowpass", freq=7, corners=10)   # , zerophase=True
tr1 = st[0]
# tr2 = st[1]
# tr3 = st[2]

p_pick, phase_info = pk_baer(tr1.data, df, 20, 60, 7.0, 12.0, 100, 100)
print(p_pick)
print(phase_info)
print(p_pick / df)
print(start_time + (p_pick / df))
#st = st.slice(starttime=start_time, endtime=(start_time+15*60))

# p_pick, s_pick = arPick(tr1.data, tr2.data, tr3.data, df, 1.0, 20.0, 1.0, 0.1, 4.0, 1.0, 2, 8, 0.1, 0.2)
# print(p_pick)
# print(s_pick)
# p_pick = start_time + p_pick
# s_pick = start_time + s_pick
# print(p_pick)
# print(s_pick)

# st.plot(type='relative')
Example #6
0
def signal_split(st,
                 event_time=None,
                 event_lon=None,
                 event_lat=None,
                 method='velocity',
                 vsplit=7.0,
                 picker_config=None):
    """
    This method tries to identifies the boundary between the noise and signal
    for the waveform. The split time is placed inside the
    'processing_parameters' key of the trace stats.

    If split_method is 'velocity', then the split between the noise and signal
    window is approximated as the arrival time of a phase with velocity equal
    to vsplit.

    If split_method is equal to 'p_arrival', then the P-wave arrival is
    used as the split between the noise and signal windows. Multiple picker
    methods are suppored and can be configured in the config file
    '~/.gmprocess/picker.yml

    Args:
        st (StationStream):
            Stream of data.
        event_time (UTCDateTime):
            Event origin time.
        event_lon (float):
            Event longitude.
        event_lat (float):
            Event latitude.
        method (str):
            Method for splitting noise and signal windows. Either 'p_arrival'
            or 'velocity'.
        vsplit (float):
            Velocity (km/s) for splitting noise and signal.

    Returns:
        trace with stats dict updated to include a
        stats['processing_parameters']['signal_split'] dictionary.
    """
    if picker_config is None:
        picker_config = get_config(picker=True)

    if method == 'p_arrival':
        preferred_picker = picker_config['order_of_preference'][0]

        if preferred_picker == 'ar':
            # Get the east, north, and vertical components from the stream
            st_e = st.select(channel='??[E1]')
            st_n = st.select(channel='??[N2]')
            st_z = st.select(channel='??[Z3]')

            # Check if we found one of each component
            # If not, use the next picker in the order of preference
            if len(st_e) != 1 or len(st_n) != 1 or len(st_z) != 1:
                logging.warning('Unable to perform AR picker.')
                logging.warning('Using next available phase picker.')
                preferred_picker = picker_config['order_of_preference'][1]
            else:
                tdiff = ar_pick(st_z[0].data, st_n[0].data, st_e[0].data,
                                st_z[0].stats.sampling_rate,
                                **picker_config['ar'])[0]
                tsplit = st[0].stats.starttime + tdiff

        if preferred_picker in ['baer', 'cwb']:
            tdiffs = []
            for tr in st:
                if preferred_picker == 'baer':
                    pick_sample = pk_baer(tr.data, tr.stats.sampling_rate,
                                          **picker_config['baer'])[0]
                    tr_tdiff = pick_sample * tr.stats.delta
                else:
                    tr_tdiff = PowerPicker(tr)[0] - tr.stats.starttime
                tdiffs.append(tr_tdiff)
            tdiff = min(tdiffs)
            tsplit = st[0].stats.starttime + tdiff

        if preferred_picker not in ['ar', 'baer', 'cwb']:
            raise ValueError('Not a valid picker.')

    elif method == 'velocity':
        epi_dist = gps2dist_azimuth(
            lat1=event_lat,
            lon1=event_lon,
            lat2=st[0].stats['coordinates']['latitude'],
            lon2=st[0].stats['coordinates']['longitude'])[0] * M_TO_KM
        tsplit = event_time + epi_dist / vsplit
        preferred_picker = None
    else:
        raise ValueError('Split method must be "p_arrival" or "velocity"')

    if tsplit >= st[0].times('utcdatetime')[0]:
        # Update trace params
        split_params = {
            'split_time': tsplit,
            'method': method,
            'vsplit': vsplit,
            'picker_type': preferred_picker
        }
        for tr in st:
            tr.setParameter('signal_split', split_params)

    return st
                     del realmax[i]
                     del realmaxloc[i]      
          
          for i in range (2):
              if len(pstimes) <= 1:
                  continue
              if pstimes[1] - pstimes[0] > 0:
                  Samp = pswaves[0]

              else :
                  Samp = pswaves[1]
  
                  
# ------------------------------------------------------------------------------------------------------------------------                 
          df = tr.stats.sampling_rate
          BAp_pick, phase_info = pk_baer(tr.data[startwave:endwave], df,
                               20, 60, 7.0, 12.0, 100, 100)

          df = tr.stats.sampling_rate
          ARp_pick, S_pick = ar_pick(tr.data[startwave:endwave], tr.data[startwave:endwave], tr.data[startwave:endwave],df,
                             1.0, 20.0, 1.0, 0.1, 4.0, 1.0, 2, 8, 0.1, 0.2, s_pick=True )
          
          Bap = int((startwave + BAp_pick))
          Arp = int((startwave) + (ARp_pick*100))
          Pwave = round((Bap+Arp)/2)
          Swave = int((startwave) + (S_pick*100))
          # P-wave Amplitude
          Pamp = abs(trdata[Arp]) 

      
          plt.figure(figNumber)
          plt.plot(trdata[startwave:endwave],'b',trdata[startwave:Swave],'y',trdata[startwave:Pwave],'r')