Settings#

Some default settings are specific to a method or function. Settings of a specific quality control method are an example of these. For these settings, the default values are provided by default argument values.

Some settings are used by multiple modules and functions in the MetObs toolkit. For example, the timezone to store timestamps is used by all classes that store timestamps. The default values of these settings are stored in the Settings class.

[4]:
import metobs_toolkit

# The Settings class is accessible directly from the package
Settings = metobs_toolkit.Settings

Settings
[4]:
metobs_toolkit.settings_collection.settings.Settings

By design (Singleton-design), there can only exist ONE Settings object. So if you change it, it will take effect everywhere the Settings are used.

Interacting with the settings#

As a user, you can read and change the current settings. Settings are stored in a dictionary structure and can be read and written like so:

[5]:
#Get all the settings as a dictionary
Settings.to_dict()
[5]:
{'version': '1.0.0',
 'label_def': {'goodrecord': {'label': 'ok',
   'numeric_val': 0,
   'plot_as': 'line',
   'plotkwargs': {'zorder': 1.2, 'color': '#07f72b', 'ls': '-'}},
  'uncheckedrecord': {'label': 'not checked',
   'numeric_val': 1,
   'plot_as': 'line',
   'plotkwargs': {'zorder': 1.2, 'color': '#f7cf07', 'ls': '-'}},
  'duplicated_timestamp': {'label': 'duplicated timestamp outlier',
   'numeric_val': 2,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#a32a1f', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'gross_value': {'label': 'gross value outlier',
   'numeric_val': 3,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#f1ff2b', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'persistence': {'label': 'persistence outlier',
   'numeric_val': 4,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#f0051c', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'repetitions': {'label': 'repetitions outlier',
   'numeric_val': 5,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#056ff0', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'step': {'label': 'in step outlier group',
   'numeric_val': 6,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#05d4f0', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'window_variation': {'label': 'in window variation outlier group',
   'numeric_val': 7,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#05f0c9', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'buddy_check': {'label': 'buddy check outlier',
   'numeric_val': 8,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#8300c4', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'buddy_check_with_safetynets': {'label': 'buddy check (with safetynets) outlier',
   'color': '#8300c4',
   'numeric_val': 9,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#8300c4', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'outlier': {'label': 'QC outlier',
   'agg_def': True,
   'numeric_val': 10,
   'plot_as': 'scatter',
   'plotkwargs': {'color': '#f20000', 'marker': '.', 's': 2, 'zorder': 1.5}},
  'regular_gap': {'label': 'gap',
   'numeric_val': 11,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#f00592',
    'ls': '-',
    'linewidth': 2,
    'zorder': 1.0}},
  'interpolated_gap': {'label': 'interpolation',
   'numeric_val': 12,
   'plot_as': 'line',
   'plotkwargs': {'color': '#d406c6',
    'ls': '--',
    'linewidth': 2,
    'zorder': 1.3}},
  'failed_interpolation_gap': {'label': 'failed interpolation',
   'numeric_val': 13,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#d406c6', 'linewidth': 2, 'zorder': 1.1}},
  'raw_modeldata_fill': {'label': 'raw modeldata fill',
   'numeric_val': 14,
   'plot_as': 'line',
   'plotkwargs': {'color': '#6e1868',
    'ls': '--',
    'linewidth': 2,
    'zorder': 1.3}},
  'failed_raw_modeldata_fill': {'label': 'failed raw modeldata fill',
   'numeric_val': 15,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#6e1868', 'linewidth': 2, 'zorder': 1.1}},
  'debias_modeldata_fill': {'label': 'debiased modeldata fill',
   'numeric_val': 16,
   'plot_as': 'line',
   'plotkwargs': {'color': '#6e1868',
    'ls': '--',
    'linewidth': 2,
    'zorder': 1.3}},
  'failed_debias_modeldata_fill': {'label': 'failed debiased modeldata fill',
   'numeric_val': 17,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#6e1868', 'linewidth': 2, 'zorder': 1.1}},
  'diurnal_debias_modeldata_fill': {'label': 'diurnal debiased modeldata fill',
   'numeric_val': 18,
   'plot_as': 'line',
   'plotkwargs': {'color': '#6e1868',
    'ls': '--',
    'linewidth': 2,
    'zorder': 1.3}},
  'failed_diurnal_debias_modeldata_fill': {'label': 'failed diurnal debiased modeldata fill',
   'numeric_val': 19,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#6e1868', 'linewidth': 2, 'zorder': 1.1}},
  'weighted_diurnal_debias_modeldata_fill': {'label': 'Weighted diurnal debiased modeldata fill',
   'numeric_val': 20,
   'plot_as': 'line',
   'plotkwargs': {'color': '#6e1868',
    'ls': '--',
    'linewidth': 2,
    'zorder': 1.3}},
  'failed_weighted_diurnal_debias_modeldata_fill': {'label': 'failed Weighted diurnal debiased modeldata fill',
   'numeric_val': 21,
   'plot_as': 'vline',
   'plotkwargs': {'color': '#6e1868', 'linewidth': 2, 'zorder': 1.1}}},
 'gapfill_label_group': ['interpolated_gap',
  'raw_modeldata_fill',
  'debias_modeldata_fill',
  'diurnal_debias_modeldata_fill',
  'weighted_diurnal_debias_modeldata_fill'],
 'failed_gapfill_label_group': ['failed_interpolation_gap',
  'failed_raw_modeldata_fill',
  'failed_debias_modeldata_fill',
  'failed_diurnal_debias_modeldata_fill',
  'failed_weighted_diurnal_debias_modeldata_fill'],
 'qc_label_group': ['duplicated_timestamp',
  'gross_value',
  'persistence',
  'repetitions',
  'step',
  'window_variation',
  'buddy_check',
  'buddy_check_with_safetynets'],
 'log_level': 'WARNING',
 'log_format': 'LOG:: %(levelname)s - %(message)s',
 'store_tz': 'UTC',
 'print_config': {'max_width': 80, 'item_indent': '  ', 'title_char': '='},
 'plotting_settings': {'coloring': {'categorical_cmap': 'tab20'},
  'time_series': {'figkwargs': {'figsize': (15, 5), 'tight_layout': True},
   'legendkwargs': {'loc': 'upper center',
    'bbox_to_anchor': (0.5, -0.15),
    'ncol': 5,
    'frameon': False},
   'linekwargs': {'linewidth': 2}},
  'pie_charts': {'figkwargs': {'figsize': (10, 10), 'tight_layout': True},
   'ncols': 4,
   'radius_big': 1.0,
   'radius_small': 0.7,
   'txt_size_big_pies': 7,
   'txt_size_small_pies': 5},
  'cycle_plot': {'figkwargs': {'figsize': (15, 10), 'tight_layout': True},
   'legendkwargs': {'loc': 'upper center',
    'bbox_to_anchor': (0.5, -0.15),
    'ncol': 5},
   'linekwargs': {'linewidth': 2},
   'hlinekwargs': {'y': 0,
    'color': 'black',
    'linestyle': '--',
    'zorder': 0.9,
    'linewidth': 0.8}}}}

We can also use the typical MetObs-toolkit syntax: the Settings.get_info() method to print out an overview.

Accessing individual settings (navigation as a nested dictionary, with . as separation for keys at hierarchical levels) is done via the Settings.get() method.

[6]:
print('The MetObs toolkit version is: ', Settings.get('version'))
print('The color for repetitions errors in plots is: ', Settings.get('label_def.repetitions.plotkwargs.color'))
The MetObs toolkit version is:  1.0.0
The color for repetitions errors in plots is:  #056ff0

Overwriting default settings#

You can overwrite individual settings by using the Settings.set() method.

[7]:
Settings.set(key='label_def.repetitions.plotkwargs.color', value='magenta')

We can see that the specific setting is updated.

[8]:
Settings.get('label_def.repetitions.plotkwargs.color')
[8]:
'magenta'

Resetting settings back to default#

If you want to reset the settings back to their default values, you can simply use the Settings.reset() method. If you only want to reset a specific setting back to the default value, you can do so by specifying the key. If no key is specified, all settings are reset to their default values.

[9]:
Settings.reset() #Set all settings back to default values
Settings.get('label_def.repetitions.plotkwargs.color')
[9]:
'#056ff0'