Skip to content

Commit

Permalink
Merge pull request #1153 from PCMDI/bug/1152_piControl-multifile_lee1043
Browse files Browse the repository at this point in the history
Bug/1152 pi control multifile lee1043
  • Loading branch information
lee1043 authored Oct 2, 2024
2 parents 776634f + a813521 commit 388b3ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pcmdi_metrics/variability_mode/lib/lib_variability_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_domain_range(mode: str, regions_specs: dict):


def read_data_in(
path: str,
path: Union[str, list],
var_in_data: str,
var_to_consider: str,
syear: Union[str, int, float],
Expand Down
36 changes: 28 additions & 8 deletions pcmdi_metrics/variability_mode/variability_modes_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@
write_nc_output,
)


def search_paths(paths, index1, index2, case_sensitive=False):
def split_string(text):
return set(re.split(r"[._ /]", text.lower() if not case_sensitive else text))

index1 = index1 if case_sensitive else index1.lower()
index2 = index2 if case_sensitive else index2.lower()

return [path for path in paths if {index1, index2}.issubset(split_string(path))]


# =================================================
# Collect user defined options
# -------------------------------------------------
Expand Down Expand Up @@ -553,7 +564,7 @@

model_path_list = sort_human(model_path_list)

debug_print(f"model_path_list: f{model_path_list}", debug)
debug_print(f"model_path_list: {model_path_list}", debug)

# Find where run can be gripped from given filename template for modpath
if realization == "*":
Expand All @@ -569,18 +580,27 @@
).split("/")[-1],
).index(realization)

runs = [
re.split("[._]", model_path.split("/")[-1])[run_in_modpath]
for model_path in model_path_list
]

else:
runs = [realization]

print("runs:", runs)

# -------------------------------------------------
# Run
# -------------------------------------------------
for model_path in model_path_list:
print("model_path:", model_path)
for run in runs:
print("run:", runs)
try:
if realization == "*":
run = re.split("[._]", model_path.split("/")[-1])[run_in_modpath]
else:
run = realization
print(" --- ", run, " ---")

model_run_path = search_paths(model_path_list, model, run)
print("model_run_path:", model_run_path)

if run not in result_dict["RESULTS"][model]:
result_dict["RESULTS"][model][run] = {}

Expand All @@ -602,7 +622,7 @@

# read data in
model_timeseries = read_data_in(
model_path,
model_run_path,
var,
var,
msyear,
Expand Down

0 comments on commit 388b3ee

Please sign in to comment.