88import xarray .ufuncs as xu
99import numpy as np
1010import pandas as pd
11- import dask .array as da
12- import dask
13- dask .config .set ({"array.slicing.split_large_chunks" : True })
1411
15- # from shapely.geometry import Point, Polygon
16- # import atlite
1712import windpowerlib
1813
1914from iepy .technologies import get_config_dict , get_config_values
2015from iepy .geographics import get_shapes
2116
2217from iepy import data_path
2318
19+ import dask .array as da
20+ import dask
21+ dask .config .set ({"array.slicing.split_large_chunks" : True })
22+
2423
2524def read_resource_database (spatial_resolution : float ) -> xr .Dataset :
2625 """
@@ -41,7 +40,6 @@ def read_resource_database(spatial_resolution: float) -> xr.Dataset:
4140 available_res = sorted ([float (res ) for res in listdir (main_resource_dir )])
4241 # Find the dataset with the least precise resolution that can accommodate the desired resolution
4342 dataset_resolution = None
44- # TODO: tis doesn't work if the smaller resolution directory doesn't contain the appropriate region
4543 for spatial_res in available_res :
4644 if int (spatial_resolution * 1e6 ) % int (spatial_res * 1e6 ) == 0 :
4745 dataset_resolution = spatial_res
@@ -323,7 +321,7 @@ def get_cap_factor_for_countries(tech: str, countries: List[str], timestamps: pd
323321 spatial_res = 0.5
324322 missing_countries = sorted (list (missing_countries ))
325323 which = 'onshore' if get_config_values (tech , ["onshore" ]) else 'offshore'
326- shapes_df = get_shapes (missing_countries , which = which )
324+ shapes_df = get_shapes (missing_countries , which = which , save = True )
327325 # TODO: weird userwarning happening on Iceland
328326 centroids = shapes_df ["geometry" ].centroid
329327 points = [(round (p .x / spatial_res ) * spatial_res , round (p .y / spatial_res ) * spatial_res )
@@ -333,88 +331,3 @@ def get_cap_factor_for_countries(tech: str, countries: List[str], timestamps: pd
333331 capacity_factors_df = pd .concat ([capacity_factors_df , cap_factor_df ], axis = 1 )
334332
335333 return capacity_factors_df [countries ].round (precision )
336-
337- # --- Using atlite --- #
338- # def get_cap_factor_for_regions(regions: List[Polygon], start_month: int, end_month: int = None):
339- # """
340- # Return the capacity factor series and generation capacity for pv and wind for a list of regions.
341- #
342- # Parameters
343- # ----------
344- # regions: List[Polygon]
345- # List of geographical regions for which we want a capacity factor series
346- # start_month: int
347- # Number of the first month
348- # end_month: int
349- # Number of the last month. If equal to start_month, data will be returned only for one month.
350- # Another way to get this behavior is just no setting end_month and leaving it to None.
351- #
352- # Returns
353- # -------
354- # wind_cap_factors: xr.DataArray with coordinates id (i.e. regions) and time
355- # Wind capacity factors for each region in regions
356- # wind_capacities:
357- # Wind generation capacities for each region in regions
358- # pv_cap_factors:
359- # PV capacity factors for each region in regions
360- # pv_capacities:
361- # PV generation capacity for each region in regions
362- # """
363- #
364- # if end_month is None:
365- # end_month = start_month
366- #
367- # assert start_month <= end_month, \
368- # "ERROR: The number of the end month must be superior to the number of the start month"
369- #
370- # cutout_dir = f"{data_path}cutouts/"
371- #
372- # cutout_params = dict(years=[2013], months=list(range(start_month, end_month+1)))
373- # cutout = atlite.Cutout("europe-2013-era5", cutout_dir=cutout_dir, **cutout_params)
374- #
375- # # Wind
376- # wind_cap_factors, wind_capacities = cutout.wind(shapes=regions, turbine="Vestas_V112_3MW", per_unit=True,
377- # return_capacity=True)
378- #
379- # # PV
380- # pv_params = {"panel": "CSi",
381- # "orientation": {
382- # "slope": 35.,
383- # "azimuth": 180.}}
384- # pv_cap_factors, pv_capacities = cutout.pv(shapes=regions, **pv_params, per_unit=True, return_capacity=True)
385- #
386- # # Change precision
387- # wind_cap_factors = xr.apply_ufunc(lambda x: np.round(x, 3), wind_cap_factors)
388- # pv_cap_factors = xr.apply_ufunc(lambda x: np.round(x, 3), pv_cap_factors)
389- #
390- # return wind_cap_factors, wind_capacities, pv_cap_factors, pv_capacities
391- #
392- #
393- # def get_cap_factor_at_points(points: List[Point], start_month: int, end_month: int = None):
394- # """
395- # Return the capacity factor series and generation capacity for pv and wind for a list of points.
396- #
397- # Parameters
398- # ----------
399- # points: List[Point]
400- # Point for which we want a capacity factor series
401- # start_month: int
402- # Number of the first month
403- # end_month: int
404- # Number of the last month. If equal to start_month, data will be returned only for one month.
405- # Another way to get this behavior is just no setting end_month and leaving it to None.
406- #
407- # Returns
408- # -------
409- # See 'get_cap_factor_for_regions'
410- #
411- # """
412- #
413- # resolution = 0.5
414- # # Create a polygon around the point
415- # polygon_df = pd.DataFrame([Polygon([(point.x-resolution, point.y-resolution),
416- # (point.x-resolution, point.y+resolution),
417- # (point.x+resolution, point.y+resolution),
418- # (point.x+resolution, point.y-resolution)]) for point in points],
419- # index=[(point.x, point.y) for point in points], columns=["region"]).region
420- # return get_cap_factor_for_regions(polygon_df, start_month, end_month)
0 commit comments