eva.utilities package#

Submodules#

eva.utilities.config module#

class eva.utilities.config.Config(dict_or_yaml, logger)[source]#

Bases: dict

Class containing a configuration for tasks.

Initialize the Config object.

Parameters:
  • dict_or_yaml (dict or str) – Either a dictionary containing configuration parameters or the path to a YAML file containing the configuration.

  • logger (Logger) – An instance of the logger to handle log messages.

Returns:

None

get(key, default=None, abort_on_failure=True)[source]#

Get the value associated with a key from the configuration.

Parameters:
  • key (str) – The key for which the value needs to be retrieved from the configuration.

  • default – The default value to return if the key is not found in the configuration.

  • abort_on_failure (bool) – If True, aborts the program if the key is not found.

Returns:

The value associated with the key if found, otherwise the default value.

eva.utilities.config.get(dict, logger, key, default=None, abort_on_failure=True)[source]#

Get the value associated with a key from a given dictionary.

Parameters:
  • dict (dict) – The dictionary from which the value needs to be retrieved.

  • logger (Logger) – An instance of the logger to handle log messages.

  • key (str) – The key for which the value needs to be retrieved from the dictionary.

  • default – The default value to return if the key is not found in the dictionary.

  • abort_on_failure (bool) – If True, aborts the program if the key is not found.

Returns:

The value associated with the key if found, otherwise the default value.

eva.utilities.ioda_definitions module#

eva.utilities.ioda_definitions.find_instrument_from_string(full_string)[source]#

Find the matching IODA instrument ID and its corresponding variable from a given string.

Parameters:

full_string (str) – The input string to search for platform codes.

Returns:

A tuple containing the found platform code and its corresponding variable,

or None if no match is found.

Return type:

tuple or None

eva.utilities.ioda_definitions.ioda_group_dict(ioda_group, logger)[source]#

Get the description of an IODA group based on its code.

Parameters:
  • ioda_group (str) – The IODA group name.

  • logger (Logger) – An instance of the logger to handle log messages.

Returns:

The description of the IODA group.

Return type:

str

eva.utilities.ioda_definitions.ioda_platform_dict()[source]#

Get a dictionary mapping IODA instrument IDs to their corresponding full names.

Returns:

A dictionary mapping platform codes to their corresponding full names.

Return type:

dict

eva.utilities.ioda_definitions.ioda_platform_to_full_name(ioda_platform, logger)[source]#

Convert an IODA instrument ID to its corresponding full name.

Parameters:
  • ioda_platform (str) – The IODA platform code.

  • logger (Logger) – An instance of the logger to handle log messages.

Returns:

The corresponding full name of the IODA platform code.

Return type:

str

eva.utilities.ioda_netcdf_api module#

eva.utilities.ioda_netcdf_api.read_ioda_variable(fh, group, variable, channel=None)[source]#

Read an IODA variable from a specified group and channel (if applicable).

Parameters:
  • fh – The IODA file handle.

  • group (str) – The IODA group from which to read the variable.

  • variable (str) – The variable to be read.

  • channel (int or None) – The channel number for the variable if applicable. Default is None.

Returns:

The data read from the IODA variable.

Return type:

ndarray

eva.utilities.logger module#

class eva.utilities.logger.Logger(task_name)[source]#

Bases: object

Class providing logging functionality for tasks.

Initialize the Logger object.

Parameters:

task_name (str) – The name of the task associated with the logger.

Returns:

None

abort(message)[source]#

Print an abort log message and exit the program.

Parameters:

message (str) – The abort log message.

Returns:

None

debug(message)[source]#

Print a debug log message.

Parameters:

message (str) – The debug log message.

Returns:

None

info(message)[source]#

Print an informational log message.

Parameters:

message (str) – The informational log message.

Returns:

None

send_message(level, message)[source]#

Print a log message at the specified logging level.

Parameters:
  • level (str) – The logging level for the message.

  • message (str) – The log message to be printed.

Returns:

None

