示例#1
0
def get_monthyeardate_to_paths_map(file_prefix="pm", start_year=-np.Inf, end_year=np.Inf, samples_dir_path=None):

    if isinstance(samples_dir_path, str):
        samples_dir_path = Path(samples_dir_path)

    monthyear_to_pathlist = {}
    for monthdir in samples_dir_path.iterdir():

        y, m = commons.get_year_and_month(monthdir.name)

        if not (start_year <= y <= end_year):
            continue

        current_list = [str(p) for p in monthdir.iterdir() if p.name.startswith(file_prefix) and not p.name[-9:-1] == 8 * "0"]

        monthyear_to_pathlist[datetime(y, m, 1)] = current_list

    return monthyear_to_pathlist
示例#2
0
文件: nemo_hl_util.py 项目: guziy/RPN
def get_monthyeardate_to_paths_map(file_prefix="pm", start_year=-np.Inf, end_year=np.Inf, samples_dir_path=None):

    if isinstance(samples_dir_path, str):
        samples_dir_path = Path(samples_dir_path)

    monthyear_to_pathlist = {}
    for monthdir in samples_dir_path.iterdir():

        y, m = commons.get_year_and_month(monthdir.name)

        if not (start_year <= y <= end_year):
            continue

        current_list = [
            str(p) for p in monthdir.iterdir() if p.name.startswith(file_prefix) and not p.name[-9:-1] == 8 * "0"
        ]

        monthyear_to_pathlist[datetime(y, m, 1)] = current_list

    return monthyear_to_pathlist
示例#3
0
def get_seasonal_means_from_rpn_monthly_folders(samples_dir="", season_to_months=None, start_year=-np.Inf, end_year=np.Inf,
                                                filename_prefix="pm", varname="", level=-1, level_kind=-1):

    result = OrderedDict()

    season_to_files = {s: [] for s in season_to_months}

    smpls_dir = Path(samples_dir)


    for month_folder in smpls_dir.iterdir():


        y, m = get_year_and_month(month_folder.name)


        # skip if the year is not in the selected range
        if not start_year <= y <= end_year:
            continue

        for season, months in season_to_months.items():
            if m in months:

                for data_file in month_folder.iterdir():

                    if data_file.name[-9:-1] == 8 * "0":
                        continue

                    if data_file.name.startswith(filename_prefix):
                        season_to_files[season].append(str(data_file))



    for season, months in season_to_months.items():
        print("{} => {}".format(season, months))
        mrpn = MultiRPN(season_to_files[season])
        date_to_field = mrpn.get_all_time_records_for_name_and_level(varname=varname, level=level, level_kind=level_kind)
        result[season] = np.mean([field for field in date_to_field.values()], axis=0)

    return result