Skip to content

Commit d20bcd3

Browse files
committed
Updated some TODOs
1 parent 9e87081 commit d20bcd3

10 files changed

Lines changed: 25 additions & 121 deletions

File tree

iepy/generation/vres/profiles/manager.py

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
import xarray.ufuncs as xu
99
import numpy as np
1010
import 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
1712
import windpowerlib
1813

1914
from iepy.technologies import get_config_dict, get_config_values
2015
from iepy.geographics import get_shapes
2116

2217
from 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

2524
def 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)

iepy/geographics/grid_cells.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def get_grid_cells(technologies: List[str], resolution: float,
9898
f"shapes for technology {tech}"
9999

100100
# Divide onshore and offshore shapes at a given resolution
101-
# TODO: why is taking ages on onshore shape of EU compared to offshore?
102101
onshore_points, onshore_grid_cells_shapes = [], np.array([])
103102
if onshore_shape is not None:
104103
for r in onshore_shape.index:

iepy/geographics/shapes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ def get_shapes(region_codes: List[str], which: str = 'onshore_offshore', save: b
286286

287287
# If shapes for those codes were previously computed, output is returned directly from file.
288288
sorted_name = "".join(sorted(region_codes))
289+
print(region_codes)
289290
hash_name = hashlib.sha224(bytes(sorted_name, 'utf-8')).hexdigest()[:10]
291+
print(hash_name)
290292
fn = f"{data_path}geographics/generated/{hash_name}.geojson"
291293
if isfile(fn):
292294
print("ok")

iepy/load/data_retrieval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def download_iea_electricity_consumption(countries, start_year, end_year):
3636

3737
if __name__ == '__main__':
3838
countries_ = ["CY", "MT"]
39-
download_iea_electricity_consumption(countries_, 1990, 2017)
39+
download_iea_electricity_consumption(countries_, 1990, 2018)

iepy/topologies/core/manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,16 @@ def remove_dangling_branches(branches_df: pd.DataFrame(), buses_ids: Union[List[
9898
def find_closest_links(links_df: pd.DataFrame, new_links_df: pd.DataFrame,
9999
distance_upper_bound: float = 1.5) -> pd.Series:
100100
"""
101-
102-
# TODO: complete
101+
TODO: complete
102+
Parameters
103+
----------
103104
104105
Returns
105106
-------
106107
107-
TODO: what does it return?
108-
109108
Notes
110109
-----
111-
This function is originally copied from PyPSA-Eur script base_network.py
110+
This function is originally copied from PyPSA-Eur script base_network.py.
112111
113112
114113
"""
@@ -154,6 +153,10 @@ def remove_unconnected_components(net: pypsa.Network) -> pypsa.Network:
154153
Returns
155154
-------
156155
156+
Notes
157+
-----
158+
This function is originally copied from PyPSA-Eur script base_network.py.
159+
157160
"""
158161
_, labels = csgraph.connected_components(net.adjacency_matrix(), directed=False)
159162
component = pd.Series(labels, index=net.buses.index)

iepy/topologies/tyndp2018.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def preprocess(plotting=True) -> None:
3939
# - DG (Distributed Generation): prosumers at the centre - small-scale generation, batteries and fuel-switching
4040
# society engaged and empowered
4141
# - GCA (Global Climate Action): full-speed global decarbonisation, large-scale renewables
42-
# TODO: Why are we using NTC 2027 as exiting capacity and not 2020?
4342
links = pd.read_excel(link_data_fn, sheet_name="NTC", index_col=0, skiprows=[0, 2],
4443
usecols=[0, 3, 4, 5, 6, 7, 8, 9, 10],
4544
names=["link", "in", "out", "st_in", "st_out", "dg_in", "dg_out", "gca_in", "gca_out"])
@@ -273,22 +272,15 @@ def get_topology(network: pypsa.Network, countries: List[str] = None,
273272

274273
topology_dir = f"{data_path}topologies/tyndp2018/generated/"
275274
links_fn = f"{topology_dir}links.csv"
276-
links = pd.read_csv(links_fn, index_col='id')
277-
print(links.p_nom_st.sum())
278-
print(links.p_nom_dg.sum())
279-
print(links.p_nom_gca.sum())
280-
print((links.p_nom_st*links.length).sum())
281-
print((links.p_nom_dg*links.length).sum())
282-
print((links.p_nom_gca*links.length).sum())
283-
exit()
284-
diff_st_dg = (links.p_nom_dg - links.p_nom_st).abs()
285-
diff_st_gca = (links.p_nom_gca - links.p_nom_st).abs()
286-
diff_dg_gca = (links.p_nom_gca - links.p_nom_dg).abs()
275+
links_ = pd.read_csv(links_fn, index_col='id')
276+
diff_st_dg = (links_.p_nom_dg - links_.p_nom_st).abs()
277+
diff_st_gca = (links_.p_nom_gca - links_.p_nom_st).abs()
278+
diff_dg_gca = (links_.p_nom_gca - links_.p_nom_dg).abs()
287279
pd.concat((diff_st_gca, diff_st_dg, diff_dg_gca), axis=1).max(axis=1).plot(kind='bar')
288280
plt.figure()
289-
links.p_nom_st.plot(ls='-', marker='.', c='b', alpha=0.5)
290-
links.p_nom_dg.plot(ls='-', marker='.', c='r', alpha=0.5)
291-
links.p_nom_gca.plot(ls='-', marker='.', c='g', alpha=0.5)
292-
plt.xticks(ticks=range(len(links)), labels=list(links.index), rotation='90')
281+
links_.p_nom_st.plot(ls='-', marker='.', c='b', alpha=0.5)
282+
links_.p_nom_dg.plot(ls='-', marker='.', c='r', alpha=0.5)
283+
links_.p_nom_gca.plot(ls='-', marker='.', c='g', alpha=0.5)
284+
plt.xticks(ticks=range(len(links_)), labels=list(links_.index), rotation='90')
293285
plt.grid()
294286
plt.show()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# TODO: complete
1+
# TODO: complete

tests/generation/vres/potentials/enspreso/test_manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ def test_get_capacity_potential_at_points_wrong_country():
9999
get_capacity_potential_at_points({'wind_onshore': [(0.5, 1.0)]}, 0.5, ['ZZ'])
100100

101101

102-
# TODO: add test for 'get_capacity_potential_at_points' and 'get_capacity_potential_for_regions'
103-
# if we keep these functions
104-
105-
106102
def test_get_capacity_potential_for_countries_wrong_tech():
107103
with pytest.raises(AssertionError):
108104
get_capacity_potential_for_countries('wind', ['BE'])

tests/land_data/__init__.py

Whitespace-only changes.

tests/land_data/test_manager.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)