Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Read data from input netCDF. Will read all variables if none provided.
Will also return all variable attributes.
Both variables (data and attributes) are returned as dictionaries named by
variable.
"""
f = Dataset(nc_file, 'r')
if variables == []:
variables = f.variables.keys()
if verbose:
print('Reading input data variables: '
' {0} from file: {1}'.format(variables, nc_file))
d = OrderedDict()
a = OrderedDict()
if coords:
if isinstance(variables, str):
d[variables] = f.variables[variables][coords]
a[variables] = f.variables[variables].__dict__
else:
for var in variables:
d[var] = f.variables[var][coords]
a[var] = f.variables[var].__dict__
else:
if isinstance(variables, str):
d[variables] = f.variables[variables][:]
a[variables] = f.variables[variables].__dict__
else:
for var in variables:
def read_config(config_file, default_config=None):
"""
Return a dictionary with subdictionaries of all configFile options/values
"""
config = SafeConfigParser()
config.optionxform = str
config.read(config_file)
sections = config.sections()
dict1 = OrderedDict()
for section in sections:
options = config.options(section)
dict2 = OrderedDict()
for option in options:
dict2[option] = config_type(config.get(section, option))
dict1[section] = dict2
if default_config is not None:
for name, section in dict1.items():
if name in default_config.keys():
for option, key in default_config[name].items():
if option not in section.keys():
dict1[name][option] = key
return dict1
# -------------------------------------------------------------------- #
def read_config(config_file, default_config=None):
"""
Return a dictionary with subdictionaries of all configFile options/values
"""
config = SafeConfigParser()
config.optionxform = str
config.read(config_file)
sections = config.sections()
dict1 = OrderedDict()
for section in sections:
options = config.options(section)
dict2 = OrderedDict()
for option in options:
dict2[option] = config_type(config.get(section, option))
dict1[section] = dict2
if default_config is not None:
for name, section in dict1.items():
if name in default_config.keys():
for option, key in default_config[name].items():
if option not in section.keys():
dict1[name][option] = key
return dict1
# -------------------------------------------------------------------- #
Will also return all variable attributes.
Both variables (data and attributes) are returned as dictionaries named by
variable.
"""
f = Dataset(nc_file, 'r')
if variables == []:
variables = f.variables.keys()
if verbose:
print('Reading input data variables: '
' {0} from file: {1}'.format(variables, nc_file))
d = OrderedDict()
a = OrderedDict()
if coords:
if isinstance(variables, str):
d[variables] = f.variables[variables][coords]
a[variables] = f.variables[variables].__dict__
else:
for var in variables:
d[var] = f.variables[var][coords]
a[var] = f.variables[var].__dict__
else:
if isinstance(variables, str):
d[variables] = f.variables[variables][:]
a[variables] = f.variables[variables].__dict__
else:
for var in variables:
d[var] = f.variables[var][:]