trace(message)[source]#

Print a trace log message.

Parameters:

message (str) – The trace log message.

Returns:

None

class eva.utilities.logger.textcolors[source]#

Bases: object

A class that defines color codes for text in the terminal.

blue = '\x1b[94m'#
cyan = '\x1b[96m'#
end = '\x1b[0m'#
green = '\x1b[92m'#

eva.utilities.stats module#

eva.utilities.stats.get_field_data(logger, field, data_collections)[source]#

Retrieve field data based on the field configuration.

Parameters:
  • logger (Logger) – The logger object for logging messages.

  • field (dict) – The field configuration containing the field name and optional channel.

  • data_collections (DataCollections) – The data collections object to retrieve data from.

Returns:

The flattened and masked field data.

Return type:

ndarray

eva.utilities.stats.stats_helper(logger, plot_obj, data_collections, config)[source]#

Add specified statistics to a plot.

Parameters:
  • logger (Logger) – The logging object.

  • plot_obj – The declarative plotting object.

  • data_collections (DataCollections) – The eva data collections object.

  • config (dict) – The input configuration dictionary.

Returns:

None

eva.utilities.timing module#

class eva.utilities.timing.Timing[source]#

Bases: object

A class for managing timing profiling of eva code.

Initialize the Timing object.

Returns:

None

finalize()[source]#

Finalize the timing measurements and log the results.

Returns:

None

start(timer_name)[source]#

Start a timer with the given name.

Parameters:

timer_name (str) – The name of the timer.

Returns:

None

stop(timer_name)[source]#

Stop a timer with the given name.

Parameters:

timer_name (str) – The name of the timer.

Returns:

None

eva.utilities.utils module#

eva.utilities.utils.camelcase_to_underscore(CamelCaseString)[source]#

Convert a CamelCase string to underscore_separated lowercase string.

Parameters:

CamelCaseString (str) – The CamelCase string to be converted.

Returns:

The underscore-separated lowercase string.

Return type:

str

class eva.utilities.utils.fontColors[source]#

Bases: object

bold = '\x1b[1m'#
end = '\x1b[0m'#
underline = '\x1b[4m'#
eva.utilities.utils.get_schema(YamlFile, configDict={}, logger=None)[source]#

Read a YAML file into a dictionary containing a configuration and overwrite the default configuration with the input configDict.

Parameters:
  • YamlFile (str) – Path to the YAML file.

  • configDict (dict, optional) – Dictionary of configuration options to overwrite defaults. Defaults to an empty dictionary.

  • logger (Logger, optional) – The logger object for logging messages. Defaults to None.

Returns:

A dictionary containing the configuration.

Return type:

dict

eva.utilities.utils.is_number(s)[source]#

Check if a given value can be converted to a number.

Parameters:

s – The value to be checked.

Returns:

True if the value can be converted to a number, False otherwise.

Return type:

bool

eva.utilities.utils.load_yaml_file(eva_config, logger)[source]#

Load a YAML file into a dictionary.

Parameters:
  • eva_config (str) – Path to the YAML file.

  • logger (Logger) – The logger object for logging messages.

Returns:

A dictionary containing the contents of the YAML file.

Return type:

dict

eva.utilities.utils.parse_channel_list(channels_str_or_list, logger)[source]#

Parse the input channels_str_or_list and return a list of channel numbers.

This function handles parsing and converting various input types into a list of channel numbers.

Parameters:
  • channels_str_or_list (list, str, int) – The input channels as a list, string, or integer.

  • logger (Logger) – The logger object for logging error messages.

Returns:

A list of channel numbers.

Return type:

list

Raises:

ValueError – If the input is not a valid list of integers or a string that can be parsed into a list of integers.

eva.utilities.utils.remove_empty_from_list_of_strings(list)[source]#

Remove empty strings from a list of strings.

Parameters:

lst (list) – The input list of strings.

Returns:

A new list with empty strings removed.

Return type:

list

