pypsa-eur icon indicating copy to clipboard operation
pypsa-eur copied to clipboard

Hardcoding nhours of a year ignores leap years

Open martacki opened this issue 3 years ago • 1 comments

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?

martacki avatar Feb 25 '22 08:02 martacki

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

fneum avatar Mar 03 '22 17:03 fneum