dvas package

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Subpackages

Submodules

dvas.dvas module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Package facade

class dvas.dvas.Log

Bases: object

Facade class for user interactions with log

static start_log(mode=1, level='INFO')

Starts the dvas logging.

Parameters:
  • mode (int) – Log output mode. 0 (No log) | 1 (Log to file only) | 2 (Log to file + console) | 3 (Log to console only). Defaults to 1.

  • level (str) – Log level. Allowed: ‘DEBUG’|’D’|’INFO’|’I’|’WARNING’|’WARN’|’W’|’ERROR’|’E’. Defaults to ‘INFO’

static stop_log()

Stop logging

class dvas.dvas.Database

Bases: object

Facade class for user interactions with database.

static init()

Initialize the dvas DB.

static refresh_db()

Refreshes the database, by deleting the existing tables and reloading them from the existing metadata.

static fetch_original_data(search_prms, strict=True)

Fetch new original data and save to DB

Parameters:
  • search_prms (str | list of str) – Search parameter value.

  • strict (bool, optional) – Search strict. Defaults to True.

static explore()

Explore DB method

static extract_global_view()

Extract global DB view

Returns:

pd.DataFrame

class dvas.dvas.MultiProfile

Bases: MultiProfile

Facade class for user interactions with MultiProfile

class dvas.dvas.MultiRSProfile

Bases: MultiRSProfile

Facade class for user interactions with MultiRSProfile

class dvas.dvas.MultiGDPProfile

Bases: MultiGDPProfile

Facade class for user interactions with MultiGDPProfile

dvas.dynamic module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: dvas dynamic variables

dvas.dynamic.DATA_IN_DB = True

whether the profile data should be stored in the db, or in individual text file on disk.

Type:

bool

dvas.environ module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

class dvas.environ.ABCSingleInstanceMeta(name, bases, namespace, /, **kwargs)

Bases: ABCMeta, SingleInstanceMetaClass

Child Meteclass from ABCMeta and SingleInstanceMetaClass

class dvas.environ.VariableManager(*args, **kwargs)

Bases: ABC

Class to manage variables

Note

Need to initialize attributes in child __init__(), in order to call properly set_default_attr() in parent __init__().

get_attr()

Return current attributes

set_default_attr()

Set attribute from _attr_def. Try first to get attribute value from environment. All attributes can be defined in environment variables using <package name>_<attribute name> in upper case.

protect()

Context manager to protect temporarily global variables. When existing the context manager, old values are restored.

class dvas.environ.GlobalPathVariablesManager(*args, **kwargs)

Bases: VariableManager

Class to manage package’s global directory path variables

orig_data_path

Original data path. Default to None.

Type:

pathlib.Path

config_dir_path

Config dir path. Default to None.

Type:

pathlib.Path

local_db_path

Local db dir path. Default to None.

Type:

pathlib.Path

output_path

DVAS output dir path. Default to None.

Type:

pathlib.Path

plot_output_path

DVAS output dir path for plots. Default to None.

Type:

pathlib.Path

plot_style_path

Plot styles dir path. Default to ./plot/mpl_styles.

Type:

pathlib.Path

class dvas.environ.GlobalPackageVariableManager(*args, **kwargs)

Bases: VariableManager

Class used to manage package global variables

config_gen_max

Config regexp generator limit. Default to 2000.

Type:

int

csv_file_ext

CSV file allowed extensions. Default to [‘csv’, ‘txt’]

Type:

list of str

config_file_ext

Config file allowed extensions. Default to [‘yml’, ‘yaml’]

Type:

list of str

flg_file_ext

Flag file allowed extensions. Default to [‘flg’]

Type:

list of str

eid_pat

Event ID pattern used in InfoManager to extract event tag.

Type:

str

rid_pat

Rig ID pattern used in InfoManager to extract rig tag.

Type:

str

tod_pat

TimeOfDay ID pattern used in InfoManager to extract rig tag.

Type:

str

dvas.environ.path_var = <dvas.environ.GlobalPathVariablesManager object>

Global variable containing directory path values

Type:

GlobalPathVariablesManager

dvas.environ.glob_var = <dvas.environ.GlobalPackageVariableManager object>

Global variable containing global package variables

Type:

