pypsa-meets-earth / pypsa-earth

PyPSA-Earth: A flexible Python-based open optimisation model to study energy system futures around the world.
https://pypsa-earth.readthedocs.io/en/latest/
207 stars 167 forks source link

Merge helpers #1029

Closed finozzifa closed 3 weeks ago

finozzifa commented 1 month ago

Closes # (if applicable).

Together with the merge of the methods from the helpers.py script of pypsa-earth-sec into the _helpers.py script of pypsa-earth, the pull request proposes also a possible solution for https://github.com/pypsa-meets-earth/pypsa-earth-sec/issues/310.

Changes proposed in this Pull Request

This is the first pull request I propose for the merge of pypsa-earth-sec into pypsa-earth. The changes are listed below:

Changes in _helpers.py

Proposed resolution of issue https://github.com/pypsa-meets-earth/pypsa-earth-sec/issues/310

I created the issue https://github.com/pypsa-meets-earth/pypsa-earth-sec/issues/310 in pypsa-earth-sec. In a nutshell, one of the inputs used in pypsa-earth-sec for _rule build_base_energytotals contains a few typos (e.g. "Hrad coal") and many duplicated entries (e.g. "Coke-oven coke", "Coke oven coke" and "Coke Oven Coke"). Such typos and duplicated entries have been propagated in the method _get_convfactors and in the method _aggregatefuels. Moreover, _aggregatefuels contains two mutually exclusive definitions for the list _coalfuels. Finally, the method _aggregatefuels does not use the function argument sector.

The above-mentioned input is composed of several text files, which are read into a pandas dataframe. The processing happens in _scripts/build_base_energytotals.py in pypsa-earth-sec. The entries "Hrad coal", "Coke-oven coke", "Coke oven coke" and "Coke Oven Coke" etc. populate the column "Commodity" of the pandas dataframe.

My proposed solution is to leave the input files untouched and to modify the pandas dataframe, replacing the typos and lower-casing all entries of column "Commodity". I implement the solution with the following methods:

Unit tests for the _helpers.py methods

I have added dedicated unit tests for some of the methods present in the _helpers.py script. In particular I test that the _modifycommodity method yields the requested changes to the "Commodity" column of the pandas dataframe.

Further notes

Checklist