def calculate_category_weights_interface(category_param, cat_wcounts): """ User interface(API) for calculating category weights Calculate the category weighting based on window counts in each category. The weighting ratios for different categoies are input parameters. So this function only normlizes the weights without change the ratio. !!! WARNING !!! It is the ratio between different categories, not the window counts. For example, the value will be mostly likely to be set to 1/N_w(for windows, less weights to balance categories) :param weight_param: user parameter, which contains the weighting ratio for each category. :type weight_param: dict :param cat_wcounts: category window counts, which should contains the same period band as category_param['ratio'] :type cat_wcounts: dict """ check_dict_keys(category_param, ["flag", "ratio"]) check_category_ratio_consistency(category_param["ratio"], cat_wcounts) weights = normalize_category_weights(category_param["ratio"], cat_wcounts) _category_validator(weights, cat_wcounts) print("Final category weights:") pprint(weights) return weights
def calculate_category_weights_interface(category_param, cat_wcounts): """ User interface(API) for calculating category weights Calculate the category weighting based on window counts in each category. The weighting ratios for different categoies are input parameters. So this function only normlizes the weights without change the ratio. !!! WARNING !!! It is the ratio between different categories, not the window counts. For example, the value will be mostly likely to be set to 1/N_w(for windows, less weights to balance categories) :param weight_param: user parameter, which contains the weighting ratio for each category. :type weight_param: dict :param cat_wcounts: category window counts, which should contains the same period band as category_param['ratio'] :type cat_wcounts: dict """ check_dict_keys(category_param, ["flag", "ratio"]) check_category_ratio_consistency(category_param["ratio"], cat_wcounts) weights = normalize_category_weights( category_param["ratio"], cat_wcounts) _category_validator(weights, cat_wcounts) print("Final category weights:") pprint(weights) return weights
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 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