GlobalPackageVariableManager

dvas.errors module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Error management

exception dvas.errors.DvasError

Bases: Exception

General exception class for dvas.

exception dvas.errors.ConfigError

Bases: DvasError

Exception for error in config

exception dvas.errors.ConfigPathError

Bases: ConfigError

Exception for error in config file path

exception dvas.errors.ConfigReadError

Bases: ConfigError

Error while reading config

exception dvas.errors.ConfigReadYAMLError

Bases: ConfigReadError

Exception for error in reading YAML file

exception dvas.errors.ConfigCheckJSONError

Bases: ConfigReadError

Exception for error in checking JSON

exception dvas.errors.ConfigGenMaxLenError

Bases: ConfigReadError

Exception class for max length config generator error

exception dvas.errors.ConfigNodeError

Bases: ConfigError

Error in config node

exception dvas.errors.ConfigGetError

Bases: ConfigError

Error in get config value

exception dvas.errors.ConfigLabelNameError

Bases: ConfigGetError

Error in config label name

exception dvas.errors.ExprInterpreterError

Bases: ConfigError

Error in expression interpreter

exception dvas.errors.NonTerminalExprInterpreterError

Bases: ExprInterpreterError

Error in non terminal expression interpreter

exception dvas.errors.TerminalExprInterpreterError

Bases: ExprInterpreterError

Error in terminal expression interpreter

exception dvas.errors.LogDirError

Bases: DvasError

Exception for error in creating log directory

exception dvas.errors.DBError

Bases: DvasError

Exception for dvas database error

exception dvas.errors.DBIOError

Bases: DBError

Exception for dvas database IOError

exception dvas.errors.SearchError

Bases: DBError

Exception for dvas database search error

exception dvas.errors.ProfileError

Bases: DvasError

Exception for dvas profile error

exception dvas.errors.LoadError

Bases: DvasError

Exception for dvas load error

dvas.hardcoded module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: hardcoded parameters and variables for dvas.

dvas.hardcoded.PKG_PATH = PosixPath('/home/runner/work/dvas/dvas/src/dvas')

Package path

Type:

pathlib.Path

dvas.hardcoded.MPL_STYLES_PATH = PosixPath('plots/mpl_styles')

Matplotlib plots styles

Type:

pathlib.Path

dvas.hardcoded.CONFIG_GEN_LIM = 10000

Config generator limit

Type:

int

dvas.hardcoded.GDP_FILE_EXT = 'nc'

GDP file extension

Type:

str

dvas.hardcoded.CSV_FILE_EXT = ['csv', 'txt', 'cor']

Data file extension

Type:

list of str

dvas.hardcoded.FLG_FILE_EXT = ['flg']

Flag data file extension

Type:

list of str

dvas.hardcoded.CONFIG_FILE_EXT = ['yml', 'yaml']

Config file extension

Type:

list of str

dvas.hardcoded.EID_PAT = '^e:\\w+$'

Event id regexp pattern

Type:

str

dvas.hardcoded.EID_LEN = 8

‘ + 6 GRUAN id digits

Type:

int

Type:

Len of the eid tag, comprised of ‘e

dvas.hardcoded.RID_PAT = '^r:\\w+$'

Rig id regexp pattern

Type:

str

dvas.hardcoded.TOD_PAT = '^tod:\\w+$'

TimeOfDay regexp pattern

Type:

str

dvas.hardcoded.TOD_VALS = ('tod:daytime', 'tod:nighttime', 'tod:twilight')

possible values for the TimeOfDay

Type:

set

dvas.hardcoded.FLG_PRM_NAME_SUFFIX = '_flag'

Suffix used for flag parameter’s name or file’s name

Type:

str

dvas.hardcoded.FLG_PRM_DESC_PREFIX = 'Flag of '

Suffix used for flag parameter’s desc

Type:

str

dvas.hardcoded.MODEL_PAT = '[a-zA-Z0-9]+(([a-zA-Z0-9])|([\\-\\_\\(\\)]))*[a-zA-Z0-9]'

Instrument type pattern (e.g. VAI-RS92, MET_LAB-C50, RS92-GDP_002)

Type:

str

