|
40 | 40 | get_windturbineconfig, |
41 | 41 | windturbine_smooth, |
42 | 42 | ) |
| 43 | +from atlite.utils import ensure_coords |
43 | 44 |
|
44 | 45 | logger = logging.getLogger(__name__) |
45 | 46 |
|
@@ -216,7 +217,7 @@ def convert_and_aggregate( |
216 | 217 | ) |
217 | 218 |
|
218 | 219 | if isinstance(matrix, xr.DataArray): |
219 | | - coords = matrix.indexes.get(matrix.dims[1]).to_frame(index=False) |
| 220 | + coords = matrix.indexes[matrix.dims[1]].to_frame(index=False) |
220 | 221 | if not np.array_equal(coords[["x", "y"]], cutout.grid[["x", "y"]]): |
221 | 222 | raise ValueError( |
222 | 223 | "Matrix spatial coordinates not aligned with cutout spatial " |
@@ -247,15 +248,17 @@ def convert_and_aggregate( |
247 | 248 | else: |
248 | 249 | matrix = csr_matrix(matrix) * spdiag(layout) |
249 | 250 |
|
250 | | - # From here on, matrix is defined and ensured to be a csr matrix. |
251 | | - if index is None: |
252 | | - index = pd.RangeIndex(matrix.shape[0]) |
| 251 | + # guaranteed by code flow above, helps type checker |
| 252 | + assert isinstance(matrix, csr_matrix) |
253 | 253 |
|
254 | | - results = aggregate_matrix(da, matrix=matrix, index=index) |
| 254 | + coords = ensure_coords(index) |
| 255 | + if len(coords.dims) > 1: |
| 256 | + raise ValueError(f"index must have a single dimension, not: {coords.dims}") |
| 257 | + results = aggregate_matrix(da, matrix=matrix, coords=coords) |
255 | 258 |
|
256 | 259 | if per_unit or return_capacity: |
257 | 260 | caps = matrix.sum(-1) |
258 | | - capacity = xr.DataArray(np.asarray(caps).flatten(), [index]) |
| 261 | + capacity = xr.DataArray(np.asarray(caps).flatten(), coords) |
259 | 262 | capacity.attrs["units"] = "MW" |
260 | 263 |
|
261 | 264 | if per_unit: |
|
0 commit comments