Skip to content

Commit

Permalink
Merge pull request #4649 from ESMCI/fix-query_config
Browse files Browse the repository at this point in the history
Fixes `query_config` tool.
- Adds longname to `--grids`
- Fixes duplicate and empty choices

Test suite: n/a
Test baseline: n/a
Test namelist changes: n/a
Test status: n/a

Fixes #4622 
Fixes #4623 
User interface changes?: n/a
Update gh-pages html (Y/N)?: n
  • Loading branch information
jasonb5 committed Aug 2, 2024
2 parents 783f23a + 9aa1e25 commit 977d122
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 387 deletions.
2 changes: 1 addition & 1 deletion CIME/XML/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def print_values(self):
for entry in entries:
name = self.get(entry, "id")
text = self.text(self.get_child("desc", root=entry))
logger.info(" {:20s} : {}".format(name, text.encode("utf-8")))
logger.info(" {:20s} : {}".format(name, text))

def return_values(self):
"""
Expand Down
68 changes: 47 additions & 21 deletions CIME/XML/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,13 @@ def _valid_lname(self, name):
break
return valid

def _read_config_grids(self, name, compset, atmnlev, lndnlev):
def _read_config_grids(self, name, compset, atmnlev=None, lndnlev=None):
"""
read config_grids.xml with version 2.0 schema
Returns a grid long name given the alias ('name' argument)
"""
model_grid = {}
for comp_gridname in self._comp_gridnames:
model_grid[comp_gridname] = None

# (1) set array of component grid defaults that match current compset
grids_node = self.get_child("grids")
grid_defaults_node = self.get_child("model_grid_defaults", root=grids_node)
for grid_node in self.get_children("grid", root=grid_defaults_node):
name_attrib = self.get(grid_node, "name")
compset_attrib = self.get(grid_node, "compset")
compset_match = re.search(compset_attrib, compset)
if compset_match is not None:
model_grid[name_attrib] = self.text(grid_node)

# (2)loop over all of the "model grid" nodes and determine is there an alias match with the
# input grid name - if there is an alias match determine if the "compset" and "not_compset"
Expand Down Expand Up @@ -200,37 +188,65 @@ def _read_config_grids(self, name, compset, atmnlev, lndnlev):
foundcompset, "grid alias {} not valid for compset {}".format(name, compset)
)

# for the match - find all of the component grid settings
return self.get_grid_longname(
grids_node, model_gridnode, compset, atmnlev, lndnlev
)

def get_grid_longname(
self, grids_node, model_gridnode, compset=None, atmnlev=None, lndnlev=None
):
model_grid = {}

for comp_gridname in self._comp_gridnames:
model_grid[comp_gridname] = None

if compset is not None:
grid_defaults_node = self.get_child("model_grid_defaults", root=grids_node)

for grid_node in self.get_children("grid", root=grid_defaults_node):
name_attrib = self.get(grid_node, "name")
compset_attrib = self.get(grid_node, "compset")
compset_match = re.search(compset_attrib, compset)

if compset_match is not None:
model_grid[name_attrib] = self.text(grid_node)

grid_nodes = self.get_children("grid", root=model_gridnode)

for grid_node in grid_nodes:
name = self.get(grid_node, "name")
value = self.text(grid_node)

if model_grid[name] != "null":
model_grid[name] = value

mask_node = self.get_optional_child("mask", root=model_gridnode)

if mask_node is not None:
model_grid["mask"] = self.text(mask_node)
else:
model_grid["mask"] = model_grid["ocnice"]

lname = ""

for component_gridname in self._comp_gridnames:
if lname:
lname = lname + "_" + grid_prefix[component_gridname]
else:
lname = grid_prefix[component_gridname]

if model_grid[component_gridname] is not None:
lname += model_grid[component_gridname]

if component_gridname == "atm" and atmnlev is not None:
if not ("a{:n}ull" in lname):
lname += "z" + atmnlev

elif component_gridname == "lnd" and lndnlev is not None:
if not ("l{:n}ull" in lname):
lname += "z" + lndnlev

else:
lname += "null"

return lname

def _get_domains(self, component_grids, atmlevregex, lndlevregex, driver):
Expand Down Expand Up @@ -539,7 +555,7 @@ def _get_gridmaps_for_one_grid_pair(
for name, value in these_gridmaps.items():
_add_grid_info(gridmaps, name, value)

def print_values(self, long_output=None):
def print_values(self, long=False):
# write out help message
helptext = self.get_element_text("help")
logger.info("{} ".format(helptext))
Expand Down Expand Up @@ -573,7 +589,7 @@ def print_values(self, long_output=None):
)

domains = {}
if long_output is not None:
if long:
domain_nodes = self.get_children("domain", root=self.get_child("domains"))
for domain_node in domain_nodes:
name = self.get(domain_node, "name")
Expand All @@ -599,7 +615,8 @@ def print_values(self, long_output=None):
desc, files
)

model_grid_nodes = self.get_children("model_grid", root=self.get_child("grids"))
grids_node = self.get_child("grids")
model_grid_nodes = self.get_children("model_grid", root=grids_node)
for model_grid_node in model_grid_nodes:
alias = self.get(model_grid_node, "alias")
compset = self.get(model_grid_node, "compset")
Expand All @@ -616,18 +633,27 @@ def print_values(self, long_output=None):
grid_nodes = self.get_children("grid", root=model_grid_node)
grids = ""
gridnames = []
lname = self.get_grid_longname(grids_node, model_grid_node)
logger.info("\n{:<7}longname: {}".format(" ", lname))
for grid_node in grid_nodes:
gridnames.append(self.text(grid_node))
grids += self.get(grid_node, "name") + ":" + self.text(grid_node) + " "
logger.info(" non-default grids are: {}".format(grids))
mask_nodes = self.get_children("mask", root=model_grid_node)
for mask_node in mask_nodes:
logger.info(" mask is: {}".format(self.text(mask_node)))
if long_output is not None:
if long:
gridnames = set(gridnames)
for gridname in gridnames:
if gridname != "null":
logger.info(" {}".format(domains[gridname]))
try:
logger.info(" {}".format(domains[gridname]))
except KeyError:
logger.info(
" Could not provide domains for gridname {!r}".format(
gridname
)
)


# ------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 977d122

Please sign in to comment.