Пример #1
0
 def test_not_delayed(self):
     """Test the method of template_gen without applying delays to
     channels."""
     cat = get_geonet_events(minlat=-40.98,
                             maxlat=-40.85,
                             minlon=175.4,
                             maxlon=175.5,
                             startdate=UTCDateTime(2016, 5, 1),
                             enddate=UTCDateTime(2016, 5, 2))
     cat = filter_picks(catalog=cat, top_n_picks=5)
     template = from_client(catalog=cat,
                            client_id='GEONET',
                            lowcut=None,
                            highcut=None,
                            samp_rate=100.0,
                            filt_order=4,
                            length=10.0,
                            prepick=0.5,
                            swin='all',
                            process_len=3600,
                            debug=0,
                            plot=False,
                            delayed=False)[0]
     for tr in template:
         tr.stats.starttime.precision = 6
     starttime = template[0].stats.starttime
     length = template[0].stats.npts
     print(template)
     for tr in template:
         self.assertTrue(
             abs((tr.stats.starttime - starttime)) <= tr.stats.delta)
         self.assertEqual(tr.stats.npts, length)
Пример #2
0
def get_test_data():
    """
    Generate a set of waveforms from GeoNet for use in subspace testing

    :return: List of cut templates with no filters applied
    :rtype: list
    """
    from eqcorrscan.tutorials.get_geonet_events import get_geonet_events
    from obspy import UTCDateTime
    from eqcorrscan.utils.catalog_utils import filter_picks
    from eqcorrscan.utils.clustering import space_cluster
    from obspy.clients.fdsn import Client

    cat = get_geonet_events(minlat=-40.98,
                            maxlat=-40.85,
                            minlon=175.4,
                            maxlon=175.5,
                            startdate=UTCDateTime(2016, 5, 11),
                            enddate=UTCDateTime(2016, 5, 13))
    cat = filter_picks(catalog=cat, top_n_picks=5)
    stachans = list(
        set([(pick.waveform_id.station_code, pick.waveform_id.channel_code)
             for event in cat for pick in event.picks]))
    clusters = space_cluster(catalog=cat, d_thresh=2, show=False)
    cluster = sorted(clusters, key=lambda c: len(c))[-1]
    client = Client('GEONET')
    design_set = []
    bulk_info = []
    for event in cluster:
        t1 = event.origins[0].time + 5
        t2 = t1 + 15
        for station, channel in stachans:
            bulk_info.append(('NZ', station, '*', channel[0:2] + '?', t1, t2))
    st = client.get_waveforms_bulk(bulk=bulk_info)
    for event in cluster:
        t1 = event.origins[0].time + 5
        t2 = t1 + 15
        design_set.append(st.copy().trim(t1, t2))
    t1 = UTCDateTime(2016, 5, 11, 19)
    t2 = UTCDateTime(2016, 5, 11, 20)
    bulk_info = [('NZ', stachan[0], '*', stachan[1][0:2] + '?', t1, t2)
                 for stachan in stachans]
    st = client.get_waveforms_bulk(bulk_info)
    st.merge().detrend('simple').trim(starttime=t1, endtime=t2)
    return design_set, st
Пример #3
0
 def setUpClass(cls):
     client = Client('GEONET')
     t1 = UTCDateTime(2016, 9, 4)
     t2 = t1 + 86400
     catalog = get_geonet_events(startdate=t1, enddate=t2, minmag=4,
                                 minlat=-49, maxlat=-35, minlon=175.0,
                                 maxlon=185.0)
     catalog = catalog_utils.filter_picks(catalog, channels=['EHZ'],
                                          top_n_picks=5)
     for event in catalog:
         extra_pick = Pick()
         extra_pick.phase_hint = 'S'
         extra_pick.time = event.picks[0].time + 10
         extra_pick.waveform_id = event.picks[0].waveform_id
         event.picks.append(extra_pick)
     cls.templates = template_gen.from_client(catalog=catalog,
                                              client_id='GEONET',
                                              lowcut=2.0, highcut=9.0,
                                              samp_rate=50.0, filt_order=4,
                                              length=3.0, prepick=0.15,
                                              swin='all', process_len=3600)
     # Download and process the day-long data
     bulk_info = [(tr.stats.network, tr.stats.station, '*',
                   tr.stats.channel[0] + 'H' + tr.stats.channel[1],
                   t1 + (4 * 3600), t1 + (5 * 3600))
                  for tr in cls.templates[0]]
     # Just downloading an hour of data
     print('Downloading data')
     st = client.get_waveforms_bulk(bulk_info)
     st.merge(fill_value='interpolate')
     st.trim(t1 + (4 * 3600), t1 + (5 * 3600)).sort()
     # This is slow?
     print('Processing continuous data')
     cls.st = pre_processing.shortproc(st, lowcut=2.0, highcut=9.0,
                                       filt_order=4, samp_rate=50.0,
                                       debug=0, num_cores=1)
     cls.st.trim(t1 + (4 * 3600), t1 + (5 * 3600)).sort()
     cls.template_names = [str(template[0].stats.starttime)
                           for template in cls.templates]
