Skip to content

Commit

Permalink
Unit test compile cost assumptions - Part 1 (#170)
Browse files Browse the repository at this point in the history
* code: unit test for get_excel_sheets

* pre-commit

* code: move sheet_names to _helpers.py

* code: modify years_list

* output: cost outputs

* code: merge from master

* code: new unit tests

* code: revert changes to _helpers.py

* code:fix quick issues

* code: add logger

* code: add docstrings

* add pre-commit changes

* code: modify sheet location method

* code: add docstring

* code: unit test clean_up_units

* code: add docstring for get_dea_martime_data

* code: add unit test for set_specify_assumptions

* code: add docstring for set_specify_assumptions

* code: remove assert False

* code: unit test for set_round_trip_efficiency

* include pre-commit

* code: switch to numpydoc and introduce static types

* code:include pre-commit

* code: numpydoc and static types for order_data

* code:replace print with logger statements

* code: add logger

* code: modify static type

* docu: update numpydoc to the requested standard

* code: add unit test for add_description

* modify logger msg

* code: fix logger messages

* code: add unit test for convert_units

* code: add numpydoc for add_gas_storage

* code: new changes

* code: add numpydoc

* code: re-factor and numpydoc'

* code: add new numpydoc

* code: add new numpydoc - 2

* code: add new numpydoc - 3

* doc: update release_notes.rst

* code: remove unit test for dea_maritime

* code: add numpydoc for carbon_flow

* code: pre-commit for carbon_flow

* code: numpydoc for add_egs_data

* code: add unit test for annuity

* code: update numpydoc and naming

* code: add numpydoc to compile_cost_assumptions_usa.py

* code: replace list_of_years to years

* code: numpydoc for final batch of functions

* code: replace NoneType with empty DataFrame

* code: pre-commit run all

* code: new changes
  • Loading branch information
finozzifa authored Feb 19, 2025
1 parent 3d238ee commit ee37d71
Show file tree
Hide file tree
Showing 7 changed files with 3,043 additions and 1,019 deletions.
3 changes: 3 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ Upcoming Release
.. The features listed below are not released yet, but will be part of the next release!
.. To use the features already you have to use the ``master`` branch.
* Include unit test for compile_cost_assumptions_usa.py (https://github.com/PyPSA/technology-data/pull/170)

* US specific folder for NREL/ATB data (https://github.com/PyPSA/technology-data/pull/172)

* Include unit test execution and compile_cost_assumptions_usa.py in ci.yaml (https://github.com/PyPSA/technology-data/pull/174)

* Align `snakemake` version and the related `mock_snakemake` to PyPSA-Eur (https://github.com/PyPSA/technology-data/pull/177)

`v0.11.0 <https://github.com/PyPSA/technology-data/releases/tag/v0.11.0>`__ (24th January 2025)
Expand Down
63 changes: 45 additions & 18 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,39 +187,66 @@ def make_accessable(*ios):
return snakemake


def adjust_for_inflation(inflation_rate, costs, techs, eur_year, col):
def adjust_for_inflation(
inflation_rate: pd.DataFrame,
costs: pd.DataFrame,
techs: pd.Series,
eur_year: int,
col_name: str,
usa_costs_flag: bool = False,
) -> pd.DataFrame:
"""
Adjust the investment costs for the specified techs for inflation.
The function adjust the investment costs for the specified techs for inflation.
techs: str or list
One or more techs in costs index for which the inflation adjustment is done.
eur_year: int
Reference year for which the costs are provided and based on which the inflation adjustment is done.
costs: Dataframe containing the costs data with multiindex on technology and one index key 'investment'.
Parameters
----------
inflation_rate : pd.DataFrame
inflation rates for several years
costs : pd.DataFrame
existing cost dataframe
techs : pd.Series
technologies
eur_year : int,
reference year for which the costs are provided and based on which the inflation adjustment is done
col_name : str
column name to which to apply the inflation rate adjustment
usa_costs_flag: bool
flag for US specific costs
Returns
-------
Dataframe
inflation updated cost dataframe
"""

def get_factor(inflation_rate, ref_year, eur_year):
def get_factor(inflation_rate_df, ref_year, eur_year_val):
if (pd.isna(ref_year)) or (ref_year < 1900):
return np.nan
if ref_year == eur_year:
if ref_year == eur_year_val:
return 1
mean = inflation_rate.mean()
if ref_year < eur_year:
new_index = np.arange(ref_year + 1, eur_year + 1)
df = 1 + inflation_rate.reindex(new_index).fillna(mean)
return df.cumprod().loc[eur_year]
mean = inflation_rate_df.mean()
if ref_year < eur_year_val:
new_index = np.arange(ref_year + 1, eur_year_val + 1)
df = 1 + inflation_rate_df.reindex(new_index).fillna(mean)
return df.cumprod().loc[eur_year_val]
else:
new_index = np.arange(eur_year + 1, ref_year + 1)
df = 1 + inflation_rate.reindex(new_index).fillna(mean)
new_index = np.arange(eur_year_val + 1, ref_year + 1)
df = 1 + inflation_rate_df.reindex(new_index).fillna(mean)
return 1 / df.cumprod().loc[ref_year]

inflation = costs.currency_year.apply(
lambda x: get_factor(inflation_rate, x, eur_year)
)

paras = ["investment", "VOM", "fuel"]
filter_i = costs.technology.isin(techs) & costs.parameter.isin(paras)
costs.loc[filter_i, col] = costs.loc[filter_i, col].mul(

if usa_costs_flag:
filter_i = costs.technology.isin(techs) & costs.parameter.isin(paras)
else:
filter_i = costs.index.get_level_values(0).isin(
techs
) & costs.index.get_level_values(1).isin(paras)
costs.loc[filter_i, col_name] = costs.loc[filter_i, col_name].mul(
inflation.loc[filter_i], axis=0
)

Expand Down
Loading

0 comments on commit ee37d71

Please sign in to comment.