Пример #1
0
def _get_geonet_pubids(publicids):
    """
    Get GeoNet events while they haven't included get_events in fdsn.

    :type publicids: list
    :param publicids: List of public id numbers for events wanted.

    :returns: Catalog of events
    :rtype: obspy.core.event.Catalog
    """
    import obspy
    if int(obspy.__version__.split('.')[0]) > 0:
        from obspy.clients.fdsn import Client
        from obspy import read_events
    else:
        from obspy.fdsn import Client
        from obspy import readEvents as read_events
    from obspy.core.event import Catalog

    client = Client('GEONET')
    catalog = Catalog()
    for publicid in publicids:
        data_stream = client._download('http://quakeml.geonet.org.nz/' +
                                       'quakeml/1.2/' + publicid)
        data_stream.seek(0, 0)
        catalog += read_events(data_stream, format="quakeml")
        data_stream.close()
    return catalog
Пример #2
0
 def test_download_various_methods(self):
     """
     Will download data from server and store in various databases,
     then create templates using the various methods.
     """
     client = Client('GEONET')
     # get the events
     catalog = Catalog()
     data_stream = client._download(
         'http://quakeml.geonet.org.nz/quakeml/1.2/2016p008194')
     data_stream.seek(0, 0)
     catalog += read_events(data_stream, format="quakeml")
     data_stream.close()
     # Select 3 channels to use and download
     sta_chans = [(pick.waveform_id.station_code,
                   pick.waveform_id.channel_code)
                  for pick in catalog[0].picks[0:3]]
     t1 = UTCDateTime(catalog[0].origins[0].time.date)
     t2 = t1 + 86400
     bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2)
             for sta_chan in sta_chans]
     continuous_st = client.get_waveforms_bulk(bulk)
     continuous_st.merge(fill_value=0)
     # Test multi_template_gen
     templates = multi_template_gen(catalog, continuous_st, length=3)
     self.assertEqual(len(templates), 1)
     # Test without an event
     templates = multi_template_gen(Catalog(), continuous_st, length=3)
     self.assertEqual(len(templates), 0)
Пример #3
0
    def test_download_various_methods(self):
        """Will download data from server and store in various databases,
        then create templates using the various methods."""
        import obspy
        if int(obspy.__version__.split('.')[0]) >= 1:
            from obspy.clients.fdsn import Client
            from obspy import read_events
        else:
            from obspy.fdsn import Client
            from obspy import readEvents as read_events
        from obspy.core.event import Catalog
        from obspy import UTCDateTime
        from eqcorrscan.utils.sfile_util import eventtosfile
        import os
        import shutil

        client = Client('GEONET')
        # get the events
        catalog = Catalog()
        data_stream = client._download('http://quakeml.geonet.org.nz/' +
                                           'quakeml/1.2/2016p008194')
        data_stream.seek(0, 0)
        catalog += read_events(data_stream, format="quakeml")
        data_stream.close()
        # Select 3 channels to use and download
        sta_chans = [(pick.waveform_id.station_code,
                      pick.waveform_id.channel_code)
                     for pick in catalog[0].picks[0:3]]
        t1 = UTCDateTime(catalog[0].origins[0].time.date)
        t2 = t1 + 86400
        bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2)
                for sta_chan in sta_chans]
        continuous_st = client.get_waveforms_bulk(bulk)
        continuous_st.merge(fill_value=0)
        # Test multi_template_gen
        templates = multi_template_gen(catalog, continuous_st, length=3)
        self.assertEqual(len(templates), 1)
        # Test without an event
        templates = multi_template_gen(Catalog(), continuous_st, length=3)
        self.assertEqual(len(templates), 0)
        # Test from contbase method
        sfile = eventtosfile(catalog[0], 'TEST', 'L', '.', 'None',
                             overwrite=True)
        os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y'))
        os.makedirs(catalog[0].origins[0].time.date.
                    strftime('Y%Y' + os.sep + 'R%j.01'))
        for tr in continuous_st:
            tr.write(catalog[0].origins[0].time.date.
                     strftime('Y%Y' + os.sep + 'R%j.01') + os.sep +
                     tr.stats.station + '.' + tr.stats.network + '.' +
                     tr.stats.location + '.' + tr.stats.channel +
                     tr.stats.starttime.strftime('%Y.%j'), format='MSEED')
        template = from_contbase(sfile,
                                 contbase_list=[('.', 'Yyyyy/Rjjj.01', 'NZ')],
                                 lowcut=1.0, highcut=5.0, samp_rate=20,
                                 filt_order=4, length=3, prepick=0.5,
                                 swin='all')
        shutil.rmtree(continuous_st[0].stats.starttime.strftime('Y%Y'))
