Exemplo n.º 1
0
def test_summary():
    datadir = get_datadir()
    tape_file = os.path.join(datadir, 'vcr_summary.yaml')
    with vcr.use_cassette(tape_file):
        eventlist = search(starttime=datetime(1994, 1, 17, 12, 30),
                           endtime=datetime(1994, 1, 18, 12, 35),
                           minmagnitude=6.6)
        event = eventlist[0]
        cmp = 'ci3144585 1994-01-17 12:30:55.390000 (34.213,-118.537) 18.2 km M6.7'
        assert str(event) == cmp
        assert event.id == 'ci3144585'
        assert event.time == datetime(1994, 1, 17, 12, 30, 55, 390000)
        assert event.latitude == 34.213
        assert event.longitude == -118.537
        assert event.depth == 18.202
        assert event.magnitude == 6.7
        assert 'cdi' in event.properties
        assert event['cdi'] == 8.6
        assert event.hasProduct('shakemap')
        assert not event.hasProduct('foo')
        try:
            event['foo']
            assert 1 == 2
        except AttributeError:
            pass
        assert event.hasProperty('cdi')
        assert not event.hasProperty('foo')
        assert isinstance(event.getDetailEvent(), DetailEvent)
        durl = 'https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=ci3144585&format=geojson'
        assert event.getDetailURL() == durl
        try:
            detail = event.getDetailEvent(includedeleted=True,
                                          includesuperseded=True)
            assert 1 == 2
        except RuntimeError:
            pass

        # find an event that has multiple versions of shakemap to test
        # include superseded
        # official20110311054624120_30
        eventlist = search(starttime=datetime(2011, 3, 11, 0, 0),
                           endtime=datetime(2011, 3, 12, 0, 0),
                           minmagnitude=8.8)
        honshu = eventlist[0]
        detail = honshu.getDetailEvent(includesuperseded=True)
        shakemaps = detail.getProducts('shakemap', version=VersionOption.ALL)
        assert shakemaps[1].source == 'atlas'
        assert event.toDict()['depth'] == 18.202
Exemplo n.º 2
0
def _query_comcat(start_time, end_time, min_magnitude=2.50,
                 min_latitude=31.50, max_latitude=43.00,
                 min_longitude=-125.40, max_longitude=-113.10, extra_comcat_params=None):
    """
    Return eventlist from ComCat web service.

    Args:
        start_time (datetime.datetime): start time of catalog query
        end_time (datetime.datetime): end time of catalog query
        min_magnitude (float): minimum magnitude of query
        min_latitude (float): minimum latitude of query
        max_latitude (float): maximum latitude of query
        min_longitude (float): minimum longitude of query
        max_longitude (float): maximum longitude of query
        extra_comcat_params (dict): additional parameters to pass to comcat search function

    Returns:
        eventlist
    """
    extra_comcat_params = extra_comcat_params or {}

    # get eventlist from Comcat
    eventlist = search(minmagnitude=min_magnitude,
        minlatitude=min_latitude, maxlatitude=max_latitude,
        minlongitude=min_longitude, maxlongitude=max_longitude,
        starttime=start_time, endtime=end_time, **extra_comcat_params)

    return eventlist
Exemplo n.º 3
0
def test_search():
    datadir = get_datadir()
    tape_file = os.path.join(datadir, 'vcr_search.yaml')
    with vcr.use_cassette(tape_file):
        eventlist = search(starttime=datetime(1994, 1, 17, 12, 30),
                           endtime=datetime(1994, 1, 18, 12, 35),
                           minmagnitude=6.6)
        event = eventlist[0]
        assert event.id == 'ci3144585'

        events = search(minmagnitude=9.0,
                        maxmagnitude=9.9,
                        starttime=datetime(2008, 1, 1),
                        endtime=datetime(2010, 2, 1),
                        updatedafter=datetime(2010, 1, 1))

        events = search(maxmagnitude=0.1,
                        starttime=datetime(2017, 1, 1),
                        endtime=datetime(2017, 1, 30))