Пример #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_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)
Пример #3
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
Пример #4
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
Пример #5
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"])
Пример #6
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"])
Пример #7
0
def get_event_category_window_counts(path_info):
    cat_wcounts = {}
    print("Reading window files to get events cateogry window counts")
    t1 = time.time()

    for ev, evinfo in path_info.iteritems():
        cat_wcounts[ev] = {}
        for pb, pbinfo in evinfo["period_info"].iteritems():
            winfile = pbinfo["window_file"]
            windows = load_json(winfile)
            _, _wcounts = calculate_receiver_window_counts(windows)
            cat_wcounts[ev][pb] = _wcounts
    t2 = time.time()
    print("Category weighting I/O time: %.2f sec" % (t2 - t1))
    return cat_wcounts
Пример #8
0
def get_event_category_window_counts(path_info):
    cat_wcounts = {}
    print("Reading window files to get events cateogry window counts")
    t1 = time.time()

    for ev, evinfo in path_info.iteritems():
        cat_wcounts[ev] = {}
        for pb, pbinfo in evinfo["period_info"].iteritems():
            winfile = pbinfo["window_file"]
            windows = load_json(winfile)
            _, _wcounts = calculate_receiver_window_counts(windows)
            cat_wcounts[ev][pb] = _wcounts
    t2 = time.time()
    print("Category weighting I/O time: %.2f sec" % (t2 - t1))
    return cat_wcounts
Пример #9
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)
Пример #10
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)
Пример #11
0
def test_normalize_receiver_weights():
    rec_counts, cat_wcounts = ww.calculate_receiver_window_counts(windows)

    comp = "BHZ"
    channels = list(rec_counts[comp].keys())
    channels.sort()
    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)
Пример #12
0
def test_normalize_receiver_weights():
    rec_counts, cat_wcounts = ww.calculate_receiver_window_counts(windows)

    comp = "BHZ"
    channels = rec_counts[comp].keys()
    channels.sort()
    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.itervalues():
        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)