Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create function rename_dataset_vars and fix in catalog.py #586

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mdtf_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def backup_config(config):
cat_subset = data_pp.process(cases, ctx.config, model_paths.MODEL_WORK_DIR)
# write the preprocessed files
data_pp.write_ds(cases, cat_subset, pod_runtime_reqs)
# rename vars in cat_subset to align with POD convention
cat_subset = data_pp.rename_dataset_vars(cat_subset, cases)
# write the ESM intake catalog for the preprocessed files
data_pp.write_pp_catalog(cat_subset, model_paths, log.log)
# configure the runtime environments and run the POD(s)
Expand Down
12 changes: 11 additions & 1 deletion src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,17 @@ def rename_key(old_dict: dict, new_dict: collections.OrderedDict, old_key, new_k
(path, filename) = os.path.split(case_d.attrs['intake_esm_attrs:path'])
rename_key(ds, new_dict, old_key, [c for c in case_names if c in filename][0])
return new_dict


def rename_dataset_vars(self, ds: dict, case_list: dict) -> collections.OrderedDict:
"""Rename variables in dataset to conform with variable names requested by the POD"""
case_names = [c for c in case_list.keys()]
for c in case_names:
name_dict = {}
for var in case_list[c].varlist.iter_vars():
name_dict[var.translation.name] = var.name
ds[c] = ds[c].rename_vars(name_dict=name_dict)
return ds

def clean_nc_var_encoding(self, var, name, ds_obj):
"""Clean up the ``attrs`` and ``encoding`` dicts of *ds_obj*
prior to writing to a netCDF file, as a workaround for the following
Expand Down
5 changes: 2 additions & 3 deletions src/util/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ def __init__(self, file_path: str):
class ppParserGFDL(ppParserBase):
def __init__(self, file_path: str):
super().__init__(file_path)

self.filename_template = (
'{realm}.{time_range}.{variable_id}.{frequency}.nc'
'{realm}.{variable_id}.{frequency}.nc'
)
self.f = _reverse_filename_format(self.file_basename,
filename_template=self.filename_template
)

self.cat_entry.update(self.f)
self.cat_entry['path'] = file_path
self.cat_entry['dataset_name'] = self.cat_entry['realm'] + '.' + self.cat_entry['time_range']
self.cat_entry['dataset_name'] = self.cat_entry['realm']


@ppParser.maker
Expand Down
Loading