dvas.hardcoded.CSV_FILE_MDL_PAT = '^([a-zA-Z0-9]+(([a-zA-Z0-9])|([\\-\\_\\(\\)]))*[a-zA-Z0-9])\\.[\\w\\-]+\\.'

CSV file model catching group pattern (e.g RS41.etc…, DFM-17.etc …)

Type:

str

dvas.hardcoded.GDP_FILE_MDL_PAT = '^[A-Z]{3}\\-[A-Z]{2}\\-\\d{2}\\_\\d\\_([\\w\\-]+\\_\\d{3})\\_\\d{8}T'

GDP file model catching group pattern (e.g PAY-RS-01_2_RS41-GDP-BETA_001_20170712Tetc.nc)

Type:

str

dvas.hardcoded.PRM_PAT = '[a-z0-9]+(([a-z0-9])|([\\_]))*(?:(?<!_flag))'

Parameter pattern (e.g. tre200s0, uorpros1, uorprosu_r)

Type:

str

dvas.hardcoded.FLG_PRM_PAT = '[a-z0-9]+(([a-z0-9])|([\\_]))*(?:(?<=_flag))'

Flag parameter pattern (e.g. tre200s0, tre200s0_flag, uorpros1, uorpros1_flag)

Type:

str

dvas.hardcoded.PRM_AND_FLG_PRM_PAT = '(?:(([a-z0-9]+(([a-z0-9])|([\\_]))*(?:(?<!_flag)))|([a-z0-9]+(([a-z0-9])|([\\_]))*(?:(?<=_flag)))))'

Parameter and flag parameter pattern (e.g. tre200s0, tre200s0_flag, uorpros1, uorpros1_flag)

Type:

str

dvas.hardcoded.PRF_IDX = '_idx'

Name of the integer index for the pandas DataFrame of Profiles, RSProfile, GDPProfiles

Type:

str

dvas.hardcoded.PRF_TDT = 'tdt'

Name of the time delta index for the pandas DataFrame of RSProfile, GDPProfiles

Type:

str

dvas.hardcoded.PRF_ALT = 'alt'

Name of the altitude index for the pandas DataFrame of Profiles, RSProfile, GDPProfiles

Type:

str

dvas.hardcoded.PRF_VAL = 'val'

Name of the variable column for the pandas DataFrame of Profiles, RSProfile, GDPProfiles

Type:

str

dvas.hardcoded.PRF_UCS = 'ucs'

Name of the Spatial-correlated uncertainty column for the pandas DataFrame of GDPProfiles

Type:

str

dvas.hardcoded.PRF_UCT = 'uct'

Name of the Temporal-correlated uncertainty column for the pandas DataFrame of GDPProfiles

Type:

str

dvas.hardcoded.PRF_UCU = 'ucu'

Name of the uncorrelated uncertainty column for the pandas DataFrame of GDPProfiles

Type:

str

dvas.hardcoded.PRF_FLG = 'flg'

Name of the flag column for the pandas DataFrame of Profiles, RSProfile, GDPProfiles

Type:

str

dvas.hardcoded.TAG_NONE = ''

Tag name for none tag in DB

Type:

str

dvas.hardcoded.TAG_NONE_DESC = 'None'

Tag desc for none tag in DB

Type:

str

dvas.hardcoded.TAG_ORIGINAL = 'is_original'

Tag name for original profiles

Type:

str

dvas.hardcoded.TAG_ORIGINAL_DESC = 'Original profile unaltered by dvas'

Tag desc for original profiles

Type:

str

dvas.hardcoded.TAG_CLN = 'is_cleaned'

Tag name for cleaned profiles

Type:

str

dvas.hardcoded.TAG_CLN_DESC = 'Cleaned-up profile'

Tag desc for cleaned profiles

Type:

str

dvas.hardcoded.TAG_1S = 'is_resampled'

Tag name for resampled profiles.

Type:

str

dvas.hardcoded.TAG_1S_DESC = 'Profile is resampled onto a regular time-step grid'

Tag description for resampled profiles.

Type:

str

dvas.hardcoded.TAG_SYNC = 'is_synchronized'

Tag name for synchronized profile

Type:

str

dvas.hardcoded.TAG_SYNC_DESC = 'Synchronized profile'

Tag desc for synchronized profile

Type:

str

dvas.hardcoded.TAG_GDP = 'is_gdp'

