Skip to content

Commit

Permalink
Merge branch '309-reduce-warnings' into 'develop'
Browse files Browse the repository at this point in the history
Resolve "Reduce warnings"

Closes #309

See merge request iek-3/shared-code/fine!323
  • Loading branch information
k-knosala committed Feb 8, 2024
2 parents f1d98fe + 087ac0a commit 9ba5d4b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
18 changes: 9 additions & 9 deletions fine/IOManagement/standardIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def plotLocations(
locationsShapeFileName,
indexColumn,
plotLocNames=False,
crs="epsg:3035",
crs="EPSG:3035",
faceColor="none",
edgeColor="black",
fig=None,
Expand Down Expand Up @@ -840,7 +840,7 @@ def plotLocations(
:type plotLocNames: boolean
:param crs: coordinate reference system
|br| * the default value is 'epsg:3035'
|br| * the default value is 'EPSG:3035'
:type crs: string
:param faceColor: face color of the plot
Expand Down Expand Up @@ -884,7 +884,7 @@ def plotLocations(
:type dpi: scalar > 0
"""

gdf = gpd.read_file(locationsShapeFileName).to_crs({"init": crs})
gdf = gpd.read_file(locationsShapeFileName).to_crs(crs)

if ax is None:
fig, ax = plt.subplots(1, 1, figsize=figsize, **kwargs)
Expand Down Expand Up @@ -919,7 +919,7 @@ def plotTransmission(
loc0,
loc1,
ip=0,
crs="epsg:3035",
crs="EPSG:3035",
variableName="capacityVariablesOptimum",
color="k",
loc=7,
Expand Down Expand Up @@ -961,7 +961,7 @@ def plotTransmission(
:type ip: int
:param crs: coordinate reference system
|br| * the default value is 'epsg:3035'
|br| * the default value is 'EPSG:3035'
:type crs: string
:param variableName: parameter for plotting installed capacity ('_capacityVariablesOptimum') or operation
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def plotTransmission(
if capMax == 0:
return fig, ax
cap = cap / capMax
gdf = gpd.read_file(transmissionShapeFileName).to_crs({"init": crs})
gdf = gpd.read_file(transmissionShapeFileName).to_crs(crs)

if ax is None:
fig, ax = plt.subplots(1, 1, figsize=figsize, **kwargs)
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def plotLocationalColorMap(
ip=0,
perArea=True,
areaFactor=1e3,
crs="epsg:3035",
crs="EPSG:3035",
variableName="capacityVariablesOptimum",
doSum=False,
cmap="viridis",
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def plotLocationalColorMap(
:type areaFactor: scalar > 0
:param crs: coordinate reference system
|br| * the default value is 'epsg:3035'
|br| * the default value is 'EPSG:3035'
:type crs: string
:param variableName: parameter for plotting installed capacity ('_capacityVariablesOptimum') or operation
Expand Down Expand Up @@ -1184,7 +1184,7 @@ def plotLocationalColorMap(

if doSum:
data = data.sum(axis=1)
gdf = gpd.read_file(locationsShapeFileName).to_crs({"init": crs})
gdf = gpd.read_file(locationsShapeFileName).to_crs(crs)

# Make sure the data and gdf indices match
## 1. Sort the indices to obtain same order
Expand Down
9 changes: 4 additions & 5 deletions fine/aggregations/spatialAggregation/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import logging
import warnings
from copy import deepcopy

import numpy as np
import xarray as xr
from shapely.ops import cascaded_union
from shapely.geometry.multipolygon import MultiPolygon
from shapely.geometry.polygon import Polygon
import pandas as pd
import xarray as xr
from shapely.ops import unary_union

logger_representation = logging.getLogger("spatial_representation")

Expand Down Expand Up @@ -46,7 +45,7 @@ def aggregate_geometries(xr_data_array_in, sub_to_sup_region_id_dict):
for sub_region_id_list in sub_to_sup_region_id_dict.values():
temp_shape_list = list(xr_data_array_in.sel(space=sub_region_id_list).values)

shape_union = cascaded_union(temp_shape_list)
shape_union = unary_union(temp_shape_list)

shape_list.append(shape_union)

Expand Down
2 changes: 1 addition & 1 deletion fine/aggregations/spatialAggregation/managerUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_gdf(df, geometries, crs=3035, file_path=None, files_name="xr_regions"
:rtype: gpd.GeoDataFrame
"""

gdf = gpd.GeoDataFrame(df, geometry=geometries, crs=f"epsg:{crs}")
gdf = gpd.GeoDataFrame(df, geometry=geometries, crs=f"EPSG:{crs}")

if file_path is not None:
gdf.reset_index(drop=True, inplace=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def rasterize_xr_ds(
)

# STEP 2. Match the CRS of shapefile to that of the dataset
shp_file = shp_file.to_crs({"init": gridded_RE_ds.attrs[CRS_attr]})
shp_file = shp_file.to_crs(gridded_RE_ds.attrs[CRS_attr])

# STEP 3. rasterize each geometry and add it to new data_var "rasters"

Expand Down
4 changes: 2 additions & 2 deletions test/aggregations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def gridded_RE_data(scope="session"):

test_xr_ds = xr.Dataset({"capacity": capacity_xr_da, "capfac": capfac_xr_da})

test_xr_ds.attrs["SRS"] = "epsg:3035"
test_xr_ds.attrs["SRS"] = "EPSG:3035"

return test_xr_ds

Expand Down Expand Up @@ -458,6 +458,6 @@ def sample_shapefile(scope="session"):

df = pd.DataFrame({"region_ids": ["reg_01", "reg_02"]})

gdf = gpd.GeoDataFrame(df, geometry=test_geometries, crs={"init": "epsg:3035"})
gdf = gpd.GeoDataFrame(df, geometry=test_geometries, crs="EPSG:3035")

return gdf
17 changes: 14 additions & 3 deletions test/aggregations/spatialAggregation/test_groupingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,20 @@ def test_get_custom_distance_matrix(

# FUNCTION CALL
n_regions = 3
output_dist_matrix = gprUtils.get_custom_distance_matrix(
test_ts_dict, test_1d_dict, test_2d_dict, n_regions, weights
)
if isinstance(weights, dict):
if not "variables" in weights:
with pytest.warns(UserWarning):
output_dist_matrix = gprUtils.get_custom_distance_matrix(
test_ts_dict, test_1d_dict, test_2d_dict, n_regions, weights
)
else:
output_dist_matrix = gprUtils.get_custom_distance_matrix(
test_ts_dict, test_1d_dict, test_2d_dict, n_regions, weights
)
else:
output_dist_matrix = gprUtils.get_custom_distance_matrix(
test_ts_dict, test_1d_dict, test_2d_dict, n_regions, weights
)

# ASSERTION
assert np.isclose(expected_dist_matrix, output_dist_matrix).all()
Expand Down
8 changes: 0 additions & 8 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ def multi_node_test_esM_init(esM_init):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand All @@ -745,7 +744,6 @@ def multi_node_test_esM_init(esM_init):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand Down Expand Up @@ -1262,7 +1260,6 @@ def multi_node_test_esM_optimized(esM_init):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand All @@ -1284,7 +1281,6 @@ def multi_node_test_esM_optimized(esM_init):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand Down Expand Up @@ -1757,7 +1753,6 @@ def multi_node_test_esM_init(scope="session"):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand All @@ -1780,7 +1775,6 @@ def multi_node_test_esM_init(scope="session"):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand Down Expand Up @@ -2228,7 +2222,6 @@ def multi_node_test_esM_optimized(scope="session"):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand All @@ -2250,7 +2243,6 @@ def multi_node_test_esM_optimized(scope="session"):
distances=data["Pipelines, distances"],
hasCapacityVariable=True,
hasIsBuiltBinaryVariable=False,
bigM=300,
locationalEligibility=data["Pipelines, eligibility"],
capacityMax=data["Pipelines, eligibility"] * 15,
sharedPotentialID="pipelines",
Expand Down

0 comments on commit 9ba5d4b

Please sign in to comment.