SharedPlotSetting

class PlasmaCalcs.plotting.plot_settings.SharedPlotSetting(*args_super, docs_key, shared_keys, **kw_super)

Bases: PlotSetting

PlotSetting which is shared amongst multiple kwargs.

E.g., in DEFAULT_PLOT_SETTINGS:
‘kw_subplots_adjust’: [
(‘hspace’, ‘wspace’, ‘bottom’, ‘top’, ‘left’, ‘right’),
(None, “None or number (probably between 0 and 1)”,
“””corresponding value that will be used during plt.subplots_adjust(…).
None –> use rcParams[“figure.subplot.*”].”””),
],
corresponds to 6 kwargs, all with the same default value and docstring.
No need to repeat the docstring multiple times.
self.docs_dict() will contain the value from super(),
in addition to {docs_key: “{’, ‘.join(self.subkeys)}: {docstring}”}.
E.g. when doing PlotSettings.format_docstring(),
formatted func could either contain individual keys, like:

hspace: {hspace} wspace: {wspace}

OR, just contain the docs_key, like:
{kw_subplots_adjust}

Methods

__iter__()

returns iter of tuple of (key, default, typestr, doc, defaults_keystring, validation).

defaults_keystring_formatting()

returns dict which will be used to .format the docstring.

defaults_keystring_value()

get the value from DEFAULTS.

docs_dict([ntab])

returns super().docs_di

docstring([ntab])

return the docstring for this setting, in format:

get([provided])

get the value from self.

get_default()

get the default value: self.default if defaults_keystring is None else value from DEFAULTS.

validate(value)

ensures that value is valid for this setting.

_docs_key_docs_dict([ntab])

return dict with key self.docs_key, "{', '.join(self.subkeys)}: {self.docstring(ntab)}".

_get_validation_message([default])

return self.validation_message, with a space prepended if needed.

_value_from_DEFAULTS_str(s, *[, s_name])

get any value from DEFAULTS.

__iter__()

returns iter of tuple of (key, default, typestr, doc, defaults_keystring, validation).

Thus, can create new PlotSetting with:
PlotSetting(self.key, *iter(self))
_docs_key_docs_dict(ntab=UNSET)

return dict with key self.docs_key, “{’, ‘.join(self.subkeys)}: {self.docstring(ntab)}”.

_get_validation_message(default=None)

return self.validation_message, with a space prepended if needed.

if default provided and self.validation_message is None, use default.
static _value_from_DEFAULTS_str(s, *, s_name='')

get any value from DEFAULTS. s_name used if raising an error message.

defaults_keystring_formatting()

returns dict which will be used to .format the docstring.

If self.defaults_keystring is provided:
{‘default_value’: self.defaults_keystring_value(),
‘default_key’: self.defaults_keystring,
‘default’: f’{self.defaults_keystring} (default: {self.defaults_keystring_value()})’}
Also, if self.defaults_keystring_dict is provided, include something similar for each key in dict,
adding ‘defaults_dict_{key}_value’, ‘defaults_dict_{key}_key’, and ‘defaults_dict_{key}’.
E.g. if defaults_keystring=(‘DEFAULTS.PLOT.ROBUST’, {True: ‘DEFAULTS.PLOT.ROBUST_PERCENTILE’}),
when DEFAULTS.PLOT.ROBUST = True and DEFAULTS.PLOT.ROBUST_PERCENTILE = 2.0:
{‘default_value’: True
‘default_key’: ‘DEFAULTS.PLOT.ROBUST’,
‘default’: ‘DEFAULTS.PLOT.ROBUST (default: True)’,
‘defaults_dict_True_value’: 2.0,
‘defaults_dict_True_key’: ‘DEFAULTS.PLOT.ROBUST_PERCENTILE’,
‘defaults_dict_True’: ‘DEFAULTS.PLOT.ROBUST_PERCENTILE (default: 2.0)’}
defaults_keystring_value()

get the value from DEFAULTS.

docs_dict(ntab=UNSET)

returns super().docs_di

docstring(ntab=UNSET)

return the docstring for this setting, in format:

{self.typestr} (default: {self.default})
{self.doc}
the typestr line will not be indented at all;
the docstring line(s) will be indented by self.tab * ntab.
self.doc will be hit by .format(**self.defaults_keystring_formatting()).
(If self.defaults_keystring is None, this shouldn’t change the result.)
get(provided=UNSET)

get the value from self. return provided if not UNSET, else return self.get_default()

get_default()

get the default value: self.default if defaults_keystring is None else value from DEFAULTS.

validate(value)

ensures that value is valid for this setting. Raise InputError if it is not.

return (if no InputError is raised) depends on self.validation:
None –> return None
iterable –> return True if valid in self.validation
callable –> return self.validation(value)