drop_leap_days when aggregating snapshots

This commit is contained in:
Fabian Neumann 2022-07-29 21:19:26 +02:00
parent ee0c69727f
commit d4fa922a2a

View File

@ -571,7 +571,7 @@ def add_co2limit(n, Nyears=1., limit=0.):
) )
# TODO PyPSA-Eur merge issue # TODO PyPSA-Eur merge issue
def average_every_nhours(n, offset): def average_every_nhours(n, offset, drop_leap_day=False):
logger.info(f'Resampling the network to {offset}') logger.info(f'Resampling the network to {offset}')
m = n.copy(with_time=False) m = n.copy(with_time=False)
@ -590,6 +590,10 @@ def average_every_nhours(n, offset):
else: else:
pnl[k] = df.resample(offset).mean() pnl[k] = df.resample(offset).mean()
if drop_leap_day:
sns = m.snapshots[~((m.snapshots.month == 2) & (m.snapshots.day == 29))]
m.set_snapshots(sns)
return m return m
@ -2428,7 +2432,8 @@ if __name__ == "__main__":
for o in opts: for o in opts:
m = re.match(r'^\d+h$', o, re.IGNORECASE) m = re.match(r'^\d+h$', o, re.IGNORECASE)
if m is not None: if m is not None:
n = average_every_nhours(n, m.group(0)) drop_leap_day = snakemake.config["atlite"].get("drop_leap_day", False)
n = average_every_nhours(n, m.group(0), drop_leap_day)
break break
limit_type = "config" limit_type = "config"