Skip to content

Commit

Permalink
Merge branch 'main' into readme1
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-f authored Apr 30, 2024
2 parents 03f15ac + 72c8617 commit ef02055
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 51 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,24 @@ The documentation is available here: [documentation](https://pypsa-earth.readthe
</a>
</td>
<td align="center">
<a href="https://github.com/carlosfv92">
<img src="https://avatars.githubusercontent.com/u/103258059?v=4" width="100;" alt="carlosfv92"/>
<a href="https://github.com/asolavi">
<img src="https://avatars.githubusercontent.com/u/131155817?v=4" width="100;" alt="asolavi"/>
<br />
<sub><b>Carlos Fernandez</b></sub>
<sub><b>Null</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/asolavi">
<img src="https://avatars.githubusercontent.com/u/131155817?v=4" width="100;" alt="asolavi"/>
<a href="https://github.com/finozzifa">
<img src="https://avatars.githubusercontent.com/u/167071962?v=4" width="100;" alt="finozzifa"/>
<br />
<sub><b>Null</b></sub>
<sub><b>Finozzifa</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/carlosfv92">
<img src="https://avatars.githubusercontent.com/u/103258059?v=4" width="100;" alt="carlosfv92"/>
<br />
<sub><b>Carlos Fernandez</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -369,15 +376,15 @@ The documentation is available here: [documentation](https://pypsa-earth.readthe
<br />
<sub><b>Stephen J Lee</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/juli-a-ko">
<img src="https://avatars.githubusercontent.com/u/126512394?v=4" width="100;" alt="juli-a-ko"/>
<br />
<sub><b>Juli-a-ko</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/squoilin">
<img src="https://avatars.githubusercontent.com/u/4547840?v=4" width="100;" alt="squoilin"/>
Expand Down Expand Up @@ -412,15 +419,15 @@ The documentation is available here: [documentation](https://pypsa-earth.readthe
<br />
<sub><b>Katherine M. Antonio</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/jessLryan">
<img src="https://avatars.githubusercontent.com/u/122939887?v=4" width="100;" alt="jessLryan"/>
<br />
<sub><b>Jess</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/jarry7">
<img src="https://avatars.githubusercontent.com/u/27745389?v=4" width="100;" alt="jarry7"/>
Expand Down
2 changes: 1 addition & 1 deletion Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ rule base_network:
rule build_bus_regions:
params:
alternative_clustering=config["cluster_options"]["alternative_clustering"],
area_crs=config["crs"]["area_crs"],
crs=config["crs"],
countries=config["countries"],
input:
country_shapes="resources/" + RDIR + "shapes/country_shapes.geojson",
Expand Down
4 changes: 3 additions & 1 deletion doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ E.g. if a new rule becomes available describe how to use it `snakemake -j1 run_t

**Minor Changes and bug-fixing**

* Minor bug-fixing to get the generalised line types work for DC lines. `PR #1008 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1008>`__
* Minor bug-fixing to get the generalised line types work for DC lines and AC lines. `PR #1008 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1008>`__ , `PR #1011 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1011>`__ and `PR #1013 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1013>`__

* Minor bug-fixing for GADM_ID format naming. `PR #980 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/980>`__, `PR #986 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/986>`__ and `PR #989 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/989>`__

* Fix download_osm_data compatibility for earth-osm v2.1. `PR #954 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/954>`__ and `PR #988 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/988>`__

* Improve geometry filtering in clean_osm_data. `PR #989 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/989>`__

* Revise bus region definition by gadm. `PR #1001 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1001>`__

* Documentation improvements. `PR ##1007 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1007>`__

PyPSA-Earth 0.3.0
Expand Down
4 changes: 2 additions & 2 deletions scripts/augmented_line_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def haversine(p):
suffix=" DC",
bus0=new_long_lines.bus0,
bus1=new_long_lines.bus1,
type=snakemake.params.lines.get("dc_type"),
type=snakemake.params.lines.get("dc_types"),
p_min_pu=-1, # network is bidirectional
p_nom_extendable=True,
p_nom_min=min_expansion_option,
Expand All @@ -158,7 +158,7 @@ def haversine(p):
suffix=" AC",
bus0=new_kedge_lines.bus0,
bus1=new_kedge_lines.bus1,
type=snakemake.params.lines["types"].get(380),
type=snakemake.params.lines["ac_types"].get(380),
s_nom_extendable=True,
# TODO: Check if minimum value needs to be set.
s_nom_min=min_expansion_option,
Expand Down
66 changes: 31 additions & 35 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,25 @@ def custom_voronoi_partition_pts(points, outline, add_bounds_shape=True, multipl
return polygons_arr


def get_gadm_shape(onshore_locs, gadm_shapes):
def locate_bus(coords):
point = Point(Point(coords["x"], coords["y"]))
gadm_shapes_country = gadm_shapes.filter(like=country, axis=0)

try:
return gadm_shapes[gadm_shapes.contains(point)].item()
except ValueError:
return min(
gadm_shapes_country, key=(point.distance)
) # TODO returns closest shape if the point was not inside one. Works well but will not catch an outlier bus.

def get_id(coords):
point = Point(Point(coords["x"], coords["y"]))
gadm_shapes_country = gadm_shapes.filter(like=country, axis=0)

try:
return gadm_shapes[gadm_shapes.contains(point)].index.item()
except ValueError:
# return 'not_found'
return gadm_shapes_country[
gadm_shapes_country.geometry
== min(gadm_shapes_country, key=(point.distance))
].index.item() # TODO returns closest shape if the point was not inside one.

regions = onshore_locs[["x", "y"]].apply(locate_bus, axis=1)
ids = onshore_locs[["x", "y"]].apply(get_id, axis=1)
return regions.values, ids.values
def get_gadm_shape(
onshore_buses, gadm_shapes, geo_crs="EPSG:4326", metric_crs="EPSG:3857"
):
geo_regions = gpd.GeoDataFrame(
onshore_buses[["x", "y"]],
geometry=gpd.points_from_xy(onshore_buses["x"], onshore_buses["y"]),
crs=geo_crs,
).to_crs(metric_crs)

join_geos = gpd.sjoin_nearest(
geo_regions, gadm_shapes.to_crs(metric_crs), how="left"
)

# when duplicates, keep only the first entry
join_geos = join_geos[~join_geos.index.duplicated()]

gadm_sel = gadm_shapes.loc[join_geos["index_right"].values]

return gadm_sel.geometry.values, gadm_sel.index.values


if __name__ == "__main__":
Expand All @@ -168,7 +159,9 @@ def get_id(coords):
configure_logging(snakemake)

countries = snakemake.params.countries
area_crs = snakemake.params.area_crs
geo_crs = snakemake.params.crs["geo_crs"]
area_crs = snakemake.params.crs["area_crs"]
metric_crs = snakemake.params.crs["distance_crs"]

n = pypsa.Network(snakemake.input.base_network)

Expand All @@ -182,9 +175,7 @@ def get_id(coords):
"geometry"
]

gadm_shapes = gpd.read_file(snakemake.input.gadm_shapes).set_index("GADM_ID")[
"geometry"
]
gadm_shapes = gpd.read_file(snakemake.input.gadm_shapes).set_index("GADM_ID")

onshore_regions = []
offshore_regions = []
Expand All @@ -197,9 +188,14 @@ def get_id(coords):

onshore_shape = country_shapes[country]
onshore_locs = n.buses.loc[c_b & n.buses.substation_lv, ["x", "y"]]
gadm_country = gadm_shapes[gadm_shapes.country == country]
if snakemake.params.alternative_clustering:
onshore_geometry = get_gadm_shape(onshore_locs, gadm_shapes)[0]
shape_id = get_gadm_shape(onshore_locs, gadm_shapes)[1]
onshore_geometry, shape_id = get_gadm_shape(
onshore_locs,
gadm_country,
geo_crs,
metric_crs,
)
else:
onshore_geometry = custom_voronoi_partition_pts(
onshore_locs.values, onshore_shape
Expand All @@ -215,7 +211,7 @@ def get_id(coords):
"country": country,
"shape_id": shape_id,
},
crs=country_shapes.crs,
crs=geo_crs,
)
temp_region = temp_region[
temp_region.geometry.is_valid & ~temp_region.geometry.is_empty
Expand Down

0 comments on commit ef02055

Please sign in to comment.