Skip to content

Commit

Permalink
Iss 677 (#679)
Browse files Browse the repository at this point in the history
* fix typos in xq, xh, yq, yh entries
comment out  entries in GFDL_fieldlist--need to refactor b/c multiple refs can't be parsed with current config

* add variable_id back to catalog query
add more descriptive error message for missing file assets in the event of a failed catalog query

* fix ds_names definition in xr_parser.reconcile_names
  • Loading branch information
wrongkindofdoctor authored Sep 4, 2024
1 parent 58917a7 commit 8de25fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 6 additions & 6 deletions data/fieldlist_GFDL.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"standard_name": "latitude",
"units": "degrees_north"
},
"yh": {
"xq": {
"axis": "Y",
"standard_name": "h_point_nominal_longitude",
"standard_name": "q_point_nominal_latitude",
"long_name": "h point nominal latitude",
"units": "degrees_north"
},
"xq": {
"xh": {
"axis": "X",
"standard_name": "x_point_nominal_latitude",
"standard_name": "h_point_nominal_latitude",
"long_name": "x point nominal latitude",
"units": "degrees_north"
},
Expand Down Expand Up @@ -96,8 +96,8 @@
}
},
"variables" : {
"$ref": "./gfdl-cmor-tables/gfdl_to_cmip6_vars.json",
"$ref": "./gfdl-cmor-tables/gfdl_to_cmip5_vars.json",
//"$ref": "./gfdl-cmor-tables/gfdl_to_cmip6_vars.json",
//"$ref": "./gfdl-cmor-tables/gfdl_to_cmip5_vars.json",

"areacello": {
"standard_name": "cell_area",
Expand Down
12 changes: 10 additions & 2 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def edit_request(self, v: varlist_util.VarlistEntry, **kwargs):
new_tv_name = var_dict['name']
new_tv = tv.remove_scalar(
'Z',
name=new_tv_name
name=new_tv_name,
long_name=""
)

# add original 4D var defined in new_tv as an alternate TranslatedVarlistEntry
Expand Down Expand Up @@ -718,6 +719,7 @@ def check_time_bounds(self, ds, var: translation.TranslatedVarlistEntry, freq: s
<https://unidata.github.io/cftime/api.html#cftime.datetime>`__
objects so that they can be compared with the model data's time axis.
"""
# TODO make time bound checks less restrictive for mon and longer data
dt_range = var.T.range
ds_decode = xr.decode_cf(ds, use_cftime=True)
t_coord = ds_decode[var.T.name]
Expand Down Expand Up @@ -930,6 +932,7 @@ def query_catalog(self,
case_d.query['path'] = [path_regex]
case_d.query['realm'] = realm_regex
case_d.query['standard_name'] = var.translation.standard_name
case_d.query['variable_id'] = var.translation.name

# change realm key name if necessary
if cat.df.get('modeling_realm', None) is not None:
Expand All @@ -948,8 +951,10 @@ def query_catalog(self,
for a in var.alternates:
if hasattr(a, 'translation'):
if a.translation is not None:
case_d.query.update({'variable_id': a.translation.name})
case_d.query.update({'standard_name': a.translation.standard_name})
else:
case_d.query.update({'variable_id': a.name})
case_d.query.update({'standard_name': a.standard_name})
if any(var.translation.scalar_coords):
found_z_entry = False
Expand All @@ -969,7 +974,10 @@ def query_catalog(self,
if cat_subset.df.empty:
raise util.DataRequestError(
f"No assets matching query requirements found for {var.translation.name} for"
f" case {case_name} in {data_catalog}")
f" case {case_name} in {data_catalog}. The input catalog may missing entries for the"
f"following required fields: standard_name, variable_id, units, realm."
f"Check that the target file paths contain the case_name(s) defined in the runtime"
f"configuration file.")
else:
raise util.DataRequestError(
f"Unable to find match or alternate for {var.translation.name}"
Expand Down
4 changes: 2 additions & 2 deletions src/xr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,12 +899,12 @@ def reconcile_names(self, our_var, ds, ds_var_name: str, overwrite_ours: bool =
# try searching for 4-D field instead of variable name for a specific level
# (e.g., U instead of U500)
else:
ds_names = []
tv_name = ds_var_name
if len(our_var.scalar_coords) > 0:
ds_var_name = ''.join(filter(lambda x: not x.isdigit(), tv_name))
ds_names.append(''.join(filter(lambda x: not x.isdigit(), tv_name)))
else:
# attempt to match on standard_name attribute if present in data
ds_names = []
for v in ds.variables:
if hasattr(v, 'name') and ds.variables[v].attrs.get('standard_name', "") == our_var.standard_name:
ds_names.append(ds.variables[v].name)
Expand Down

0 comments on commit 8de25fa

Please sign in to comment.