Tag name for GDP profiles

Type:

str

dvas.hardcoded.TAG_GDP_DESC = 'GRUAN Data Product'

Tag desc for GDP profiles

Type:

str

dvas.hardcoded.TAG_CWS = 'is_cws'

Tag name for combined working standard profile

Type:

str

dvas.hardcoded.TAG_CWS_DESC = 'Combined working measurement standard'

Tag desc for combined working standard profile

Type:

str

dvas.hardcoded.TAG_DTA = 'is_delta'

Tag name for profile deltas with CWS

Type:

str

dvas.hardcoded.TAG_DTA_DESC = 'Profile minus CWS'

Tag desc for profile deltas with CWS

Type:

str

dvas.hardcoded.TAG_EMPTY = 'is_empty'

Tag name for empty original data

Type:

str

dvas.hardcoded.TAG_EMPTY_DESC = 'Empty data'

Tag desc for empty original data

Type:

str

dvas.hardcoded.FLG_NOPRF = 'no_original_data'

Flag name for when we have no original data (i.e. synced gaps, etc …)

Type:

str

dvas.hardcoded.FLG_NOPRF_DESC = 'No original data existing for this point (i.e. out of bound)'

Flag desc for no data

Type:

str

dvas.hardcoded.FLG_ISINVALID = 'is_invalid'

Flag name for invalid values

Type:

str

dvas.hardcoded.FLG_ISINVALID_DESC = 'Invalid data (e.g. NaN value for real GDP measurement)'

Flag desc for invalid values

Type:

str

dvas.hardcoded.FLG_WASINVALID = 'was_invalid'

Flag name for invalid values

Type:

str

dvas.hardcoded.FLG_WASINVALID_DESC = 'Invalid data (e.g. NaN uct value for real GDP gph measurement) that was corrected following official GRUAN instructions'

Flag desc for invalid values

Type:

str

dvas.hardcoded.FLG_INTERP = 'is_interpolated'

Flag name for interpolated values

Type:

str

dvas.hardcoded.FLG_INTERP_DESC = 'Interpolated values'

Flag desc for interpolated values

Type:

str

dvas.hardcoded.FLG_INCOMPATIBLE = 'is_GDP_incompatible'

Flag name for resampled values

Type:

str

dvas.hardcoded.FLG_INCOMPATIBLE_DESC = 'GDPs are incompatible with one another'

Flag desc for resampled values

Type:

str

dvas.hardcoded.FLG_HASCWS = 'has_valid_cws'

Flag name for regions with valid CWS

Type:

str

dvas.hardcoded.FLG_HASCWS_DESC = 'A valid CWS measure exists for this measurement point'

Flag desc

Type:

str

dvas.hardcoded.FLG_PRELAUNCH = 'is_prelaunch_data'

Flag name for ascent data

Type:

str

dvas.hardcoded.FLG_PRELAUNCH_DESC = 'Prelaunch data'

Flag desc for ascent data

Type:

str

dvas.hardcoded.FLG_ASCENT = 'is_ascent_data'

Flag name for ascent data

Type:

str

dvas.hardcoded.FLG_ASCENT_DESC = 'Ascent data'

Flag desc for ascent data

Type:

str

dvas.hardcoded.FLG_DESCENT = 'is_descent_data'

Flag name for descent data

Type:

str

dvas.hardcoded.FLG_DESCENT_DESC = 'Descent data'

Flag desc for descent data

Type:

str

dvas.hardcoded.FLG_PBL = 'is_in_PBL'

Flag name for PBL points

Type:

str

dvas.hardcoded.FLG_PBL_DESC = 'Measurement is in the PBL (i.e. x < PBLH)'

Flag desc for PBL points

Type:

str

dvas.hardcoded.FLG_FT = 'is_in_FT'

Flag name for free troposphere points

Type:

str

dvas.hardcoded.FLG_FT_DESC = 'Measurement is in the FT (i.e. x < tropopause and x > PBLH)'

Flag desc for free troposphere points

Type:

str

dvas.hardcoded.FLG_UTLS = 'is_in_UTLS'

Flag name for UTLS points

Type:

str

dvas.hardcoded.FLG_UTLS_DESC = 'Measurement is in the UTLS'