Пример #4
0
def run_tutorial(plot=False, multiplex=True, return_streams=False):
    """
    Run the tutorial.

    :return: detections
    """
    # We are going to use data from the GeoNet (New Zealand) catalogue. GeoNet
    # do not implement the full FDSN system yet, so we have a hack to get
    # around this.  It is not strictly part of EQcorrscan, so we haven't
    # included it here, but you can find it in the tutorials directory of the
    # github repository
    import obspy
    if int(obspy.__version__.split('.')[0]) >= 1:
        from obspy.clients.fdsn import Client
    else:
        from obspy.fdsn import Client
    from eqcorrscan.tutorials.get_geonet_events import get_geonet_events
    from obspy import UTCDateTime
    from eqcorrscan.utils.catalog_utils import filter_picks
    from eqcorrscan.utils.clustering import space_cluster
    from eqcorrscan.core import subspace

    cat = get_geonet_events(minlat=-40.98,
                            maxlat=-40.85,
                            minlon=175.4,
                            maxlon=175.5,
                            startdate=UTCDateTime(2016, 5, 1),
                            enddate=UTCDateTime(2016, 5, 20))
    # This gives us a catalog of events - it takes a while to download all
    # the information, so give it a bit!
    # We will generate a five station, multi-channel detector.
    cat = filter_picks(catalog=cat, top_n_picks=5)
    stachans = list(
        set([(pick.waveform_id.station_code, pick.waveform_id.channel_code)
             for event in cat for pick in event.picks]))
    # In this tutorial we will only work on one cluster, defined spatially.
    # You can work on multiple clusters, or try to whole set.
    clusters = space_cluster(catalog=cat, d_thresh=2, show=False)
    # We will work on the largest cluster
    cluster = sorted(clusters, key=lambda c: len(c))[-1]
    # This cluster contains 32 events, we will now download a trim the
    # waveforms.  Note that each chanel must start at the same time and be the
    # same length for multiplexing.  If not multiplexing EQcorrscan will
    # maintain the individual differences in time between channels and delay
    # the detection statistics by that amount before stacking and detection.
    client = Client('GEONET')
    design_set = []
    bulk_info = []
    for event in cluster:
        t1 = event.origins[0].time
        t2 = t1 + 25
        for station, channel in stachans:
            bulk_info.append(('NZ', station, '*', channel[0:2] + '?', t1, t2))
    st = client.get_waveforms_bulk(bulk=bulk_info)
    for event in cluster:
        t1 = event.origins[0].time
        t2 = t1 + 25
        design_set.append(st.copy().trim(t1, t2))
    # Construction of the detector will process the traces, then align them,
    # before multiplexing.
    detector = subspace.Detector()
    detector.construct(streams=design_set,
                       lowcut=2.0,
                       highcut=9.0,
                       filt_order=4,
                       sampling_rate=20,
                       multiplex=multiplex,
                       name='Wairarapa1',
                       align=True,
                       reject=0.2,
                       shift_len=6,
                       plot=plot).partition(9)
    if plot:
        detector.plot()
    # We also want the continuous stream to detect in.
    t1 = UTCDateTime(2016, 5, 11, 19)
    t2 = UTCDateTime(2016, 5, 11, 20)
    # We are going to look in a single hour just to minimize cost, but you can \
    # run for much longer.
    bulk_info = [('NZ', stachan[0], '*', stachan[1][0] + '?' + stachan[1][-1],
                  t1, t2) for stachan in detector.stachans]
    st = client.get_waveforms_bulk(bulk_info)
    st.merge().detrend('simple').trim(starttime=t1, endtime=t2)
    # We set a very low threshold because the detector is not that great, we
    # haven't aligned it particularly well - however, at this threshold we make
    # two real detections.
    detections, det_streams = detector.detect(st=st,
                                              threshold=0.005,
                                              trig_int=2,
                                              extract_detections=True)
    if return_streams:
        return detections, det_streams
    else:
        return detections
Пример #5
0
#template creation
#Works with GEONET

import sys
sys.path.insert(0, '/Users/home/taylorte/EQcorrscan')

from obspy import UTCDateTime
from obspy.clients.fdsn import Client
from eqcorrscan.core.template_gen import from_client
from eqcorrscan.tutorials.get_geonet_events import get_geonet_events
from eqcorrscan.utils.catalog_utils import filter_picks
from eqcorrscan.core import template_gen


catalog = get_geonet_events(
        startdate = UTCDateTime('2016-11-13T11:00:00'), 
        enddate = UTCDateTime('2016-11-14T11:00:00'), 
        maxlat = -42.0, minlat = -43.0, minlon = 173, maxlon = 174)

print catalog


filtered_catalog = filter_picks(catalog, stations=['WEL'], top_n_picks=2) 
print filtered_catalog

templates = from_client(
        catalog = filtered_catalog, client_id='GEONET', lowcut = 2.0, 
        highcut = 9.0, samp_rate = 20.0, filt_order = 4, length = 2.0, 
        prepick = 0.15, swin = 'all', process_len = 86400)
print templates

templates[0].plot()