Пример #4
0
    def test_download_various_methods(self):
        """Will download data from server and store in various databases,
        then create templates using the various methods."""
        import obspy
        if int(obspy.__version__.split('.')[0]) >= 1:
            from obspy.clients.fdsn import Client
            from obspy import read_events
        else:
            from obspy.fdsn import Client
            from obspy import readEvents as read_events
        from obspy.core.event import Catalog
        from obspy import UTCDateTime
        from eqcorrscan.utils.sfile_util import eventtosfile
        import os
        import shutil

        client = Client('GEONET')
        # get the events
        catalog = Catalog()
        data_stream = client._download('http://quakeml.geonet.org.nz/' +
                                           'quakeml/1.2/2016p008194')
        data_stream.seek(0, 0)
        catalog += read_events(data_stream, format="quakeml")
        data_stream.close()
        # Select 3 channels to use and download
        sta_chans = [(pick.waveform_id.station_code,
                      pick.waveform_id.channel_code)
                     for pick in catalog[0].picks[0:3]]
        t1 = UTCDateTime(catalog[0].origins[0].time.date)
        t2 = t1 + 86400
        bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2)
                for sta_chan in sta_chans]
        continuous_st = client.get_waveforms_bulk(bulk)
        continuous_st.merge(fill_value=0)
        # Test multi_template_gen
        templates = multi_template_gen(catalog, continuous_st, length=3)
        self.assertEqual(len(templates), 1)
        # Test without an event
        templates = multi_template_gen(Catalog(), continuous_st, length=3)
        self.assertEqual(len(templates), 0)
        # Test from contbase method
        sfile = eventtosfile(catalog[0], 'TEST', 'L', '.', 'None',
                             overwrite=True)
        os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y'))
        os.makedirs(catalog[0].origins[0].time.date.
                    strftime('Y%Y' + os.sep + 'R%j.01'))
        for tr in continuous_st:
            tr.write(catalog[0].origins[0].time.date.
                     strftime('Y%Y' + os.sep + 'R%j.01') + os.sep +
                     tr.stats.station + '.' + tr.stats.network + '.' +
                     tr.stats.location + '.' + tr.stats.channel +
                     tr.stats.starttime.strftime('%Y.%j'), format='MSEED')
        template = from_contbase(sfile,
                                 contbase_list=[('.', 'Yyyyy/Rjjj.01', 'NZ')],
                                 lowcut=1.0, highcut=5.0, samp_rate=20,
                                 filt_order=4, length=3, prepick=0.5,
                                 swin='all')
        shutil.rmtree(continuous_st[0].stats.starttime.strftime('Y%Y'))
Пример #5
0
def mktemplates(network_code='GEONET',
                publicIDs=['2016p008122', '2016p008353', '2016p008155',
                           '2016p008194'], plot=True):
    """Functional wrapper to make templates"""
    # We want to download some QuakeML files from the New Zealand GeoNet
    # network, GeoNet currently doesn't support FDSN event queries, so we
    # have to work around to download quakeml from their quakeml.geonet site.

    client = Client(network_code)
    # We want to download a few events from an earthquake sequence, these are
    # identified by publiID numbers, given as arguments

    catalog = Catalog()
    for publicID in publicIDs:
        if network_code == 'GEONET':
            data_stream = client._download(
                'http://quakeml.geonet.org.nz/quakeml/1.2/' + publicID)
            data_stream.seek(0, 0)
            catalog += read_events(data_stream, format="quakeml")
            data_stream.close()
        else:
            catalog += client.get_events(
                eventid=publicID, includearrivals=True)

    # Lets plot the catalog to see what we have
    if plot:
        catalog.plot(projection='local', resolution='h')

    # We don't need all the picks, lets take the information from the
    # five most used stations - note that this is done to reduce computational
    # costs.
    catalog = filter_picks(catalog, top_n_picks=5)
    # We only want the P picks in this example, but you can use others or all
    #  picks if you want.
    for event in catalog:
        for pick in event.picks:
            if pick.phase_hint == 'S':
                event.picks.remove(pick)

    # Now we can generate the templates
    templates = template_gen.template_gen(
        method='from_client', catalog=catalog, client_id=network_code,
        lowcut=2.0, highcut=9.0, samp_rate=20.0, filt_order=4, length=3.0,
        prepick=0.15, swin='all', process_len=3600, debug=0, plot=plot)

    # We now have a series of templates! Using Obspy's Stream.write() method we
    # can save these to disk for later use.  We will do that now for use in the
    # following tutorials.
    for i, template in enumerate(templates):
        template.write('tutorial_template_' + str(i) + '.ms', format='MSEED')
        # Note that this will warn you about data types.  As we don't care
        # at the moment, whatever obspy chooses is fine.
    return
