コード例 #1
0
def test_emsc_file():
    eventid = 'unknown'
    datadir = get_datadir()
    config = get_config()
    iparser = IntensityParser(eventid=eventid, config=config, network='emsc')

    # Test reading an emsc ZIP file
    testfile = os.path.join(datadir, '20190330_0000065.txt')
    df, msg = iparser.get_dyfi_dataframe_from_file(testfile)
    assert len(df) == 49
    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 151.2, decimal=1)
    np.testing.assert_equal(df['NRESP'].sum(), 227)
コード例 #2
0
def test_comcat_data():

    datadir = get_datadir()
    config = get_config()

    # test extraction from comcat event data. The VCR files are
    # example Comcat event datastreams.
    eventid = 'ci14607652'

    # This event has both geo_1km and geo_10km
    tape_file1 = os.path.join(datadir, 'vcr_comcat_geojson.yaml')

    iparser = IntensityParser(eventid=eventid, config=config, network='neic')

    with vcr.use_cassette(tape_file1):
        detail = get_event_by_id(eventid)

    df, msg = comcat.get_dyfi_dataframe_from_comcat(iparser, detail)
    df, msg = iparser.postprocess(df, 'neic')

    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 4510.1)

    reference = 'USGS Did You Feel It? System'
    tempdir = tempfile.mkdtemp(prefix='tmp.', dir=datadir)
    outfile = os.path.join(tempdir, 'dyfi_dat.xml')
    dataframe_to_xml(df, outfile, reference)

    # For debugging save the output with this line:
    # dataframe_to_xml(df, datadir + '/tmp.keepthis.xml', reference)

    outfilesize = os.path.getsize(outfile)
    # Longer size is for file with nresp field
    assert outfilesize == 183953 or outfilesize == 172852
    rmtree(tempdir)

    # This event has only text data
    eventid = 'ci14745580'
    tape_file2 = os.path.join(datadir, 'vcr_comcat_txt.yaml')

    with vcr.use_cassette(tape_file2):
        detail = get_event_by_id(eventid)
        df, msg = comcat.get_dyfi_dataframe_from_comcat(iparser, detail)
        df, msg = iparser.postprocess(df, 'neic')

    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 800.4)
コード例 #3
0
def test_emsc_zip():
    # Test output from EMSC testimonials feed

    eventid = 'nc72282711'
    extid = '20140824_0000036'
    datadir = get_datadir()
    config = get_config()

    tape_file1 = os.path.join(datadir, 'vcr_emsc_zip.yaml')

    iparser = IntensityParser(eventid=eventid, config=config, network='emsc')
    with vcr.use_cassette(tape_file1):
        df, msg = iparser.get_dyfi_dataframe_from_network(extid)

    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 221.7, decimal=1)
    np.testing.assert_equal(df['NRESP'].sum(), 426)

    return
コード例 #4
0
ファイル: ga_test.py プロジェクト: vinceq-usgs/getintensity
def test_ga():
    # Test output from GA feed

    eventid = 'us70004jxe'
    extid = 'ga2019nsodfc'
    datadir = get_datadir()
    config = get_config()
    config['directories']['data_path'] = datadir
    print('config.directories.data_path is now', datadir)

    tape_file1 = os.path.join(datadir, 'vcr_ga.yaml')

    iparser = IntensityParser(eventid=eventid, config=config, network='ga')
    with vcr.use_cassette(tape_file1):
        df, msg = iparser.get_dyfi_dataframe_from_network(extid)

    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 434.8, decimal=1)
    np.testing.assert_equal(df['NRESP'].sum(), 1174)

    return
コード例 #5
0
ファイル: ga_test.py プロジェクト: vinceq-usgs/getintensity
def test_ga_file():
    eventid = 'unknown'
    datadir = get_datadir()
    config = get_config()

    iparser = IntensityParser(eventid=eventid, config=config, network='ga')

    # Test reading a dyfi format file
    testfile = os.path.join(datadir, 'felt_reports_1km_filtered.geojson')
    df, msg = iparser.get_dyfi_dataframe_from_file(testfile)
    assert len(df) == 126
    np.testing.assert_almost_equal(df['INTENSITY'].sum(), 471.3)
    np.testing.assert_equal(df['NRESP'].sum(), 1316)

    # Test reading a dyfi format file
    testfile = os.path.join(datadir, 'felt_reports_10km_filtered.geojson')
    df, msg = iparser.get_dyfi_dataframe_from_file(testfile)
    assert len(df) == 62
    np.testing.assert_equal(df['INTENSITY'].sum(), 201.3)
    np.testing.assert_equal(df['NRESP'].sum(), 1525)

    return
コード例 #6
0
def test_comcat_file():
    eventid = 'nc72282711'
    datadir = get_datadir()
    config = get_config()
    iparser = IntensityParser(eventid=eventid, config=config, network='neic')

    # Test reading a comcat file
    testfile = os.path.join(datadir, 'nc72282711_dyfi_geo_10km.geojson')
    df, msg = iparser.get_dyfi_dataframe_from_file(testfile)

    assert len(df) == 203
    np.testing.assert_equal(df['INTENSITY'].sum(), 705.3)
    np.testing.assert_equal(df['NRESP'].sum(), 16202)

    # Test that stddev and resp carry throuh
    try:
        np.testing.assert_almost_equal(df['INTENSITY_STDDEV'].sum(), 39.548)

        reference = 'TEST'
        tempdir = tempfile.mkdtemp(prefix='tmp.', dir=datadir)
        outfile = os.path.join(tempdir, 'dyfi_dat.xml')

        # Make sure output file includes stddev
        dataframe_to_xml(df, outfile, reference)
        # To save this file for testing:
        # dataframe_to_xml(df, datadir + '/tmp.test_for_stddev.xml', reference)
        with open(outfile, 'r') as f:
            textdata = f.read()
            assert 'stddev' in textdata
            rmtree(tempdir)

    except AssertionError:
        msg = 'A newer version of impactutils is required to process \
intensity parameters. If you do not work with stddev, \
you can safely ignore this warning.'

        rmtree(tempdir)
        warnings.warn(msg)
コード例 #7
0
def test_emsc_retrieve():
    # Test output from EMSC name server

    eventid = 'nc72282711'
    extid = '20140824_0000036'
    datadir = get_datadir()
    config = get_config()

    tape_file1 = os.path.join(datadir, 'vcr_emsc_eventid.yaml')

    iparser = IntensityParser(eventid=eventid, config=config, network='emsc')
    with vcr.use_cassette(tape_file1):
        extid = emsc.get_extid_from_emsc(iparser, eventid)

    assert extid == '20140824_0000036'

    return