예제 #1
0
def calculate_receiver_weights_interface(src_info,
                                         path_info,
                                         weighting_param,
                                         _verbose=True):
    """
    The user interface(API) for calculation the receiver weighting
    in pypaw

    :param src_info: keys contains ["latitude", "longitude"]
    :type src_info: dict
    :param path_info: keys contains ["station_file", "window_file",
        "output_file"]
    :type path_info: dict
    :param weighting_param: keys contains ["flag", "plot", "search_ratio"]
    :type weighting_param: dict
    """
    check_dict_keys(src_info, ["latitude", "longitude", "depth_in_m"])
    check_dict_keys(path_info, ["station_file", "window_file", "output_file"])
    check_dict_keys(weighting_param, ["flag", "plot", "search_ratio"])

    search_ratio = weighting_param["search_ratio"]
    plot_flag = weighting_param["plot"]
    weight_flag = weighting_param["flag"]
    # each file still contains 3-component
    if _verbose:
        print("src_info: %s" % src_info)
        print("path_info:")
        pprint(path_info)
        print("weighting param:")
        pprint(weighting_param)

    station_info = load_json(path_info["station_file"])
    window_info = load_json(path_info["window_file"])

    outputdir = os.path.dirname(path_info["output_file"])
    if not os.path.exists(outputdir):
        os.makedirs(outputdir)
    figname_prefix = os.path.join(outputdir, "weights")

    _results = determine_receiver_weighting(src_info,
                                            station_info,
                                            window_info,
                                            search_ratio=search_ratio,
                                            weight_flag=weight_flag,
                                            plot_flag=plot_flag,
                                            figname_prefix=figname_prefix)

    return _results
예제 #2
0
def test_stats_all_windows(tmpdir):
    windows = {"II.BBK": {"II.BBK..BHZ": [1, 2, 3, 4], "II.BBK..BHR": [],
                          "II.BBK..BHT": [1, 2, 3]},
               "II.AAK": {"II.AAK.10.BHZ": [1, 2, 3], "II.AAK.10.BHR": [1, 2],
                          "II.AAK.10.BHT": [1]},
               "II.CCK": {}}

    outputfile = os.path.join(str(tmpdir), "windows.log.json")
    wu.stats_all_windows(windows, "proc_obsd_17_40", "proc_synt_17_40",
                         True, outputfile)

    log = load_json(outputfile)
    _true = {
        "component": {
            "BHR": {
                "traces": 2, "traces_with_windows": 1, "windows": 2},
            "BHT": {
                "traces": 2, "traces_with_windows": 2, "windows": 4},
            "BHZ": {
                "traces": 2, "traces_with_windows": 2, "windows": 7}},
        "overall": {
            "stations": 3, "stations_with_windows": 2, "traces": 6,
            "traces_with_windows": 5, "windows": 13},
        "instrument_merge_flag": True,
        "obsd_tag": "proc_obsd_17_40",
        "synt_tag": "proc_synt_17_40"
    }
    assert log == _true
예제 #3
0
def calculate_receiver_weights_interface(
        src_info, path_info, weighting_param, _verbose=True):
    """
    The user interface(API) for calculation the receiver weighting
    in pypaw

    :param src_info: keys contains ["latitude", "longitude"]
    :type src_info: dict
    :param path_info: keys contains ["station_file", "window_file",
        "output_file"]
    :type path_info: dict
    :param weighting_param: keys contains ["flag", "plot", "search_ratio"]
    :type weighting_param: dict
    """
    check_dict_keys(src_info, ["latitude", "longitude", "depth_in_m"])
    check_dict_keys(path_info, ["station_file", "window_file", "output_file"])
    check_dict_keys(weighting_param, ["flag", "plot", "search_ratio"])

    search_ratio = weighting_param["search_ratio"]
    plot_flag = weighting_param["plot"]
    weight_flag = weighting_param["flag"]
    # each file still contains 3-component
    if _verbose:
        print("src_info: %s" % src_info)
        print("path_info:")
        pprint(path_info)
        print("weighting param:")
        pprint(weighting_param)

    station_info = load_json(path_info["station_file"])
    window_info = load_json(path_info["window_file"])

    outputdir = os.path.dirname(path_info["output_file"])
    if not os.path.exists(outputdir):
        os.makedirs(outputdir)
    figname_prefix = os.path.join(outputdir, "weights")

    _results = determine_receiver_weighting(
        src_info, station_info, window_info,
        search_ratio=search_ratio,
        weight_flag=weight_flag,
        plot_flag=plot_flag, figname_prefix=figname_prefix)

    return _results
