settings
settings
Global modelskill settings.
The settings module holds package-wide configurables and provides a uniform API for working with them.
This module is inspired by pandas config module.
Overview
This module supports the following requirements:
- options are referenced using keys in dot.notation, e.g. “x.y.option - z”.
- keys are case-insensitive.
- functions should accept partial/regex keys, when unambiguous.
- options can be registered by modules at import time.
- options have a default value, and (optionally) a description and validation function associated with them.
- options can be reset to their default value.
- all option can be reset to their default value at once.
- all options in a certain sub - namespace can be reset at once.
- the user can set / get / reset or ask for the description of an option.
- a developer can register an option.
Implementation
- Data is stored using nested dictionaries, and should be accessed through the provided API.
- “Registered options” have metadata associated with them, which are stored in auxiliary dictionaries keyed on the fully-qualified key, e.g. “x.y.z.option”.
Examples
>>> import modelskill as ms
>>> ms.options
metrics.list : [<function bias at 0x0000029D614A2DD0>, (...)]
plot.rcparams : {}
plot.scatter.legend.bbox : {'facecolor': 'white', (...)}
plot.scatter.legend.fontsize : 12
plot.scatter.legend.kwargs : {}
plot.scatter.oneone_line.color : blue
plot.scatter.oneone_line.label : 1:1
plot.scatter.points.alpha : 0.5
plot.scatter.points.label :
plot.scatter.points.size : 20
plot.scatter.quantiles.color : darkturquoise
plot.scatter.quantiles.kwargs : {}
plot.scatter.quantiles.label : Q-Q
plot.scatter.quantiles.marker : X
plot.scatter.quantiles.markeredgecolor : (0, 0, 0, 0.4)
plot.scatter.quantiles.markeredgewidth : 0.5
plot.scatter.quantiles.markersize : 3.5
plot.scatter.reg_line.kwargs : {'color': 'r'}
>>> ms.set_option("plot.scatter.points.size", 4)
>>> plot.scatter.points.size
4
>>> ms.get_option("plot.scatter.points.size")
4
>>> ms.options.plot.scatter.points.size = 10
>>> ms.options.plot.scatter.points.size
10
>>> ms.reset_option("plot.scatter.points.size")
>>> ms.options.plot.scatter.points.size
20Classes
| Name | Description |
|---|---|
| OptionsContainer | provide attribute-style access to a nested dict of options |
OptionsContainer
settings.OptionsContainer(d, prefix='')provide attribute-style access to a nested dict of options
Accessed by ms.options
Methods
| Name | Description |
|---|---|
| to_dict | Return options as dictionary with full-name keys |
to_dict
settings.OptionsContainer.to_dict()Return options as dictionary with full-name keys
Functions
| Name | Description |
|---|---|
| get_option | Get value of a single option matching a pattern |
| load_style | Load a number of options from a named style. |
| register_option | Register an option in the package-wide modelskill settingss object |
| reset_option | Reset one or more options (matching a pattern) to the default value |
| set_option | Set the value of one or more options |
get_option
settings.get_option(pat)Get value of a single option matching a pattern
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pat | str | pattern of seeked option | required |
Returns
| Name | Type | Description |
|---|---|---|
| Any | value of matched option |
load_style
settings.load_style(name)Load a number of options from a named style.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| name | str | Name of the predefined style to load. Available styles are: ‘MOOD’: Resembling the plots of the www.metocean-on-demand.com data portal. | required |
Raises
| Name | Type | Description |
|---|---|---|
| KeyError | If a named style is not found. |
Examples
>>> import modelskill as ms
>>> ms.load_style('MOOD')register_option
settings.register_option(key, defval, doc='', validator=None)Register an option in the package-wide modelskill settingss object
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| key | str | Fully-qualified key, e.g. “x.y.option - z”. | required |
| defval | object | Default value of the option. | required |
| doc | str | Description of the option. | '' |
| validator | Callable | Function of a single argument, should raise ValueError if called with a value which is not a legal value for the option. |
None |
Raises
| Name | Type | Description |
|---|---|---|
ValueError if validator is specified and defval is not a valid value. |
reset_option
settings.reset_option(pat='', silent=False)Reset one or more options (matching a pattern) to the default value
Examples
>>> ms.options.plot.scatter.points.size
20
>>> ms.options.plot.scatter.points.size = 10
>>> ms.options.plot.scatter.points.size
10
>>> ms.reset_option("plot.scatter.points.size")
>>> ms.options.plot.scatter.points.size
20set_option
settings.set_option(*args, **kwargs)Set the value of one or more options
Examples
>>> ms.set_option("plot.scatter.points.size", 4)
>>> ms.set_option({"plot.scatter.points.size": 4})
>>> ms.options.plot.scatter.points.size = 4