:py:mod:`eelib.utils.eval.evaluation_utils` =========================================== .. py:module:: eelib.utils.eval.evaluation_utils .. autoapi-nested-parse:: 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 ~~~~~~~~~ .. autoapisummary:: eelib.utils.eval.evaluation_utils.find_corresponding_component_dict eelib.utils.eval.evaluation_utils.find_corresponding_component eelib.utils.eval.evaluation_utils.make_compact eelib.utils.eval.evaluation_utils.hdf5_file_as_pandas eelib.utils.eval.evaluation_utils.get_config eelib.utils.eval.evaluation_utils.get_timeseries eelib.utils.eval.evaluation_utils.convert_hdf5_to_csv eelib.utils.eval.evaluation_utils.timestep_to_datetime eelib.utils.eval.evaluation_utils.save_figure eelib.utils.eval.evaluation_utils._read_config Attributes ~~~~~~~~~~ .. autoapisummary:: eelib.utils.eval.evaluation_utils.NAME_COM_DICT .. py:data:: NAME_COM_DICT .. py:function:: find_corresponding_component_dict(series_group_name: str, name_com_dict: dict = NAME_COM_DICT) Tries to infer the component that corresponds to a `series_group_name` using a dictionary of regular expressions and components. :param series_group_name: the name of the series group inside the hdf5 file. :type series_group_name: str :param name_com_dict: dictionary linking regular expressions to components. Defaults to ``NAME_COM_DICT``. :type name_com_dict: dict :returns: A string representation of the component, i.e. the value corresponding to the first regular expression in ``name_com_dict`` that matches the ``series_group_name``. Returns `"Unidentified"`, if no proper value is found. :rtype: str .. py:function:: find_corresponding_component(series_group_name: str) Tries to infer the component that corresponds to a ``series_group_name`` using a pre-defined regular expression. :param series_group_name: the name of the series group inside the ``.hdf5`` file. :type series_group_name: str :returns: (1) A string representation of the component. "Unidentified", if no proper value is found. (2) The number of the component. :rtype: str, int .. py:function:: make_compact(df: pandas.DataFrame) The function returns a compacted version of the non-compact output of `hdf5_file_as_pandas()` so the rows represent elements of timeseries and columns represent compacted names for each. :param df: non-compact dataframe. :type df: DataFrame :returns: compacted dataframe. :rtype: DataFrame .. py:function:: hdf5_file_as_pandas(path: str, pseudonyms=True, compact=False, datetime_col=False) Return a dataframe representation of the hdf5 file. :param path: path of the hdf5 file. :type path: str :param pseudonyms: If set to `True` the function also tries to infer the component corresponding to each timeseries group in the file and adds it as a column to the beginning of the dataframe. Uses `find_corresponding_component()`. Defaults to True. :type pseudonyms: bool :param compact: If set to `True` the function returns a compacted version of the pandas dataframe so the rows represent elements of timeseries and columns represent compacted names for each. Defaults to False. :type compact: bool :param datetime_col: If set to `True` 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. :type datetime_col: bool :returns: A dataframe representation of the data inside the hdf5 file. :rtype: pandas.DataFrame .. py:function:: get_config(path: str) -> dict Return scenario configuration of the hdf5 file. :param path: path of the hdf5 file. :type path: str :returns: scenario configuration dict. :rtype: dict .. py:function:: get_timeseries(dataframe: pandas.DataFrame, unit: str, component: str, number: int = 0) Extracts timeseries data from non-compact dataframe using component name, number and unit. :param dataframe: the dataframe generated from `hdf5_file_as_pandas()` method. :type dataframe: DataFrame :param unit: the name of the unit. :type unit: str :param component: the name of the component. :type component: str :param number: the number of the component. Defaults to 0. :type number: int :raises KeyError: if the column `"Component"` does not exist. :raises ValueError: if there are multiple or zero timeseries matching the inputs. :returns: the timeseries corresponding to the received component and unit. :rtype: list .. py:function:: convert_hdf5_to_csv(input_path: str, output_path: str, pseudonyms=True, sep=',', na_rep='', compact=False, datetime_col=False) Converts an hdf5 file with the proper format into a csv file. Uses non-compact representation unless specified. :param input_path: path for input hdf5 file. :type input_path: str :param output_path: path for the output csv file. :type output_path: str :param pseudonyms: If set to `True` the function also tries to infer the component corresponding to each timeseries group in the file and adds it as a column to the beginning of the dataframe. Defaults to True. :type pseudonyms: bool :param sep: String of length 1. Field delimiter for the output file. Defaults to ','. :type sep: str :param na_rep: Missing data representation. Defaults to ''. :type na_rep: str :param compact: Whether function returns a compacted version of the data - rows represent elements of timeseries and columns represent compacted names for each. Defaults to False :type compact: bool :param datetime_col: 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 :type datetime_col: bool .. py:function:: 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). :param timestep: a timestep or a numpy array of timesteps. :param zero_datetime: the datetime corresponding to timestep 0. Inclusion of zero in the list is not mandatory. :type zero_datetime: datetime :param step_size: size of each timestep in seconds. :type step_size: int :returns: calculated date(s) corresponding to timestep(s). :rtype: numpy.datetime64 .. py:function:: save_figure(fig, ax, filename, path, figsize=(15, 5), dpi=300, format='svg', rasterized=True) Saves a Matplotlib figure with standardized sizing and format. :param fig: Matplotlib figure to be saved. :type fig: Figure :param ax: Matplotlib ax. :type ax: Axes :param filename: Name of the output file. :type filename: str :param path: path of the output file. :type path: str :param figsize: Size of the figure in inches (width, height). :type figsize: tuple :param dpi: Dots per inch for image resolution. :type dpi: int :param format: Output file format (e.g., 'svg', 'png', 'jpg', etc.). :type format: str :param rasterized: Whether to rasterize vector elements (True) or not (False). :type rasterized: bool .. py:function:: _read_config(hdf5_data) Return dictionary corresponding to scenario_config. :param hdf5_data: data read from an hdf5 file using h5py. :returns: the scenario_config as stored. :rtype: dict