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
list : [<function bias at 0x0000029D614A2DD0>, (...)]
metrics.
plot.rcparams : {}'facecolor': 'white', (...)}
plot.scatter.legend.bbox : {12
plot.scatter.legend.fontsize :
plot.scatter.legend.kwargs : {}
plot.scatter.oneone_line.color : blue1:1
plot.scatter.oneone_line.label : 0.5
plot.scatter.points.alpha :
plot.scatter.points.label :20
plot.scatter.points.size :
plot.scatter.quantiles.color : darkturquoise
plot.scatter.quantiles.kwargs : {}-Q
plot.scatter.quantiles.label : Q
plot.scatter.quantiles.marker : X0, 0, 0, 0.4)
plot.scatter.quantiles.markeredgecolor : (0.5
plot.scatter.quantiles.markeredgewidth : 3.5
plot.scatter.quantiles.markersize : 'color': 'r'}
plot.scatter.reg_line.kwargs : {>>> 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
20
Classes
Name | Description |
---|---|
OptionsContainer | provide attribute-style access to a nested dict of options |
OptionsContainer
self, d, prefix='') settings.OptionsContainer(
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
='', validator=None) settings.register_option(key, defval, doc
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
='', silent=False) settings.reset_option(pat
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
20
set_option
*args, **kwargs) settings.set_option(
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