PyPSA / pypsa-eur

PyPSA-Eur: A Sector-Coupled Open Optimisation Model of the European Energy System
https://pypsa-eur.readthedocs.io/
311 stars 213 forks source link

Hardcoding nhours of a year ignores leap years #317

Open martacki opened 2 years ago

martacki commented 2 years ago

It's not a minor issue, but currently the number of hours is hard coded, which ignores at least leap years that have not 8760 hours but 8784 hours. This is particulary nasty if it's happening within functions, not so much after "__main__" (?) (at least for me...). However it might be useful to adapt this also outside of functions.

My quick scan spotted this issue within three functions/scripts: https://github.com/PyPSA/pypsa-eur/blob/master/scripts/_helpers.py#L122 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/make_summary.py#L405 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/solve_network.py#L131

Additionally outside of functions (ie. after "__main__") here: https://github.com/PyPSA/pypsa-eur/blob/master/scripts/add_electricity.py#L548 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/add_extra_components.py#L199 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/cluster_network.py#L357 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/prepare_network.py#L212 https://github.com/PyPSA/pypsa-eur/blob/master/scripts/simplify_network.py#L394

Any idea on how to fix it? If we knew for certain which year is modelled, we could write a short _helpers script to calculate n_hours of a year. But the snapshot index does not necessarily have to be a DateRange, does it?

fneum commented 2 years ago

My two cents: to save headaches, cut 29 Feb in leap years...