Skip to content

Commit

Permalink
Bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rigoudyg committed Jun 2, 2022
1 parent fa9b574 commit 3ef0fa3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 26 deletions.
21 changes: 13 additions & 8 deletions dr2xml/dr_interface/CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,31 @@ def get_sectors_list():


def get_element_uid(id=None, error_msg=None, raise_on_error=False, check_print_DR_errors=True,
check_print_stdnames_error=False):
check_print_stdnames_error=False, elt_type=None):
"""
Get the uid of an element if precised, else the list of all elements.
"""
logger = get_logger()
if id is None:
return dq.inx.uid
rep = dq.inx.uid
elif id in dq.inx.uid:
return dq.inx.uid[id]
rep = dq.inx.uid[id]
else:
if error_msg is None:
error_msg = "DR Error: issue with %s" % id
if raise_on_error:
raise Dr2xmlError(error_msg)
elif check_print_DR_errors and print_DR_errors:
logger.error(error_msg)
return None
elif check_print_stdnames_error and print_DR_stdname_errors:
logger.error(error_msg)
return None
else:
return None
rep = None
if rep is not None:
if elt_type in ["variable", ]:
pass
elif elt_type in ["dim", ]:
correct_data_request_dim(rep)
return rep


def get_experiment_label(experiment):
Expand Down Expand Up @@ -154,7 +157,9 @@ def correct_data_request_dim(dim):
if dim.label in ["misrBands", ]:
dim.dimsize = 16
if dim.type in ["character", ]:
dim.altLabel = "sector"
dim.name = "sector"
else:
dim.name = dim.altLabel
# The latter is a bug in DR01.00.21 : typewetla has no value there
if dim.label in ["typewetla", ]:
dim.value = "wetland"
Expand Down
8 changes: 4 additions & 4 deletions dr2xml/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def change_axes_in_grid(grid_id):
# Definitely don't want to change an unnamed axis. Such an axis is
# generated by vertical interpolation
if not any([ssub.tag in ['interpolate_axis', ] for ssub in sub]):
logger.warning("Cannot normalize an axis in grid %s : no axis_ref for axis %s" % (grid_id, sub))
logger.warning("Cannot normalize an axis in grid %s: no axis_ref for axis %s" % (grid_id, sub))
else:
axis_ref = sub.attrib['axis_ref']
# Just quit if axis doesn't have to be processed
Expand All @@ -290,7 +290,7 @@ def change_axes_in_grid(grid_id):
dim_id = 'dim:{}'.format(dr_axis_id)
# print "in change_axis for %s %s"%(grid_id,dim_id)
# dim_id should be a dimension !
dim = get_element_uid(dim_id,
dim = get_element_uid(dim_id, elt_type="dim",
error_msg="Value %s in 'non_standard_axes' is not a DR dimension id" % dr_axis_id)
# We don't process scalars here
if dim.value in ['', ] or dim.label in ["scatratio", ]:
Expand Down Expand Up @@ -318,7 +318,7 @@ def create_axis_from_dim(dim, labels, axis_ref):
constructs generating CMIP6 requested attributes
"""
axis_id = "DR_" + dim.label + "_" + axis_ref
axis_name = dim.altLabel
axis_name = dim.name
if axis_id in get_config_variable("axis_defs"):
return axis_id, axis_name
#
Expand Down Expand Up @@ -375,7 +375,7 @@ def scalar_vertical_dimension(sv):
Return the altLabel attribute if it is a vertical dimension, else None.
"""
if 'cids' in sv.struct.__dict__:
cid = get_element_uid(sv.struct.cids[0])
cid = get_element_uid(sv.struct.cids[0], elt_type="dim")
if is_vert_dim(cid):
return cid.altLabel
return None
Expand Down
16 changes: 11 additions & 5 deletions dr2xml/infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from __future__ import print_function, division, absolute_import, unicode_literals

from collections import OrderedDict
from collections import OrderedDict, defaultdict

from logger import get_logger

Expand Down Expand Up @@ -113,12 +113,14 @@ def print_some_stats(context, svars_per_table, skipped_vars_per_table, actually_
if extended:
logger.info("\n\nSome Statistics on actually written variables per variable...")
dic = OrderedDict()
dic_ln = OrderedDict()
dic_ln = defaultdict(set)
for label, long_name, table, frequency, Priority, spatial_shp in actually_written_vars:
dic_ln[label].add(long_name)
if label not in dic:
dic[label] = []
dic_ln.update({label: long_name})
dic[label] = list()
dic[label].append(frequency + '_' + table + '_' + spatial_shp + '_' + str(Priority))
for label in dic_ln:
dic_ln[label] = sorted(list(dic_ln[label]))

list_labels = list(dic)
list_labels.sort()
Expand All @@ -127,9 +129,13 @@ def print_some_stats(context, svars_per_table, skipped_vars_per_table, actually_

for label in list_labels:
logger.info((14 + len(label)) * "-")
logger.info("--- VARNAME: %s: %s" % (label, dic_ln[label]))
logger.info("--- VARNAME: %s: %s" % (label, dic_ln[label][0]))
logger.info((14 + len(label)) * "-")
for val in dic[label]:
logger.info(14 * " " + "* %20s %s" % (val, label))
if len(dic_ln[label]) > 1:
logger.warning(14 * " " + "Warning: several long names are available:")
for long_name in dic_ln[label]:
logger.warning(18 * " " + "- %s" % long_name)

return True
8 changes: 4 additions & 4 deletions dr2xml/pingfiles_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ def check_for_file_input(sv, hgrid):
remap_grid_def = DR2XMLElement(tag="grid", id=file_grid_id)
remap_grid_def.append(DR2XMLElement(tag="domain", domain_ref=file_domain_id))
add_value_in_dict_config_variable(variable="grid_defs", key=file_grid_id, value=remap_grid_def)
logger.info(domain_def)
logger.info(remap_grid_def)
logger.debug(domain_def)
logger.debug(remap_grid_def)

# Create xml for reading the variable
filename = externs[sv.label][hgrid][get_grid_choice()]
Expand All @@ -322,7 +322,7 @@ def check_for_file_input(sv, hgrid):
file_def.append(DR2XMLElement(tag="field", id=field_in_file_id, name=sv.label, operation="instant",
freq_op="1ts", freq_offset="1ts", grid_ref=file_grid_id))
add_value_in_dict_config_variable(variable="file_defs", key=file_id, value=file_def)
logger.info(file_def)
logger.debug(file_def)
#
# field_def='<field id="%s" grid_ref="%s" operation="instant" >%s</field>'%\
field_def = DR2XMLElement(tag="field", id=pingvar, grid_ref=grid_id, field_ref=field_in_file_id,
Expand All @@ -331,4 +331,4 @@ def check_for_file_input(sv, hgrid):
context_index = get_config_variable("context_index", to_change=True)
context_index[pingvar] = field_def

logger.info(field_def)
logger.debug(field_def)
6 changes: 6 additions & 0 deletions dr2xml/projects/CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ def fill_license(value, institution_id, info_url):
)
)
]
),
realm=ParameterSettings(
key="realm",
corrections=dict(
ocnBgChem="ocnBgchem"
)
)
)
)
Expand Down
2 changes: 2 additions & 0 deletions dr2xml/projects/projects_interface_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ def check(self, common_dict=dict(), internal_dict=dict(), additional_dict=dict()
additional_dict=additional_dict,
allow_additional_keytypes=allow_additional_keytypes)
if relevant:
if isinstance(check_value, list) and len(check_value) == 1:
check_value = check_value[0]
reference_values = [return_value(reference_value, common_dict=common_dict, internal_dict=internal_dict,
additional_dict=additional_dict,
allow_additional_keytypes=allow_additional_keytypes)
Expand Down
6 changes: 5 additions & 1 deletion dr2xml/vars_interface/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ class SimpleDim(SimpleObject):
"""
def __init__(self, label=False, zoom_label=False, stdname=False, long_name=False, positive=False, requested="",
value=False, out_name=False, units=False, is_zoom_of=False, bounds=False, boundsValues=False,
axis=False, type=False, coords=False, title=False, is_union_for=list(), **kwargs):
axis=False, type=False, coords=False, title=False, name=None, is_union_for=list(), **kwargs):
self.label = label
self.altLabel = self.label
self.zoom_label = zoom_label
self.stdname = stdname
self.long_name = long_name
Expand All @@ -126,6 +127,7 @@ def __init__(self, label=False, zoom_label=False, stdname=False, long_name=False
self.coords = coords
self.title = title
self.is_union_for = is_union_for
self.name = name
super(SimpleDim, self).__init__(**kwargs)

def correct_data_request(self):
Expand All @@ -134,3 +136,5 @@ def correct_data_request(self):
self.dimsize = max(len(self.requested.split(" ")), 1)
else:
self.dimsize = 1
if self.altLabel != self.label:
self.altLabel = self.label
2 changes: 1 addition & 1 deletion dr2xml/vars_interface/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def read_extra_table(path, table):
realms=["atmos", "aerosol", "atmosChem"]))
extra_var.set_attributes(ref_var=extra_var.label_without_psuffix)
extravars.append(extra_var)
logger.info("For extra table %s (which has %d variables): " % (table, len(extravars)))
logger.info("For extra table %s (which has %d variables):" % (table, len(extravars)))
logger.info("\tVariables which dim was found in extra coordinates table:\n%s" %
"\n".join(["\t\t%20s: %s\n" % (d, " ".join(sorted(dim_from_extra[d])))
for d in sorted(list(dim_from_extra))]))
Expand Down
2 changes: 1 addition & 1 deletion dr2xml/vars_interface/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_simple_dim_from_dim_id(dimid):
"""
d = get_element_uid(dimid)
#
stdname = get_element_uid(d.standardName, check_print_stdnames_error=True,
stdname = get_element_uid(d.standardName, check_print_stdnames_error=True, check_print_DR_errors=False,
error_msg="Issue with standardname for dimid %s" % dimid)
if stdname is not None:
stdname = stdname.uid
Expand Down
2 changes: 1 addition & 1 deletion dr2xml/vars_interface/generic_data_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def select_data_request_CMORvars_for_lab(sset=False, year=None):
% (multiple_grids[-1], repr(d[v])))
if not print_multiple_grids and multiple_grids is not None and len(multiple_grids) > 0:
logger.info("\tThese variables will be processed with multiple grids "
"(rerun with print_multiple_grids set to True for details): %s" % repr(multiple_grids.sort()))
"(rerun with print_multiple_grids set to True for details): %s" % repr(sorted(multiple_grids)))
#
# Print a count of distinct var labels
logger.info('Number of distinct var labels is: %d' % len(set([get_element_uid(v).label for v in d])))
Expand Down
3 changes: 2 additions & 1 deletion dr2xml/vars_interface/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def check_exclusion(var, *exclusions):
reasons = ". ".join(reasons).strip()
if len(reasons) == 0:
reasons = "Unknown reason."
reasons = " " + reasons
return tests, reasons


Expand Down Expand Up @@ -90,7 +91,7 @@ def select_variables_to_be_processed(year, context, select):
else:
svars_per_table[svar.mipTable].append(svar)
if len(excluded_vars) > 0:
logger.info("The following pairs (variable,table) have been excluded for these reasons :\n%s" %
logger.info("The following pairs (variable,table) have been excluded for these reasons:\n%s" %
"\n".join(["%s: %s" % (reason, print_struct(excluded_vars[reason], skip_sep=True, sort=True))
for reason in sorted(list(excluded_vars))]))
for table in sorted(list(svars_per_table)):
Expand Down

0 comments on commit 3ef0fa3

Please sign in to comment.