def is_valid_mesh(nc, varname):
"""
determine if the given variable name is a valid mesh definition
:param nc: a netCDF4 Dataset to check
:param varname: name of the candidate mesh variable
"""
try:
mesh_var = nc.variables[varname]
except KeyError:
return False
try:
if (mesh_var.cf_role.strip() == 'mesh_topology' and
int(mesh_var.topology_dimension) == 2):
return True
except AttributeError:
# not a valid mesh variable
return False
# Defining properties of various connectivity arrays
# so that the same code can load all of them.
评论列表
文章目录