Flag desc for UTLS points

Type:

str

dvas.hardcoded.FLG_MUS = 'is_in_MUS'

Flag name for MUS points

Type:

str

dvas.hardcoded.FLG_MUS_DESC = 'Measurement is in the MUS'

Flag desc for MUS points

Type:

str

dvas.hardcoded.MTDTA_FIRST = 'first_timestamp'

Metdata field to store the GNSS time of the first point in the profile.

Type:

str

dvas.hardcoded.MTDTA_LAUNCH = 'launch_timestamp'

Metadata field to store the GNSS time of the manufacturer-detected launch.

Type:

str

dvas.hardcoded.MTDTA_BURST = 'burst_timestamp'

Metadata field to store the GNSS time of the manufacturer-detected balloon burst.

Type:

str

dvas.hardcoded.MTDTA_TROPOPAUSE = 'dvas_tropopause'

Metadata field to store the tropopause geopotential height

Type:

str

dvas.hardcoded.MTDTA_PBLH = 'dvas_PBLH'

Metadata field to store the tropopause geopotential height

Type:

str

dvas.hardcoded.MTDTA_UTLSMIN = 'dvas_UTLS_min'

Metadata field to store the min geopotential height of the UTLS region

Type:

str

dvas.hardcoded.MTDTA_UTLSMAX = 'dvas_UTLS_max'

Metadata field to store the max geopotential height of the UTLS region

Type:

str

dvas.hardcoded.MTDTA_MUSMIN = 'dvas_MUS_min'

Metadata field to store the max geopotential height of the UTLS region

Type:

str

dvas.hardcoded.MTDTA_SYNOP = 'synop_clouds'

Metadata field to store the synop cloud code

Type:

str

dvas.helper module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Package helper classes and functions.

dvas.helper.camel_to_snake(name)

Convert camel case to snake case

Parameters:

name (str) – Camel case string

Returns:

str

class dvas.helper.SingleInstanceMetaClass

Bases: type

Metaclass to create single instance of class

classmethod has_instance(inst)

Check if instance

Parameters:

inst (type) – Instance type to check

class dvas.helper.RequiredAttrMetaClass(name, bases, namespace, /, **kwargs)

Bases: ABCMeta

Meta class for requiring specific attribute to abstract parent class

Use this meta abstract class to construct a parent abstract class to require special attributes into children.

REQUIRED_ATTRIBUTES = {}

Required class attributes. key: attribute name, value: required attribute type

Type:

dict

__init__(*args, **kwargs)

Without this __init__ function, the Child classes all show the init signature of the __call__ method below, when accessing their help.

