Skip to content

Commit

Permalink
implement resource class split per bus
Browse files Browse the repository at this point in the history
  • Loading branch information
fneum committed Jan 6, 2025
1 parent 46ccd6d commit c50cd0c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions scripts/build_renewable_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
import atlite
import geopandas as gpd
import numpy as np
import pandas as pd
import xarray as xr
from _helpers import configure_logging, get_snapshots, set_scenario_config
from atlite.gis import ExclusionContainer
from build_shapes import _simplify_polys
from dask.distributed import Client

Expand Down Expand Up @@ -218,17 +218,22 @@
f"Create masks for {nbins} resource classes for technology {technology}..."
)

# indicator matrix for which cells touch which regions
I = np.ceil(cutout.availabilitymatrix(regions, ExclusionContainer()))
cf_by_bus = capacity_factor * I.where(I > 0)

epsilon = 1e-3
cf_min, cf_max = (
capacity_factor.min() - epsilon,
capacity_factor.max() + epsilon,
cf_by_bus.min(dim=["x", "y"]) - epsilon,
cf_by_bus.max(dim=["x", "y"]) + epsilon,
)
bins = np.linspace(cf_min, cf_max, nbins + 1)
class_masks = [
np.logical_and(bins[i] <= capacity_factor, capacity_factor < bins[i + 1])
for i in range(nbins)
]
class_masks = xr.concat(class_masks, pd.Index(range(nbins), name="bin"))
normed_bins = xr.DataArray(np.linspace(0, 1, nbins + 1), dims=["bin"])
bins = cf_min + (cf_max - cf_min) * normed_bins

cf_by_bus_bin = cf_by_bus.expand_dims(bin=range(nbins))
lower_edges = bins[:, :-1]
upper_edges = bins[:, 1:]
class_masks = (cf_by_bus_bin >= lower_edges) & (cf_by_bus_bin < upper_edges)

layout = capacity_factor * area * capacity_per_sqkm

Expand Down

0 comments on commit c50cd0c

Please sign in to comment.