eva.utilities.utils.remove_list_duplicates(input_list)[source]#

Remove duplicate elements from a list while preserving the order.

Parameters:

input_list (list) – The input list containing elements.

Returns:

A new list with duplicate elements removed while preserving the order.

Return type:

list

eva.utilities.utils.replace_vars_dict(d, **defs)[source]#

Replace variable placeholders in the dictionary values using provided definitions.

This function replaces variable placeholders in the dictionary values with their corresponding values provided in the ‘defs’ dictionary. It searches for placeholders in the dictionary values and substitutes them with their definitions.

Parameters:
  • d (dict) – The dictionary to be modified.

  • defs (dict) – A dictionary of variable definitions for resolving variables, expressed as key-word arguments.

Returns:

The modified dictionary with variable placeholders replaced by their definitions.

Return type:

dict

Example

If defs = {‘swell_dir’: ‘/path/to/swell’}, and d = {‘key’: ‘$(swell_dir)/some/file.ext’}, the returned dictionary would be {‘key’: ‘/path/to/swell/some/file.ext’}.

eva.utilities.utils.replace_vars_notebook(nb, **defs)[source]#

Replace variable placeholders in a nbconvert NotebookNode’s cell source code.

This function iterates through the cells of a nbconvert NotebookNode, searching for variable placeholders in the cell source code. Variable placeholders are then substituted with their corresponding definitions provided in the ‘defs’ dictionary.

Parameters:
  • nb (NotebookNode) – A nbconvert dict-like NotebookNode to be modified.

  • defs (dict) – A dictionary of variable definitions for resolving variables, expressed as key-word arguments.

Returns:

The modified nbconvert NotebookNode with variable placeholders in cell

source code replaced by their definitions.

Return type:

NotebookNode

Example

If defs = {‘swell_dir’: ‘/path/to/swell’}, and a cell source code contains ‘file_path = $(swell_dir)/file.txt’, the modified cell source code will be ‘file_path = /path/to/swell/file.txt’.

eva.utilities.utils.replace_vars_str(s, **defs)[source]#

Interpolate and replace variables in the input string.

This function replaces variable placeholders in the input string with their corresponding values provided in the ‘defs’ dictionary. It can handle recursive variable substitution.

Parameters:
  • s (str) – The input string containing variables to be resolved.

  • defs (dict) – A dictionary of variable definitions for resolving variables, expressed as key-word arguments.

Returns:

The interpolated string. Undefined variables are left unchanged.

Return type:

str

Example

If defs = {‘var1’: ‘value1’, ‘var2’: ‘value2’}, and s = ‘This is ${var1} and ${var2}.’, the returned string would be ‘This is value1 and value2.’

eva.utilities.utils.slice_var_from_str(config, datavar, logger)[source]#

Slice a variable from an array based on the configuration.

This function evaluates the slicing configuration and applies it to the input variable ‘datavar’.

Parameters:
  • config (dict) – The configuration dictionary containing slicing information.

  • datavar – The input variable to be sliced.

  • logger (Logger) – The logger object for logging messages.

Returns:

The sliced variable ‘datavar’.

eva.utilities.utils.string_does_not_contain(disallowed_chars, string_to_check)[source]#

Check if a string does not contain any of the specified characters.

Parameters:
  • disallowed_chars (str) – A string containing characters that should not be present in ‘string_to_check’.

  • string_to_check (str) – The string to be checked.

Returns:

True if ‘string_to_check’ does not contain any of the ‘disallowed_chars’, False

otherwise.

Return type:

bool

eva.utilities.utils.update_object(myObj, configDict, logger=None)[source]#

Update the attributes of the input object myObj based on a dictionary configDict and return a new, updated myObj.

Parameters:
  • myObj (object) – The object to be updated.

  • configDict (dict) – Dictionary containing attribute names and their corresponding values to

  • update.

  • logger (Logger, optional) – The logger object for logging messages. Defaults to None.

Returns:

The updated object with modified attributes.

Return type:

object

Module contents#