Пример #6
0
def mktemplates(network_code='GEONET',
                publicIDs=['2016p008122', '2016p008353', '2016p008155',
                           '2016p008194']):
    """Functional wrapper to make templates"""

    from collections import Counter
    from eqcorrscan.core import template_gen

    # This import section copes with namespace changes between obspy versions
    import obspy
    if int(obspy.__version__.split('.')[0]) >= 1:
        from obspy.clients.fdsn import Client
        from obspy import read_events
    else:
        from obspy.fdsn import Client
        from obspy import readEvents as read_events
    from obspy.core.event import Catalog

    # We want to download some QuakeML files from the New Zealand GeoNet
    # network, GeoNet currently doesn't support FDSN event queries, so we
    # have to work around to download quakeml from their quakeml.geonet site.

    client = Client(network_code)
    # We want to download a few events from an earthquake sequence, these are
    # identified by publiID numbers, given as arguments

    catalog = Catalog()
    for publicID in publicIDs:
        if network_code == 'GEONET':
            data_stream = client._download('http://quakeml.geonet.org.nz/' +
                                           'quakeml/1.2/' + publicID)
            data_stream.seek(0, 0)
            catalog += read_events(data_stream, format="quakeml")
            data_stream.close()
        else:
            catalog += client.get_events(eventid=publicID,
                                         includearrivals=True)

    # Lets plot the catalog to see what we have
    catalog.plot(projection='local', resolution='h')

    # We don't need all the picks, lets take the information from the
    # five most used stations
    all_picks = []
    for event in catalog:
        all_picks += [(pick.waveform_id.station_code) for pick in event.picks]
    all_picks = Counter(all_picks).most_common(5)
    all_picks = [pick[0] for pick in all_picks]

    for event in catalog:
        if len(event.picks) == 0:
            raise IOError('No picks found')
        event.picks = [pick for pick in event.picks
                       if pick.waveform_id.station_code in all_picks]

    # Now we can generate the templates
    templates = template_gen.from_client(catalog=catalog,
                                         client_id=network_code,
                                         lowcut=2.0, highcut=9.0,
                                         samp_rate=20.0, filt_order=4,
                                         length=3.0, prepick=0.15,
                                         swin='all', debug=1, plot=True)

    # We now have a series of templates! Using Obspys Stream.write() method we
    # can save these to disk for later use.  We will do that now for use in the
    # following tutorials.
    for i, template in enumerate(templates):
        template.write('tutorial_template_' + str(i) + '.ms', format='MSEED')
        # Note that this will warn you about data types.  As we don't care
        # at the moment, whatever obspy chooses is fine.
    return
Пример #7
0
def mktemplates(network_code='GEONET',
                publicIDs=['2016p008122', '2016p008353', '2016p008155',
                           '2016p008194']):
    """Functional wrapper to make templates"""

    from collections import Counter
    from eqcorrscan.core import template_gen

    # This import section copes with namespace changes between obspy versions
    import obspy
    if int(obspy.__version__.split('.')[0]) >= 1:
        from obspy.clients.fdsn import Client
        from obspy import read_events
    else:
        from obspy.fdsn import Client
        from obspy import readEvents as read_events
    from obspy.core.event import Catalog

    # We want to download some QuakeML files from the New Zealand GeoNet
    # network, GeoNet currently doesn't support FDSN event queries, so we
    # have to work around to download quakeml from their quakeml.geonet site.

    client = Client(network_code)
    # We want to download a few events from an earthquake sequence, these are
    # identified by publiID numbers, given as arguments

    catalog = Catalog()
    for publicID in publicIDs:
        if network_code == 'GEONET':
            data_stream = client._download('http://quakeml.geonet.org.nz/' +
                                           'quakeml/1.2/' + publicID)
            data_stream.seek(0, 0)
            catalog += read_events(data_stream, format="quakeml")
            data_stream.close()
        else:
            catalog += client.get_events(eventid=publicID,
                                         includearrivals=True)

    # Lets plot the catalog to see what we have
    catalog.plot(projection='local', resolution='h')

    # We don't need all the picks, lets take the information from the
    # five most used stations
    all_picks = []
    for event in catalog:
        all_picks += [(pick.waveform_id.station_code,
                       pick.waveform_id.channel_code) for pick in event.picks]
    all_picks = Counter(all_picks).most_common(5)
    all_picks = [pick[0] for pick in all_picks]

    for event in catalog:
        if len(event.picks) == 0:
            raise IOError('No picks found')
        event.picks = [pick for pick in event.picks
                       if (pick.waveform_id.station_code,
                           pick.waveform_id.channel_code) in all_picks]

    # Now we can generate the templates
    templates = template_gen.from_client(catalog=catalog,
                                         client_id=network_code,
                                         lowcut=2.0, highcut=9.0,
                                         samp_rate=20.0, filt_order=4,
                                         length=3.0, prepick=0.05,
                                         swin='all', debug=1, plot=True)

    # We now have a series of templates! Using Obspys Stream.write() method we
    # can save these to disk for later use.  We will do that now for use in the
    # following tutorials.
    for i, template in enumerate(templates):
        template.write('tutorial_template_' + str(i) + '.ms', format='MSEED')
        # Note that this will warn you about data types.  As we don't care
        # at the moment, whatever obspy chooses is fine.
    return