2019-04-16 14:03:51 +00:00
|
|
|
|
|
|
|
import geopandas as gpd
|
|
|
|
import atlite
|
|
|
|
import pandas as pd
|
|
|
|
import xarray as xr
|
|
|
|
import scipy as sp
|
2020-05-07 12:45:14 +00:00
|
|
|
import helper
|
2019-04-16 14:03:51 +00:00
|
|
|
|
|
|
|
if 'snakemake' not in globals():
|
|
|
|
from vresutils import Dict
|
|
|
|
import yaml
|
|
|
|
snakemake = Dict()
|
|
|
|
with open('config.yaml') as f:
|
2021-04-27 07:54:52 +00:00
|
|
|
snakemake.config = yaml.safe_load(f)
|
2019-04-16 14:03:51 +00:00
|
|
|
snakemake.input = Dict()
|
|
|
|
snakemake.output = Dict()
|
|
|
|
|
|
|
|
time = pd.date_range(freq='m', **snakemake.config['snapshots'])
|
|
|
|
params = dict(years=slice(*time.year[[0, -1]]), months=slice(*time.month[[0, -1]]))
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-30 16:38:55 +00:00
|
|
|
cutout = atlite.Cutout(snakemake.config['atlite']['cutout_name'],
|
2019-04-16 14:03:51 +00:00
|
|
|
cutout_dir=snakemake.config['atlite']['cutout_dir'],
|
|
|
|
**params)
|
|
|
|
|
|
|
|
clustered_busregions_as_geopd = gpd.read_file(snakemake.input.regions_onshore).set_index('name', drop=True)
|
|
|
|
|
|
|
|
clustered_busregions = pd.Series(clustered_busregions_as_geopd.geometry, index=clustered_busregions_as_geopd.index)
|
|
|
|
|
2020-05-07 12:45:14 +00:00
|
|
|
helper.clean_invalid_geometries(clustered_busregions)
|
|
|
|
|
2019-04-16 14:03:51 +00:00
|
|
|
I = cutout.indicatormatrix(clustered_busregions)
|
|
|
|
|
|
|
|
|
|
|
|
for item in ["total","rural","urban"]:
|
|
|
|
|
|
|
|
pop_layout = xr.open_dataarray(snakemake.input['pop_layout_'+item])
|
2020-04-30 16:38:55 +00:00
|
|
|
|
2019-04-16 14:03:51 +00:00
|
|
|
M = I.T.dot(sp.diag(I.dot(pop_layout.stack(spatial=('y', 'x')))))
|
|
|
|
nonzero_sum = M.sum(axis=0, keepdims=True)
|
|
|
|
nonzero_sum[nonzero_sum == 0.] = 1.
|
|
|
|
M_tilde = M/nonzero_sum
|
2020-04-30 16:38:55 +00:00
|
|
|
|
2019-04-16 14:03:51 +00:00
|
|
|
solar_thermal_angle = 45.
|
|
|
|
#should clearsky_model be "simple" or "enhanced"?
|
|
|
|
solar_thermal = cutout.solar_thermal(clearsky_model="simple",
|
|
|
|
orientation={'slope': solar_thermal_angle, 'azimuth': 180.},
|
|
|
|
matrix = M_tilde.T,
|
|
|
|
index=clustered_busregions.index)
|
|
|
|
|
|
|
|
solar_thermal.to_netcdf(snakemake.output["solar_thermal_"+item])
|