pipeline_functions
This module contains the functions to run the pipeline module
- This module contains:
load_config: loads the configuration parameters.
check_download: checks if the entso-e data needs to be downloaded.
load_raw_prod_exchanges: loads the raw production and exchanges data.
load_impact_matrix: loads the impact matrix.
check_mapping: checks the mapping between production and impacts.
get_mix: computes the electric mix of the target countries.
get_impacts: computes the impacts of these mixs.
get_productions : computes production values in kWh for each source.
translate_to_timezone: translates the data into the timezone.
save_results: saves the results.
localize_from_utc: shifts the time-zone from results.
- ecodynelec.pipeline_functions.check_download(parameters: Parameter, is_verbose: bool = False) None[source]
Checks if the config requires to download the entso-e data, and if so, downloads it.
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by
load_config().is_verbose (bool, default to False) – To display information
- ecodynelec.pipeline_functions.get_consuming_mix_kwh(flows_df: DataFrame, mix_df: DataFrame) DataFrame[source]
Converts a relative consumption mix to absolute values (in kWh) for the target country.
- Parameters:
flows_df (pd.DataFrame) – A dataframe containing the raw productions/imports/exports (in kWh) for each target.
mix_df (pd.DataFrame) – A dataframe containing the relative consumption mix of the target country.
- Return type:
A dataframe containing the consumption mix in kWh for the target country.
- ecodynelec.pipeline_functions.get_flows_kwh(parameters: Parameter, raw_prod_exch: DataFrame) dict[source]
Compute the total production, imports and exports for each country, in kWh, at each time step. Useful to compute the mixes in kWh (instead of %).
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
raw_prod_exch (pandas.DataFrame) – The raw production and exchange data, as returned by load_raw_prod_exchanges.
- Returns:
flows_dict – A dictionary of countries and their production/imports/exports, in kWh.
- Return type:
dict of DataFrame
- ecodynelec.pipeline_functions.get_impacts(mix_dict: dict, impact_matrix: DataFrame, missing_mapping: str = 'error', is_verbose: bool = False) dict[source]
Computes the impact of the given electrical mix.
- Parameters:
mix_dict (dict of pandas.DataFrame) – The mix for each target, as returned by get_mix.
impact_matrix (pandas.DataFrame) – The impact matrix, as returned by load_impact_matrix.
missing_mapping (str, default to ‘error’) – strategy for handling producing units with not mapping. ‘error’ (default) raises an error, ‘worst’ takes the highest impact value in the available set, ‘unit’ takes the highest impact value available from a similar unit type, defaults to ‘error’
is_verbose (bool, default to False) – To display progress information
- Returns:
imp_dict – A dictionary containing the impacts for each target. For each country, this is a dict of tables containing the dynamic impacts of 1kWh of electricity.
- Return type:
dict
- ecodynelec.pipeline_functions.get_mix(parameters: Parameter, raw_prod_exch: DataFrame, return_matrix: bool = False, return_prod_mix: bool = False, is_verbose: bool = False, progress_bar: ProgressInfo | None = None)[source]
Loads the mix from the specified parameters. If return_matrix is True, returns the whole consumption mix matrix instead of the mix dictionary. Else, returns the consumption mix dictionary (the impact matrix sorted by target country). If return_prod_mix is True, the production mix in the studied countries is also returned (as a tuple with the consumption mix).
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
raw_prod_exch (pandas.DataFrame) – The raw production and exchange data, as returned by load_raw_prod_exchanges.
return_matrix (bool, default to False) – If True, returns the whole mix matrix instead of the mix dictionary (the impact matrix sorted by target country). (overrides return_prod_mix).
return_prod_mix (bool, default to False) – If True, returns the production mix in the studied countries, as a tuple with the consumption mix. Has no effect if return_matrix is True.
is_verbose (bool, default to False) – To display progress information
progress_bar (ecodynelec.ProgressInfo, default to None) – To display progress information
- Returns:
return_matrix is False and return_prod_mix is False – A dictionary of pandas.DataFrame, with the consumption mix for each target (parameter.target) (containing the contribution of each production mean in 1 kWh consumed in the target country). This includes the local residual if parameters.residual_local is True.
return_matrix is False and return_prod_mix is True – A tuple (prod_mix_dict, cons_mix_dict) of two dictionaries of pandas.DataFrame, with the consumption mix (containing the contribution of each production mean in 1 kWh consumed in the target country) and the production mix (containing the contribution of each production mean in 1 kWh produced in the studied countries) for each target (parameter.target).
return_matrix is True – The raw table with the electricity mix in the studied countries (parameter.ctry + ‘Other’), containing each production mean of each country. This is a list of pandas.DataFrame, for each time step.
- ecodynelec.pipeline_functions.get_producing_mix_kwh(flows_df: DataFrame, prod_mix_df: DataFrame) DataFrame[source]
Converts a relative production mix to absolute values (in kWh) for the target country.
- Parameters:
flows_df (pd.DataFrame) – A dataframe containing the raw productions/imports/exports (in kWh) for each target.
prod_mix_df (pd.DataFrame) – A dataframe containing the relative production mix of the target country.
- Return type:
A dataframe containing the production mix in kWh for the target country.
- ecodynelec.pipeline_functions.get_voltage_impacts(parameters: Parameter, imp_dict: dict | None = None, network_imp: dict | None = None, mix: dict | None = None, is_verbose: bool = False) dict[source]
Calculates the voltage impacts for a given set of parameters ???????
- Parameters:
parameters (Parameter) – Contains parameter values that guide the computation process.
imp_dict (dict, optional) – A dictionary with existing impact data for each country. Default is None.
network_imp (dict, optional) – A dictionary containing network impact data categorized by voltage types and impacts. Default is None.
mix (dict, optional) – A dictionary containing energy mix data by country. The function modifies these data structures by dropping certain mix columns. Default is None.
is_verbose (bool, optional) – A flag to enable or disable verbose output during computations. Default is False.
- Returns:
A new impact dictionary containing calculated impacts for each voltage type (High Voltage, Medium Voltage, Low Voltage) and impact type, structured by country.
- Return type:
dict
- ecodynelec.pipeline_functions.load_config(config) Parameter[source]
Loads the configuration parameters.
- Parameters:
config (ecodynelec.Parameter or str) – a set of configuration parameters to govern the computation, either as Parameter object or str pointing at an xlsx file.
- Returns:
The loaded Parameter object.
- Return type:
ecodynelec.Parameter
- ecodynelec.pipeline_functions.load_impact_matrix(parameters: Parameter, is_verbose: bool = False) DataFrame[source]
Loads the impact matrix from the specified parameters.
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
is_verbose (bool, default to False) – To display progress information
- Returns:
impact_matrix – The unit impact vector of electricity production
- Return type:
pandas.DataFrame
- ecodynelec.pipeline_functions.load_network_impact(parameters: Parameter, is_verbose: bool = False) DataFrame[source]
Loads the network impact from the specified parameters.
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
is_verbose (bool, default to False) – To display progress information
- Returns:
network_impact – The network impact dictionary
- Return type:
dict
- ecodynelec.pipeline_functions.load_raw_prod_exchanges(parameters: ~ecodynelec.parameter.Parameter | str, is_verbose: bool = False, progress_bar: ~ecodynelec.progress_info.ProgressInfo | None = None) -> (<class 'pandas.core.frame.DataFrame'>, <class 'pandas.core.frame.DataFrame'>, <class 'pandas.core.frame.DataFrame'>)[source]
Loads the raw production and exchange data from entso-e.
- Parameters:
parameters (ecodynelec.Parameter or str) – a set of configuration parameters to govern the computation, either as Parameter object or str pointing at an xlsx file.
is_verbose (bool, default to False) – To display progress information
progress_bar (ecodynelec.ProgressInfo, default to None) – The progress bar to use, or None
- Returns:
praw_prodExch
- Return type:
DataFrame with all productions and all exchanges from all included countries.
- ecodynelec.pipeline_functions.localize_from_utc(data: DataFrame, timezone: str = 'CET') DataFrame[source]
Converts the index of a dataframe from UTC to another time zone.
- Parameters:
data (pandas.DataFrame) – table with TimeIndex, assumed to be UTC
timezone – the time zone to convert to, defaults to ‘CET’
- Returns:
a table with shifted TimeIndex to the right time zone
- Return type:
pandas.DataFrame
- ecodynelec.pipeline_functions.save_results(parameters: Parameter, flows_dict: dict | None = None, impact_matrix: DataFrame | None = None, prod_mix_dict: dict | None = None, mix_dict: dict | None = None, prod_imp_dict: dict | None = None, imp_dict: dict | None = None, is_verbose: bool = False) None[source]
Saves the results in the specified directory (parameters.path.savedir).
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
flows_dict (dict or None) – A dictionary of pandas.DataFrame, with the raw productions/imports/exports (in kWh) for each target. As returned by get_flows_kwh.
impact_matrix (pandas.DataFrame or None) – The impact matrix, as returned by load_impact_matrix.
prod_mix_dict (dict or None) – A dictionary of pandas.DataFrame, with the production mix for each target, as returned by get_mix.
mix_dict (dict or None) – A dictionary of pandas.DataFrame, with the consumption mix for each target, as returned by get_mix.
prod_imp_dict (dict or None) – A dictionary containing the electricity production impacts for each target, as returned by get_impacts.
imp_dict (dict or None) – A dictionary containing the electricity consumption impacts for each target, as returned by get_impacts.
is_verbose (bool, default to False) – To display progress information
- ecodynelec.pipeline_functions.translate_to_timezone(parameters: Parameter, flows_dict: dict | None = None, prod_mix_dict: dict | None = None, mix_dict: dict | None = None, prod_imp_dict: dict | None = None, imp_dict: dict | None = None, is_verbose: bool = False)[source]
Translates the data to the right timezone. The data is modified in place.
- Parameters:
parameters (ecodynelec.Parameter) – Parameters returned by load_config.
flows_dict (dict or None) – A dictionary of pandas.DataFrame, with the raw productions/imports/exports (in kWh) for each target. As returned by get_flows_kwh.
prod_mix_dict (dict or None) – A dictionary of pandas.DataFrame, with the production mix for each target. As returned by get_mix.
mix_dict (dict or None) – A dictionary of pandas.DataFrame, with the consumption mix for each target. As returned by get_mix.
prod_imp_dict (dict or None) – A dictionary containing the electricity production impacts for each target. As returned by get_impacts.
imp_dict (dict or None) – A dictionary containing the electricity consumption impacts for each target. As returned by get_impacts.
is_verbose (bool, default to False) – To display progress information
- Returns:
(flows_dict, prod_mix_dict, mix_dict, prod_imp_dict, imp_dict) – The same dictionaries, with the data translated to the right timezone.
- Return type:
tuple of dict