From 173ab7b318e1d0e38bbab96b6bc3f103ccbf2abf Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 16 Jun 2022 09:00:33 +0200 Subject: [PATCH] add_electricity: make drop_leap_year own function --- scripts/add_electricity.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index b86e8a9e..9158ce33 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -547,6 +547,15 @@ def add_nice_carrier_names(n, config): logger.warning(f'tech_colors for carriers {missing_i} not defined in config.') n.carriers['color'] = colors + +def drop_leap_day(n): + if not n.snapshots.is_leap_year.any(): return + leap_days = (n.snapshots.day == 29) & (n.snapshots.month == 2) + n.set_snapshots(n.snapshots[~leap_days]) + n.snapshot_weightings[:] = 8760/len(n.snapshots) + logger.info("Dropped February 29 from leap year.") + + if __name__ == "__main__": if 'snakemake' not in globals(): from _helpers import mock_snakemake @@ -600,7 +609,6 @@ if __name__ == "__main__": add_nice_carrier_names(n, snakemake.config) if snakemake.config['enable'].get('drop_leap_days', True): - leap_days = (n.snapshots.day == 29) & (n.snapshots.month == 2) - n.set_snapshots(n.snapshots[~leap_days]) + drop_leap_day(n) n.export_to_netcdf(snakemake.output[0])