def _test_trim_multiple_events():
    datapath = os.path.join("data", "testdata", "multiple_events")
    datadir = pkg_resources.resource_filename("gmprocess", datapath)
    sc = StreamCollection.from_directory(os.path.join(datadir, "ci38457511"))
    origin = get_event_object("ci38457511")
    df, catalog = create_travel_time_dataframe(
        sc, os.path.join(datadir, "catalog.csv"), 5, 0.1, "iasp91"
    )
    for st in sc:
        st.detrend("demean")
        remove_response(st, None, None)
        st = corner_frequencies.from_constant(st)
        lowpass_filter(st)
        highpass_filter(st)
        signal_split(st, origin)
        signal_end(
            st,
            origin.time,
            origin.longitude,
            origin.latitude,
            origin.magnitude,
            method="model",
            model="AS16",
        )
        cut(st, 2)
        trim_multiple_events(
            st, origin, catalog, df, 0.2, 0.7, "B14", {"vs30": 760}, {"rake": 0}
        )

    num_failures = sum([1 if not st.passed else 0 for st in sc])
    assert num_failures == 2

    failure = sc.select(station="WRV2")[0][0].getParameter("failure")
    assert failure["module"] == "trim_multiple_events"
    assert failure["reason"] == (
        "A significant arrival from another event "
        "occurs within the first 70.0 percent of the "
        "signal window"
    )

    for tr in sc.select(station="JRC2")[0]:
        np.testing.assert_almost_equal(
            tr.stats.endtime, UTCDateTime("2019-07-06T03:20:56.368300Z")
        )
Esempio n. 2
0
def test_trim_multiple_events():
    datapath = os.path.join('data', 'testdata', 'multiple_events')
    datadir = pkg_resources.resource_filename('gmprocess', datapath)
    sc = StreamCollection.from_directory(os.path.join(datadir, 'ci38457511'))
    origin = get_event_object('ci38457511')
    df, catalog = create_travel_time_dataframe(
        sc, os.path.join(datadir, 'catalog.csv'), 5, 0.1, 'iasp91')
    for st in sc:
        st.detrend('demean')
        remove_response(st, None, None)
        st = corner_frequencies.get_constant(st)
        lowpass_filter(st)
        highpass_filter(st)
        signal_split(st, origin)
        signal_end(st,
                   origin.time,
                   origin.longitude,
                   origin.latitude,
                   origin.magnitude,
                   method='model',
                   model='AS16')
        cut(st, 2)
        trim_multiple_events(st, origin, catalog, df, 0.2, 0.7, 'B14',
                             {'vs30': 760}, {'rake': 0})

    num_failures = sum([1 if not st.passed else 0 for st in sc])
    assert num_failures == 1

    failure = sc.select(station='WRV2')[0][0].getParameter('failure')
    assert failure['module'] == 'trim_multiple_events'
    assert failure['reason'] == ('A significant arrival from another event '
                                 'occurs within the first 70.0 percent of the '
                                 'signal window')

    for tr in sc.select(station='JRC2')[0]:
        np.testing.assert_almost_equal(
            tr.stats.endtime, UTCDateTime('2019-07-06T03:20:38.7983Z'))
Esempio n. 3
0
def test_v0():
    datafiles, origin = read_data_dir("cosmos", "ftbragg")
    dfile = datafiles[0]
    # TODO: Fix this problem, or get the data fixed?
    assert is_cosmos(dfile)
    try:
        rstreams = read_cosmos(dfile)
        tstream = rstreams[0].copy()  # raw stream
        streams = StreamCollection(rstreams)
        pstream = remove_response(rstreams[0], 0, 0)
        pstream.detrend(type="demean")

        for trace in tstream:
            trace.data /= trace.stats.standard.instrument_sensitivity
            trace.data *= 100
        tstream.detrend(type="demean")

        np.testing.assert_almost_equal(tstream[0].data, pstream[0].data)
    except Exception as e:
        pass