eelib.utils.eval.evaluation_utils

Useful helper methods for evaluating .hdf5 results in jupyter notebooks.

Author: elenia@TUBS
Copyright 2024 elenia
This file is part of eELib, which is free software under the terms of the GNU GPL Version 3.

Module Contents

Functions

_extract_datasets_from_group(group[, parent_name, pattern])

Recursively extract data from hdf5 file.

hdf5_file_as_pandas(path[, datetime_col, pattern])

Return a dataframe representation of the hdf5 file.

get_config(→ dict)

Return scenario configuration of the hdf5 file.

convert_hdf5_to_csv(input_path, output_path[, sep, ...])

Converts an hdf5 file with the proper format into a csv file. Uses non-compact representation

timestep_to_datetime(timestep, zero_datetime, step_size)

Converts a (numpy list of) timestep(s) to a (numpy list of) actual date(s).

save_figure(fig, ax, filename, path[, figsize, dpi, ...])

Saves a Matplotlib figure with standardized sizing and format.

_read_config(hdf5_data)

Return dictionary corresponding to Config grouping.

_extract_datasets_from_group(group, parent_name='', pattern=None)

Recursively extract data from hdf5 file.

Parameters:
  • group (Group) – The group where the search is currently occuring.

  • parent_name (str, optional) – The parent name of that group.

  • pattern (str) – regex pattern. If given, only the part matching the first grouping in the pattern remains as the name for each timeseries. Otherwise, the full path of the timeseries is used as its name.

Raises:

ValueError – if pattern is given and at least one name does not match it

Returns:

the fully formed subgroup for the current group.

Return type:

dict

hdf5_file_as_pandas(path: str, datetime_col=False, pattern=None)

Return a dataframe representation of the hdf5 file.

Parameters:
  • path (str) – hdf5 file path.

  • datetime_col (bool, optional) – determines whether a datetime column is created using the Config section of the database.

  • pattern (str) – regex pattern. If given, only the part matching the first grouping in the pattern remains as the name for each timeseries. Otherwise, the full path of the timeseries is used as its name.

Returns:

The resulting dataframe.

Return type:

Dataframe

get_config(path: str) dict

Return scenario configuration of the hdf5 file.

Parameters:

path (str) – path of the hdf5 file.

Returns:

scenario configuration dict.

Return type:

dict

convert_hdf5_to_csv(input_path: str, output_path: str, sep=',', na_rep='', datetime_col=False)

Converts an hdf5 file with the proper format into a csv file. Uses non-compact representation unless specified.

Parameters:
  • input_path (str) – path for input hdf5 file.

  • output_path (str) – path for the output csv file.

  • sep (str) – String of length 1. Field delimiter for the output file. Defaults to ‘,’.

  • na_rep (str) – Missing data representation. Defaults to ‘’.

  • datetime_col (bool) – Whether the function adds a column to dataframe to display the actual date and time in addition to timesteps. Only works if compact=True. Defaults to False

timestep_to_datetime(timestep, zero_datetime: datetime.datetime, step_size: int)

Converts a (numpy list of) timestep(s) to a (numpy list of) actual date(s).

Parameters:
  • timestep – a timestep or a numpy array of timesteps.

  • zero_datetime (datetime) – the datetime corresponding to timestep 0. Inclusion of zero in the list is not mandatory.

  • step_size (int) – size of each timestep in seconds.

Returns:

calculated date(s) corresponding to timestep(s).

Return type:

numpy.datetime64

save_figure(fig, ax, filename, path, figsize=(15, 5), dpi=300, format='svg', rasterized=True)

Saves a Matplotlib figure with standardized sizing and format.

Parameters:
  • fig (Figure) – Matplotlib figure to be saved.

  • ax (Axes) – Matplotlib ax.

  • filename (str) – Name of the output file.

  • path (str) – path of the output file.

  • figsize (tuple) – Size of the figure in inches (width, height).

  • dpi (int) – Dots per inch for image resolution.

  • format (str) – Output file format (e.g., ‘svg’, ‘png’, ‘jpg’, etc.).

  • rasterized (bool) – Whether to rasterize vector elements (True) or not (False).

_read_config(hdf5_data)

Return dictionary corresponding to Config grouping.

Parameters:

hdf5_data – data read from an hdf5 file using h5py.

Returns:

the Config as stored.

Return type:

dict