2018-01-29 21:28:33 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-08-03 09:54:28 +00:00
|
|
|
import os
|
2018-01-29 21:28:33 +00:00
|
|
|
import atlite
|
|
|
|
import pandas as pd
|
2018-08-03 09:53:14 +00:00
|
|
|
import geopandas as gpd
|
|
|
|
from vresutils import hydro as vhydro
|
2018-01-29 21:28:33 +00:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.setLevel(level=snakemake.config['logging_level'])
|
|
|
|
|
2018-08-03 09:54:28 +00:00
|
|
|
cutout = atlite.Cutout(snakemake.config['renewable']['hydro']['cutout'],
|
|
|
|
cutout_dir=os.path.dirname(snakemake.input.cutout))
|
2018-01-29 21:28:33 +00:00
|
|
|
|
|
|
|
countries = snakemake.config['countries']
|
2018-12-19 14:37:18 +00:00
|
|
|
country_shapes = gpd.read_file(snakemake.input.country_shapes).set_index('name')['geometry'].reindex(countries)
|
2018-01-29 21:28:33 +00:00
|
|
|
country_shapes.index.name = 'countries'
|
|
|
|
|
2018-08-03 09:53:14 +00:00
|
|
|
eia_stats = vhydro.get_eia_annual_hydro_generation(snakemake.input.eia_hydro_generation).reindex(columns=countries)
|
2018-01-29 21:28:33 +00:00
|
|
|
inflow = cutout.runoff(shapes=country_shapes,
|
|
|
|
smooth=True,
|
|
|
|
lower_threshold_quantile=True,
|
|
|
|
normalize_using_yearly=eia_stats)
|
|
|
|
|
|
|
|
inflow.to_netcdf(snakemake.output[0])
|