diff --git a/scripts/build_industrial_distribution_key.py b/scripts/build_industrial_distribution_key.py index ce5a59ed..909268ff 100644 --- a/scripts/build_industrial_distribution_key.py +++ b/scripts/build_industrial_distribution_key.py @@ -3,7 +3,11 @@ import uuid import pandas as pd import geopandas as gpd + from itertools import product +from distutils.version import StrictVersion + +gpd_version = StrictVersion(gpd.__version__) def locate_missing_industrial_sites(df): @@ -69,7 +73,8 @@ def prepare_hotmaps_database(regions): gdf = gpd.GeoDataFrame(df, geometry='coordinates', crs="EPSG:4326") - gdf = gpd.sjoin(gdf, regions, how="inner", op='within') + kws = dict(op="within") if gpd_version < '0.10' else dict(predicate="within") + gdf = gpd.sjoin(gdf, regions, how="inner", **kws) gdf.rename(columns={"index_right": "bus"}, inplace=True) gdf["country"] = gdf.bus.str[:2] diff --git a/scripts/cluster_gas_network.py b/scripts/cluster_gas_network.py index c128f47a..4a74dff1 100755 --- a/scripts/cluster_gas_network.py +++ b/scripts/cluster_gas_network.py @@ -8,7 +8,9 @@ import geopandas as gpd from shapely import wkt from pypsa.geo import haversine_pts +from distutils.version import StrictVersion +gpd_version = StrictVersion(gpd.__version__) def concat_gdf(gdf_list, crs='EPSG:4326'): """Concatenate multiple geopandas dataframes with common coordinate reference system (crs).""" @@ -32,12 +34,13 @@ def build_clustered_gas_network(df, bus_regions, length_factor=1.25): gdf = gpd.GeoDataFrame(geometry=df[f"point{i}"], crs="EPSG:4326") - bus_mapping = gpd.sjoin(gdf, bus_regions, how="left", op="within").index_right + kws = dict(op="within") if gpd_version < '0.10' else dict(predicate="within") + bus_mapping = gpd.sjoin(gdf, bus_regions, how="left", **kws).index_right bus_mapping = bus_mapping.groupby(bus_mapping.index).first() df[f"bus{i}"] = bus_mapping - df[f"point{i}"] = df[f"bus{i}"].map(bus_regions.centroid) + df[f"point{i}"] = df[f"bus{i}"].map(bus_regions.to_crs(3035).centroid.to_crs(4326)) # drop pipes where not both buses are inside regions df = df.loc[~df.bus0.isna() & ~df.bus1.isna()] diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 2f10443d..f3c0a401 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -543,17 +543,6 @@ def average_every_nhours(n, offset): logger.info(f'Resampling the network to {offset}') m = n.copy(with_time=False) - # TODO is this still needed? - #fix copying of network attributes - #copied from pypsa/io.py, should be in pypsa/components.py#Network.copy() - allowed_types = (float, int, bool, str) + tuple(np.typeDict.values()) - attrs = dict((attr, getattr(n, attr)) - for attr in dir(n) - if (not attr.startswith("__") and - isinstance(getattr(n,attr), allowed_types))) - for k,v in attrs.items(): - setattr(m,k,v) - snapshot_weightings = n.snapshot_weightings.resample(offset).sum() m.set_snapshots(snapshot_weightings.index) m.snapshot_weightings = snapshot_weightings