Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
fname_base = prefix
# some special logic is required for grid variables
if prefix in self._all_grid_variables:
# grid variables don't have an iteration number suffix
iternum = None
# some grid variables have a different filename than their varname
if 'filename' in self._all_grid_variables[prefix]:
fname_base = self._all_grid_variables[prefix]['filename']
else:
assert iternum is not None
# get a dict of variables and their data
vardata = read_mds(os.path.join(self.dirname, fname_base), iternum,
endian=self.endian)
for vname, data in vardata.items():
# we now have to revert to the original prefix once the file is read
if fname_base != prefix:
vname = prefix
try:
metadata = (self._all_grid_variables[vname]
if vname in self._all_grid_variables
else self._all_data_variables[vname])
except KeyError:
if self._ignore_unknown_vars:
# we didn't find any metadata, so we just skip this var
continue
else:
raise KeyError("Couln't find metadata for variable %s "
"and `ignore_unknown_vars`==False." % vname)