Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new possiblities for providing paramters. #1756

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions oggm/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ def _log_param_change(self, key, value):
_doc = "The outlines of this glacier complex sub-entities (for RGI7C only!)."
BASENAMES['complex_sub_entities'] = ('complex_sub_entities.shp', _doc)

_doc = ("A dict containing optional settings for a model run. Could contain "
"mass balance parameters, dynamic parameters or observations. If a "
"required parameter is not included, the default value will be used.")
BASENAMES['run_settings'] = ('run_settings.yml', _doc)


def set_logging_config(logging_level='INFO'):
"""Set the global logger parameters.
Expand Down Expand Up @@ -378,29 +383,45 @@ def initialize_minimal(file=None, logging_level='INFO', params=None):
Parameters
----------
file : str
path to the configuration file (default: OGGM params.cfg)
path to a user configuration file. The parameters provided in this file
will override the default settings in `OGGM params.cfg`. The file does
not need to include all parameters.
logging_level : str
set a logging level. See :func:`set_logging_config` for options.
params : dict
overrides for specific parameters from the config file
overrides for specific parameters from the config file. Overrules a
potential provided file.
"""
global IS_INITIALIZED
global PARAMS
global PATHS

set_logging_config(logging_level=logging_level)

is_default = False
if file is None:
file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'params.cfg')
is_default = True
# Open default params file
is_default = True
file_default = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'params.cfg')
try:
cp = ConfigObj(file, file_error=True)
cp = ConfigObj(file_default, file_error=True)
except (ConfigObjError, IOError) as e:
log.critical('Config file could not be parsed (%s): %s', file, e)
log.critical('Config file could not be parsed (%s): %s',
file_default, e)
sys.exit()

# If provided open user params file and overwrite defaults
if file:
is_default = False
try:
cp_user = ConfigObj(file, file_error=True)
except (ConfigObjError, IOError) as e:
log.critical('Config file could not be parsed (%s): %s',
file, e)
sys.exit()

for k, v in cp_user.items():
cp[k] = v

if is_default:
log.workflow('Reading default parameters from the OGGM `params.cfg` '
'configuration file.')
Expand All @@ -411,7 +432,7 @@ def initialize_minimal(file=None, logging_level='INFO', params=None):
# Static Paths
oggm_static_paths()

# Apply code-side manual params overrides
# Apply code-side manual params overrides, overrules provided params file
if params:
for k, v in params.items():
cp[k] = v
Expand Down
Loading