예제 #1
0
def test_assign_receiver_points():
    rec_counts, _ = ww.calculate_receiver_window_counts(windows)

    def _assert(_points):
        for p in _points:
            if p.tag == "II.AAK..BHZ":
                npt.assert_almost_equal(p.latitude, 0.0)
                npt.assert_almost_equal(p.longitude, 0.0)
            elif p.tag == "II.ABKT..BHZ":
                npt.assert_almost_equal(p.latitude, 0.0)
                npt.assert_almost_equal(p.longitude, 120.0)
            elif p.tag == "IU.BCD..BHZ":
                npt.assert_almost_equal(p.latitude, 0.0)
                npt.assert_almost_equal(p.longitude, -120.0)

    points = ww.assign_receiver_to_points(rec_counts["BHZ"], stations)
    assert len(points) == 3
    _assert(points)

    points = ww.assign_receiver_to_points(rec_counts["BHR"], stations)
    assert len(points) == 3
    _assert(points)

    points = ww.assign_receiver_to_points(rec_counts["BHT"], stations)
    assert len(points) == 2
    _assert(points)
예제 #2
0
def test_calculate_receiver_window_counts():
    rec_counts, cat_wcounts = ww.calculate_receiver_window_counts(windows)

    _true = {"BHZ": {"II.AAK..BHZ": 3, "II.ABKT..BHZ": 2, "IU.BCD..BHZ": 5},
             "BHR": {"II.AAK..BHR": 2, "II.ABKT..BHR": 1, "IU.BCD..BHR": 2},
             "BHT": {"II.AAK..BHT": 1, "IU.BCD..BHT": 2}}
    assert rec_counts == _true

    _true = {"BHZ": 10, "BHR": 5, "BHT": 3}
    assert cat_wcounts == _true
예제 #3
0
def test_receiver_validator():
    src = {"latitude": 0.0, "longitude": 0.0}
    results = ww.determine_receiver_weighting(
        src, stations, windows, search_ratio=0.35, weight_flag=True,
        plot_flag=False)

    weights = results["rec_weights"]

    weights["BHZ"]["II.AAK..BHZ"] *= 2
    rec_counts, cat_wcounts = ww.calculate_receiver_window_counts(windows)
    with pytest.raises(ValueError):
        ww._receiver_validator(weights["BHZ"], rec_counts["BHZ"],
                               cat_wcounts["BHZ"])
예제 #4
0
def test_get_receiver_weights():
    center = SpherePoint(0, 0, tag="source")

    rec_counts, _ = ww.calculate_receiver_window_counts(windows)

    points = ww.assign_receiver_to_points(rec_counts["BHZ"], stations)
    ref_distance, cond_number = ww.get_receiver_weights(
        "BHZ", center, points, 0.35, plot=False)
    for p in points:
        npt.assert_almost_equal(p.weight, 1.0)
    npt.assert_almost_equal(cond_number, 1.0)

    points = ww.assign_receiver_to_points(rec_counts["BHT"], stations)
    ref_distance, cond_number = ww.get_receiver_weights(
        "BHZ", center, points, 0.35, plot=False)
    for p in points:
        npt.assert_almost_equal(p.weight, 1.0)
    npt.assert_almost_equal(cond_number, 1.0)
예제 #5
0
def test_normalize_receiver_weights():
    rec_counts, cat_wcounts = ww.calculate_receiver_window_counts(windows)

    comp = "BHZ"
    channels = rec_counts[comp].keys()
    channels = sorted(channels)
    points = ww.assign_receiver_to_points(channels, stations)
    weights = ww.normalize_receiver_weights(points, rec_counts[comp])
    assert len(weights) == 3
    for v in weights.values():
        npt.assert_almost_equal(v, 1.0)

    points[0].weight = 0.5
    points[1].weight = 0.75
    points[2].weight = 1.0
    weights = ww.normalize_receiver_weights(points, rec_counts[comp])
    assert len(weights) == 3
    npt.assert_almost_equal(weights["II.AAK..BHZ"], 0.625)
    npt.assert_almost_equal(weights["II.ABKT..BHZ"], 0.9375)
    npt.assert_almost_equal(weights["IU.BCD..BHZ"], 1.25)