def _upper_level(path, nlevel=4):
    """
    Go the nlevel dir up
    """
    for i in range(nlevel):
        path = os.path.dirname(path)
    return path


# Most generic way to get the data folder path.
TESTBASE_DIR = _upper_level(os.path.abspath(
    inspect.getfile(inspect.currentframe())), 4)
DATA_DIR = os.path.join(TESTBASE_DIR, "tests", "data")

measure_file = os.path.join(DATA_DIR, "window", "measurements.fake.json")
_measurements = load_json(measure_file)

station_file = os.path.join(DATA_DIR, "stations", "stations.fake.json")
_stations = load_json(station_file)


def test_extract_usable_stations_from_one_period():
    ms = deepcopy(_measurements)
    stations, channels = gas.extract_usable_stations_from_one_period(ms)
    assert set(stations) == set(["II.AAK", "II.ABKT", "IU.BCD"])
    assert set(channels) == set(["II.AAK..BHR", "II.AAK..BHT", "II.AAK..BHZ",
                                 "II.ABKT..BHR", "II.ABKT..BHZ",
                                 "IU.BCD..BHR", "IU.BCD..BHT", "IU.BCD..BHZ"])

    # add a fake station with no measurements
    ms["FK.FAKE"] = {}
예제 #5
0
def _upper_level(path, nlevel=4):
    """
    Go the nlevel dir up
    """
    for i in range(nlevel):
        path = os.path.dirname(path)
    return path


# Most generic way to get the data folder path.
TESTBASE_DIR = _upper_level(
    os.path.abspath(inspect.getfile(inspect.currentframe())), 4)
DATA_DIR = os.path.join(TESTBASE_DIR, "tests", "data")

WINDOWFILE = os.path.join(DATA_DIR, "window", "windows.fake.json")
windows = load_json(WINDOWFILE)
MEASUREFILE = os.path.join(DATA_DIR, "window", "measurements.fake.json")
measures = load_json(MEASUREFILE)
STATIONFILE = os.path.join(DATA_DIR, "stations", "stations.fake.json")
stations = load_json(STATIONFILE)


def test_is_right_sensor():
    pools = ["STS-1", "STS1", "KS54000"]

    assert fw.is_right_sensor("STS1", pools)
    assert fw.is_right_sensor("STS-1", pools)
    assert not fw.is_right_sensor("KS5400", pools)


def test_count_windows():
예제 #6
0
def _upper_level(path, nlevel=4):
    """
    Go the nlevel dir up
    """
    for i in range(nlevel):
        path = os.path.dirname(path)
    return path

# Most generic way to get the data folder path.
TESTBASE_DIR = _upper_level(
    os.path.abspath(inspect.getfile(inspect.currentframe())), 4)
DATA_DIR = os.path.join(TESTBASE_DIR, "tests", "data")

WINDOWFILE = os.path.join(DATA_DIR, "window", "windows.fake.json")
windows = load_json(WINDOWFILE)
MEASUREFILE = os.path.join(DATA_DIR, "window", "measurements.fake.json")
measures = load_json(MEASUREFILE)
STATIONFILE = os.path.join(DATA_DIR, "stations", "stations.fake.json")
stations = load_json(STATIONFILE)


def test_is_right_sensor():
    pools = ["STS-1", "STS1", "KS54000"]

    assert fw.is_right_sensor("STS1", pools)
    assert fw.is_right_sensor("STS-1", pools)
    assert not fw.is_right_sensor("KS5400", pools)


def test_count_windows():