示例#1
0
def test_detail():
    eventid = 'ci3144585'  #northridge
    url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/%s.geojson' % eventid
    event = DetailEvent(url)
    assert str(
        event
    ) == 'ci3144585 1994-01-17 12:30:55.390000 (34.213,-118.537) 18.2 km M6.7'
    assert event.hasProduct('shakemap')
    assert event.hasProduct('foo') == False
    assert event.hasProperty('foo') == False
    assert event.hasProperty('time')
    try:
        event['foo']
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getNumVersions('foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getProducts('foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getProducts('shakemap', source='foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    assert event.toDict()['magnitude'] == 6.7

    eventid = 'nc72282711'  #Napa 2014 eq, multiple origins and MTs.
    # cievent = get_event_by_id(eventid,catalog='ci')
    # usevent = get_event_by_id(eventid,catalog='us')
    # atevent = get_event_by_id(eventid,catalog='at')
    event = get_event_by_id(eventid)

    phases = event.getProducts('phase-data', source='all')

    ncdict = event.toDict(catalog='nc')
    usdict = event.toDict(catalog='us')
    atdict = event.toDict(catalog='at')

    try:
        event.toDict(catalog='foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    assert ncdict['depth'] == 11.12
    assert usdict['depth'] == 11.25
    assert atdict['depth'] == 9.0

    ncdict_allmags = event.toDict(get_all_magnitudes=True)
    assert ncdict_allmags['magtype3'] == 'Ml'

    ncdict_alltensors = event.toDict(get_tensors='all')
    assert ncdict_alltensors['us_Mwb_mrr'] == 7.63e+16
    ncdict_allfocals = event.toDict(get_focals='all')
    assert ncdict_allfocals['nc_np1_strike'] == '345.0'

    assert event.getNumVersions('shakemap') > 0
    assert isinstance(event.getProducts('shakemap')[0], Product)
    assert event.latitude == 38.2151667
    assert event.longitude == -122.3123333
    assert event.depth == 11.12
    assert event.id == eventid
    assert event.time == datetime(2014, 8, 24, 10, 20, 44, 70000)
    assert 'sources' in event.properties
    assert event['mag'] == 6.02

    #test all of the different functionality of the getProducts() method
    #first, test default behavior (get the most preferred product):
    event = get_event_by_id('nc21323712',
                            includesuperseded=True)  #2003 Central California
    pref_shakemap = event.getProducts('shakemap')[0]
    assert pref_shakemap.source == 'atlas'
    assert pref_shakemap.update_time >= datetime(2017, 4, 12, 10, 50, 9,
                                                 368000)
    assert pref_shakemap.preferred_weight >= 100000000

    #get the first Atlas shakemap
    first_shakemap = event.getProducts('shakemap',
                                       version=VersionOption.FIRST,
                                       source='atlas')[0]
    assert first_shakemap.source == 'atlas'
    assert first_shakemap.update_time >= datetime(2015, 2, 4, 6, 1, 33, 400000)
    assert first_shakemap.preferred_weight >= 81

    #get the first nc shakemap
    first_shakemap = event.getProducts('shakemap',
                                       version=VersionOption.FIRST,
                                       source='nc')[0]
    assert first_shakemap.source == 'nc'
    assert first_shakemap.update_time >= datetime(2017, 3, 8, 20, 12, 59,
                                                  380000)
    assert first_shakemap.preferred_weight >= 231

    #get the last version of the nc shakemaps
    last_shakemap = event.getProducts('shakemap',
                                      version=VersionOption.LAST,
                                      source='nc')[0]
    assert last_shakemap.source == 'nc'
    assert last_shakemap.update_time >= datetime(2017, 3, 17, 17, 40, 26,
                                                 576000)
    assert last_shakemap.preferred_weight >= 231

    #get all the nc versions of the shakemap
    shakemaps = event.getProducts('shakemap',
                                  version=VersionOption.ALL,
                                  source='nc')
    for shakemap4 in shakemaps:
        assert shakemap4.source == 'nc'

    #get all versions of all shakemaps
    shakemaps = event.getProducts('shakemap',
                                  version=VersionOption.ALL,
                                  source='all')
    assert event.getNumVersions('shakemap') == len(shakemaps)
示例#2
0
def test_detail():
    cassettes, datadir = get_datadir()
    tape_file = os.path.join(cassettes, 'classes_detailevent.yaml')
    with vcr.use_cassette(tape_file):
        eventid = 'ci3144585'  # northridge
        fmt = ('https://earthquake.usgs.gov/earthquakes/feed/v1.0/'
               'detail/%s.geojson')
        url = fmt % eventid
        event = DetailEvent(url)
        assert str(event) == ('ci3144585 1994-01-17 12:30:55.390000 '
                              '(34.213,-118.537) 18.2 km M6.7')
        assert event.hasProduct('shakemap')
        assert event.hasProduct('foo') is False
        assert event.hasProperty('foo') is False
        assert event.hasProperty('time')
        try:
            event['foo']
            assert 1 == 2
        except AttributeError:
            pass

        try:
            event.getNumVersions('foo')
            assert 1 == 2
        except ProductNotFoundError:
            pass

        try:
            event.getProducts('foo')
            assert 1 == 2
        except ProductNotFoundError:
            pass

        try:
            event.getProducts('shakemap', source='foo')
            assert 1 == 2
        except ProductNotFoundError:
            pass

        assert event.toDict()['magnitude'] == 6.7

        eventid = 'nc72282711'  # Napa 2014 eq, multiple origins and MTs.
        # cievent = get_event_by_id(eventid,catalog='ci')
        # usevent = get_event_by_id(eventid,catalog='us')
        # atevent = get_event_by_id(eventid,catalog='at')
        event = get_event_by_id(eventid)

        # smoke test
        _ = event.getProducts('phase-data', source='all')

        ncdict = event.toDict(catalog='nc')
        usdict = event.toDict(catalog='us')
        atdict = event.toDict(catalog='at')

        try:
            event.toDict(catalog='foo')
            assert 1 == 2
        except ProductNotFoundError:
            pass

        assert ncdict['depth'] == 11.12
        assert usdict['depth'] == 11.25
        assert atdict['depth'] == 9.0

        ncdict_allmags = event.toDict(get_all_magnitudes=True)
        allmags = []
        for key, value in ncdict_allmags.items():
            if key.startswith('magtype'):
                allmags.append(value)
        cmpmags = [
            'Md', 'Ml', 'Ms_20', 'Mw', 'Mwb', 'Mwc', 'Mwr', 'Mww', 'mb', 'mw'
        ]
        assert sorted(allmags) == sorted(cmpmags)

        ncdict_alltensors = event.toDict(get_tensors='all')
        assert ncdict_alltensors['us_Mwb_mrr'] == 7.63e+16
        ncdict_allfocals = event.toDict(get_focals='all')
        assert ncdict_allfocals['nc_np1_strike'] == 345.0

        assert event.getNumVersions('shakemap') > 0
        assert isinstance(event.getProducts('shakemap')[0], Product)
        assert event.latitude == 38.2151667
        assert event.longitude == -122.3123333
        assert event.depth == 11.12
        assert event.id == eventid
        assert event.time == datetime(2014, 8, 24, 10, 20, 44, 70000)
        assert 'sources' in event.properties
        assert event['mag'] == 6.02

        # test all of the different functionality of the getProducts() method
        # first, test default behavior (get the most preferred product):
        # 2003 Central California
        event = get_event_by_id('nc21323712', includesuperseded=True)
        pref_shakemap = event.getProducts('shakemap')[0]
        assert pref_shakemap.source == 'atlas'
        assert pref_shakemap.update_time >= datetime(2017, 4, 12, 10, 50, 9,
                                                     368000)
        assert pref_shakemap.preferred_weight >= 100000000

        # get the first Atlas shakemap
        first_shakemap = event.getProducts('shakemap',
                                           version='first',
                                           source='atlas')[0]
        assert first_shakemap.source == 'atlas'
        assert first_shakemap.update_time >= datetime(2015, 2, 4, 6, 1, 33,
                                                      400000)
        assert first_shakemap.preferred_weight >= 81

        # get the first nc shakemap
        first_shakemap = event.getProducts('shakemap',
                                           version='first',
                                           source='nc')[0]
        assert first_shakemap.source == 'nc'
        assert first_shakemap.update_time >= datetime(2017, 3, 8, 20, 12, 59,
                                                      380000)
        assert first_shakemap.preferred_weight >= 231

        # get the last version of the nc shakemaps
        last_shakemap = event.getProducts('shakemap',
                                          version='last',
                                          source='nc')[0]
        assert last_shakemap.source == 'nc'
        assert last_shakemap.update_time >= datetime(2017, 3, 17, 17, 40, 26,
                                                     576000)
        assert last_shakemap.preferred_weight >= 231

        # get all the nc versions of the shakemap
        shakemaps = event.getProducts('shakemap', version='all', source='nc')
        for shakemap4 in shakemaps:
            assert shakemap4.source == 'nc'

        # get all versions of all shakemaps
        shakemaps = event.getProducts('shakemap', version='all', source='all')
        assert event.getNumVersions('shakemap') == len(shakemaps)
示例#3
0
def test_detail():
    eventid = 'ci3144585' #northridge
    url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/%s.geojson' % eventid
    event = DetailEvent(url)
    assert str(event) == 'ci3144585 1994-01-17 12:30:55.390000 (34.213,-118.537) 18.2 km M6.7'
    assert event.hasProduct('shakemap')
    assert event.hasProduct('foo') == False
    assert event.hasProperty('foo') == False
    assert event.hasProperty('time')
    try:
        event['foo']
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getNumVersions('foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getProducts('foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    try:
        event.getProducts('shakemap',source='foo')
        assert 1 == 2
    except AttributeError as ae:
        pass
    
    assert event.toDict()['magnitude'] == 6.7

    eventid = 'nc72282711' #Napa 2014 eq, multiple origins and MTs.
    # cievent = get_event_by_id(eventid,catalog='ci')
    # usevent = get_event_by_id(eventid,catalog='us')
    # atevent = get_event_by_id(eventid,catalog='at')
    event = get_event_by_id(eventid)

    phases = event.getProducts('phase-data',source='all')
    
    ncdict = event.toDict(catalog='nc')
    usdict = event.toDict(catalog='us')
    atdict = event.toDict(catalog='at')

    try:
        event.toDict(catalog='foo')
        assert 1 == 2
    except AttributeError as ae:
        pass

    assert ncdict['depth'] == 11.12
    assert usdict['depth'] == 11.25
    assert atdict['depth'] == 9.0

    ncdict_allmags = event.toDict(get_all_magnitudes=True)
    assert ncdict_allmags['magtype3'] == 'Ml'

    ncdict_alltensors = event.toDict(get_tensors='all')
    assert ncdict_alltensors['us_Mwb_mrr'] == 7.63e+16
    ncdict_allfocals = event.toDict(get_focals='all')
    assert ncdict_allfocals['nc_np1_strike'] == '345.0'

    assert event.getNumVersions('shakemap') > 0
    assert isinstance(event.getProducts('shakemap')[0],Product)
    assert event.latitude == 38.2151667
    assert event.longitude == -122.3123333
    assert event.depth == 11.12
    assert event.id == eventid
    assert event.time == datetime(2014, 8, 24, 10, 20, 44, 70000)
    assert 'sources' in event.properties
    assert event['mag'] == 6.02

    #test all of the different functionality of the getProducts() method
    #first, test default behavior (get the most preferred product):
    event = get_event_by_id('nc21323712',includesuperseded=True) #2003 Central California
    pref_shakemap = event.getProducts('shakemap')[0]
    assert pref_shakemap.source == 'atlas'
    assert pref_shakemap.update_time >= datetime(2017, 4, 12, 10, 50, 9, 368000)
    assert pref_shakemap.preferred_weight >= 100000000

    #get the first Atlas shakemap
    first_shakemap = event.getProducts('shakemap',version=VersionOption.FIRST,source='atlas')[0]
    assert first_shakemap.source == 'atlas'
    assert first_shakemap.update_time >= datetime(2015, 2, 4, 6, 1, 33, 400000)
    assert first_shakemap.preferred_weight >= 81

    #get the first nc shakemap
    first_shakemap = event.getProducts('shakemap',version=VersionOption.FIRST,source='nc')[0]
    assert first_shakemap.source == 'nc'
    assert first_shakemap.update_time >= datetime(2017, 3, 8, 20, 12, 59, 380000)
    assert first_shakemap.preferred_weight >= 231
    
    #get the last version of the nc shakemaps
    last_shakemap = event.getProducts('shakemap',version=VersionOption.LAST,source='nc')[0]
    assert last_shakemap.source == 'nc'
    assert last_shakemap.update_time >= datetime(2017, 3, 17, 17, 40, 26, 576000)
    assert last_shakemap.preferred_weight >= 231

    #get all the nc versions of the shakemap
    shakemaps = event.getProducts('shakemap',version=VersionOption.ALL,source='nc')
    for shakemap4 in shakemaps:
        assert shakemap4.source == 'nc'

    #get all versions of all shakemaps
    shakemaps = event.getProducts('shakemap',version=VersionOption.ALL,source='all')
    assert event.getNumVersions('shakemap') == len(shakemaps)
示例#4
0
def test_detail():
    cassettes, datadir = get_datadir()
    tape_file = os.path.join(cassettes, "classes_detailevent.yaml")
    with vcr.use_cassette(tape_file):
        eventid = "ci3144585"  # northridge
        fmt = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/" "detail/%s.geojson"
        url = fmt % eventid
        event = DetailEvent(url)
        assert str(event) == ("ci3144585 1994-01-17 12:30:55.390000 "
                              "(34.213,-118.537) 18.2 km M6.7")
        assert event.hasProduct("shakemap")
        assert event.hasProduct("foo") is False
        assert event.hasProperty("foo") is False
        assert event.hasProperty("time")
        try:
            event["foo"]
            assert 1 == 2
        except AttributeError:
            pass

        try:
            event.getNumVersions("foo")
            assert 1 == 2
        except ProductNotFoundError:
            pass

        try:
            event.getProducts("foo")
            assert 1 == 2
        except ProductNotFoundError:
            pass

        try:
            event.getProducts("shakemap", source="foo")
            assert 1 == 2
        except ProductNotFoundError:
            pass

        assert event.toDict()["magnitude"] == 6.7

        eventid = "nc72282711"  # Napa 2014 eq, multiple origins and MTs.
        # cievent = get_event_by_id(eventid,catalog='ci')
        # usevent = get_event_by_id(eventid,catalog='us')
        # atevent = get_event_by_id(eventid,catalog='at')
        event = get_event_by_id(eventid)

        # smoke test
        _ = event.getProducts("phase-data", source="all")

        ncdict = event.toDict(catalog="nc")
        usdict = event.toDict(catalog="us")
        atdict = event.toDict(catalog="at")

        try:
            event.toDict(catalog="foo")
            assert 1 == 2
        except ProductNotFoundError:
            pass

        assert ncdict["depth"] == 11.12
        assert usdict["depth"] == 11.25
        assert atdict["depth"] == 9.0

        ncdict_allmags = event.toDict(get_all_magnitudes=True)
        allmags = []
        for key, value in ncdict_allmags.items():
            if key.startswith("magtype"):
                allmags.append(value)
        cmpmags = [
            "Md", "Ml", "Ms_20", "Mw", "Mwb", "Mwc", "Mwr", "Mww", "mb", "mw"
        ]
        assert sorted(allmags) == sorted(cmpmags)

        ncdict_alltensors = event.toDict(get_tensors="all")
        assert ncdict_alltensors["us_Mwb_mrr"] == 7.63e16
        ncdict_allfocals = event.toDict(get_focals="all")
        assert ncdict_allfocals["nc_np1_strike"] == 345.0

        assert event.getNumVersions("shakemap") > 0
        assert isinstance(event.getProducts("shakemap")[0], Product)
        assert event.latitude == 38.2151667
        assert event.longitude == -122.3123333
        assert event.depth == 11.12
        assert event.id == eventid
        assert event.time == datetime(2014, 8, 24, 10, 20, 44, 70000)
        assert "sources" in event.properties
        assert event["mag"] == 6.02

        # test all of the different functionality of the getProducts() method
        # first, test default behavior (get the most preferred product):
        # 2003 Central California
        event = get_event_by_id("nc21323712", includesuperseded=True)
        pref_shakemap = event.getProducts("shakemap")[0]
        assert pref_shakemap.source == "atlas"
        assert pref_shakemap.update_time >= datetime(2017, 4, 12, 10, 50, 9,
                                                     368000)
        assert pref_shakemap.preferred_weight >= 100000000

        # get the first Atlas shakemap
        first_shakemap = event.getProducts("shakemap",
                                           version="first",
                                           source="atlas")[0]
        assert first_shakemap.source == "atlas"
        assert first_shakemap.update_time >= datetime(2015, 2, 4, 6, 1, 33,
                                                      400000)
        assert first_shakemap.preferred_weight >= 81

        # get the first nc shakemap
        first_shakemap = event.getProducts("shakemap",
                                           version="first",
                                           source="nc")[0]
        assert first_shakemap.source == "nc"
        assert first_shakemap.update_time >= datetime(2017, 3, 8, 20, 12, 59,
                                                      380000)
        assert first_shakemap.preferred_weight >= 231

        # get the last version of the nc shakemaps
        last_shakemap = event.getProducts("shakemap",
                                          version="last",
                                          source="nc")[0]
        assert last_shakemap.source == "nc"
        assert last_shakemap.update_time >= datetime(2017, 3, 17, 17, 40, 26,
                                                     576000)
        assert last_shakemap.preferred_weight >= 231

        # get all the nc versions of the shakemap
        shakemaps = event.getProducts("shakemap", version="all", source="nc")
        for shakemap4 in shakemaps:
            assert shakemap4.source == "nc"

        # get all versions of all shakemaps
        shakemaps = event.getProducts("shakemap", version="all", source="all")
        assert event.getNumVersions("shakemap") == len(shakemaps)