Skip to content

Commit

Permalink
more general wildcard identification
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjwilson committed Sep 19, 2024
1 parent e9b402a commit fec8725
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ecoval/matchall.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ def get_time_res(x, folder=None):

wild_card = final_extension + x
wild_card = wild_card.replace("**", "*")
for x in pathlib.Path(folder).glob(wild_card):
path = x
# convert to string
path = str(path)
break
# figure out if the session is fvcom
if True:
for x in pathlib.Path(folder).glob(wild_card):
path = x
# convert to string
path = str(path)
break

ds = nc.open_data(path, checks=False)
ds_times = ds.times
Expand Down Expand Up @@ -330,14 +332,21 @@ def extract_variable_mapping(folder, exclude=[], n_check=None, fvcom = False):

# replace integers with 4 or more digits with **
new_name = re.sub(r"\d{4,}", "**", new_name)
# replace strings of the form _12. with _**.
new_name = re.sub(r"\d{2,}", "**", new_name)
#new_name = re.sub(r"_\d{2,}\.", "_**.", new_name)

all_df.append(
pd.DataFrame.from_dict(new_dict).melt().assign(pattern=new_name)
)

all_df = pd.concat(all_df).reset_index(drop=True)

all_df["resolution"] = [get_time_res(x, folder) for x in all_df.pattern]
patterns = set(all_df.pattern)
resolution_dict = dict()
for folder in patterns:
resolution_dict[folder] = get_time_res(folder, new_directory)
all_df["resolution"] = [resolution_dict[x] for x in all_df.pattern]

all_df = (
all_df.sort_values("resolution").groupby("value").head(1).reset_index(drop=True)
Expand Down Expand Up @@ -664,6 +673,8 @@ def write_report(x):
key_failed = False
if key_failed:
raise ValueError(f"{key} is not a valid argument")

session_info["fvcom"] = fvcom

if end is not None:
sim_end = end
Expand Down

0 comments on commit fec8725

Please sign in to comment.