This corrects this unwanted behavior (see #84 for details).

Adapted from the reply of johnbaltis on SO .

class dvas.helper.ContextDecorator

Bases: ABC

Use this class as superclass of a context manager to convert it into a decorator.

__init__()

Abstract constructor

property func

Contain the decorated function. Set automatically only when class is used as decorated. Default to None.

Type:

callable

class dvas.helper.TimeIt(header_msg='', logger=None)

Bases: AbstractContextManager

Code elapsed time calculator context manager.

__init__(header_msg='', logger=None)

Constructor.

Parameters:
  • header_msg (str) – User defined elapsed time header. Default to ‘’.

  • logger (logging.Logger, optional) – Print output to log (debug level only). Defaults to None.

dvas.helper.deepcopy(func)

Use a deepcopy of the class when calling a given “func” function.

Intended to be used as a decorator, that will “correctly” handle the decorated function signature AND its docstring.

Note

This implementation was inspired by the following sources:

class dvas.helper.TypedProperty(match, setter_fct=None, args=None, kwargs=None, getter_fct=None, allow_none=False)

Bases: object

Typed property class

Note

Adapted from Stackoverflow.

__init__(match, setter_fct=None, args=None, kwargs=None, getter_fct=None, allow_none=False)

Constructor

Parameters:
  • match (type or types.UnionType) – Data type(s), used in a isinstance check

  • setter_fct (callable, optional) – Function applied before assign value in setter method. The function can include special check and raises - use TypeError to raise appropriate exception. Default to lambda x: x

  • args (tuple, optional) – setter function args. Default to None.

  • kwargs (dict, optional) – setter function kwargs. Default to None.

  • getter_fct (callable, optional) – Function applied before returning attributes in getter method. Default to lambda x: x

  • allow_none (bool, optional) – Allow none value (bypass pampy match and setter fct). Defaults to False.

Note

pampy no longer used from v0.6 onwards …

dvas.helper.get_by_path(root, items, sep='.')

Access a nested object in root by item sequence.

Parameters:
  • root (dict|list|class) – Object to access

  • items (list|str) – Item sequence. String sequence must be separated by sep value.

  • sep (str, optional) – Separator.

Returns:

object – Nested value

Raises:

Exception associated to lists and dicts.

Examples: >>>get_by_path([1,[2,3]], [1, 0]) 2

>>>get_by_path({‘a’: [0, 1]}, [‘a’, 0]) 0

>>>get_by_path({‘a’: {‘b’: 1, ‘c’:0}}, [‘a’, ‘c’]) 0

>>>get_by_path({‘a’: {‘b’: 1, ‘c’:0}}, ‘a.c’) 0

dvas.helper.check_path(value, exist_ok=False)

Test and set input argument into pathlib.Path object.

Parameters:
  • value (pathlib.Path, str) – Argument to be tested

  • exist_ok (bool, optional) – If True check existence. Default to False.

Returns:

pathlib.Path

Raises:

TypeError – In case if path does not exist falls exist_ok is True

dvas.helper.check_datetime(val, utc=True)

Test and set input argument into datetime.datetime.

Parameters:
  • val (str | datetime | pd.Timestamp) – Datetime

  • utc (bool) – Check UTC. Default to True.

Returns:

datetime.datetime

dvas.helper.unzip(val)

Unzip list of tuple

Parameters:

val (list of tuples) – Zipped list

Returns:

list

dvas.helper.get_dict_len(val)

Return the length of a dict (recursively)

Parameters:

val (dict) – Dict to get length

Returns:

int

dvas.helper.get_class_public_attr(obj)

Get public attributes from an object

Returns:

dict

class dvas.helper.AttrDict(*args, **kwargs)

Bases: dict

Dictionary keys like an attribute

dvas.logger module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Logging management

class dvas.logger.DeltaTimeFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Bases: Formatter

Delta time formatter

Note

Adapted from StackOverflow. Author: Keith

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class dvas.logger.DvasFormatter(colors=False)

Bases: Formatter

The custom logging formatter class for dvas. To handle time deltas AND colors.

__init__(colors=False)

Init function.

Parameters:

colors (bool, optional) – if True, will add colors to the log message via ANSI codes. Defaults to False.

log_msg(level=20)

Return the dvas log message canvas, possibly with colors and stuff.

Parameters:

level (logging.lvl, optional) – the log level, e.g. logging.INFO, logging.ERROR, …

Returns:

DeltaTimeFormatter – the formatted log message canvas.

format(record)

Format the log message as required

dvas.logger.apply_dvas_formatter(handler, colors=False)

A small routine responsible for apply a custom formatter to a given logging handler.

class dvas.logger.LogManager(mode, level)

Bases: object

Class for log management

__init__(mode, level)

Args: mode (int): Log output mode. level (str): Log level.

log_mode

Log output mode. Defaults to 1. No log: False|0 Log to file only: True|1 Log to file + console: 2 Log to console only: 3

Type:

str

log_level

Log level. Default to ‘INFO’

Type:

str

init_log()

Function used to initialize logger

static get_console_handler()

Return the console handler

static get_file_handler()

Return the log file handler

static get_logger(name)

Get logger

static clear_log()

Function used to clear log

dvas.logger.log_func_call(logger, time_it=False, level='info')

Intended as a decorator that logs a function call the the log. The first part of the message containing the function name is at the ‘INFO’ level. The second part of the message containing the argument values is at the ‘DEBUG’ level.

Parameters:
  • logger (str) – one of the loggers defined in dvas_logger.py, e.g.: gruan_logger

  • time_it (bool, optional) – whether to evaluate the decorated function execution time (and log it), or not. Default to False.

Note

Adapted from this post on SO, in particular the reply from Kfir Eisner and Peter Mortensen. See also this.

dvas.version module

Copyright (c) 2020-2023 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Version of the package.