From bed6bfbb4eebf88f949c54398722cfa65d654d31 Mon Sep 17 00:00:00 2001 From: luseverin Date: Wed, 5 Feb 2025 09:33:11 +0100 Subject: [PATCH 1/4] Use position-based index for reaggregation --- climada/util/lines_polys_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index ee2058a68d..38d913d17c 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -232,13 +232,13 @@ def _aggregate_impact_mat(imp_pnt, gdf_pnt, agg_met): row_pnt = np.arange(len(col_geom)) if agg_met is AggMethod.SUM: - mask = np.ones(len(col_geom)) + mask = np.ones(len(row_pnt)) else: raise NotImplementedError( f"The available aggregation methods are {AggMethod._member_names_}" ) # pylint: disable=no-member, protected-access csr_mask = sp.sparse.csr_matrix( - (mask, (row_pnt, col_geom)), shape=(len(row_pnt), len(np.unique(col_geom))) + (mask, (row_pnt, row_pnt)), shape=(len(row_pnt), len(np.unique(row_pnt))) ) return imp_pnt.imp_mat.dot(csr_mask) From e18290916008fec94d7110f93115156e3f00ccba Mon Sep 17 00:00:00 2001 From: luseverin Date: Wed, 5 Feb 2025 09:54:16 +0100 Subject: [PATCH 2/4] Remove useless remaining code parts --- climada/util/lines_polys_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index 38d913d17c..b56d44db42 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -228,7 +228,7 @@ def _aggregate_impact_mat(imp_pnt, gdf_pnt, agg_met): col_geom = gdf_pnt.index.get_level_values(level=0) # Converts string multi-index level 0 to integer index - col_geom = np.sort(np.unique(col_geom, return_inverse=True)[1]) + # col_geom = np.sort(np.unique(col_geom, return_inverse=True)[1]) row_pnt = np.arange(len(col_geom)) if agg_met is AggMethod.SUM: @@ -238,7 +238,7 @@ def _aggregate_impact_mat(imp_pnt, gdf_pnt, agg_met): f"The available aggregation methods are {AggMethod._member_names_}" ) # pylint: disable=no-member, protected-access csr_mask = sp.sparse.csr_matrix( - (mask, (row_pnt, row_pnt)), shape=(len(row_pnt), len(np.unique(row_pnt))) + (mask, (row_pnt, row_pnt)), shape=(len(row_pnt), len(row_pnt)) ) return imp_pnt.imp_mat.dot(csr_mask) From e69e584fc2beda31d89f0368bd78289955f4595d Mon Sep 17 00:00:00 2001 From: luseverin Date: Wed, 5 Feb 2025 11:18:07 +0100 Subject: [PATCH 3/4] Fix some typos --- climada/util/lines_polys_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index b56d44db42..632c6a9b49 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -962,7 +962,7 @@ def _line_to_pnts(gdf_lines, res, to_meters): LOGGER.warning( "%d lines with a length < 10*resolution were found. " "Each of these lines is disaggregate to one point. " - "Reaggregatint values will thus likely lead to overestimattion. " + "Reaggregating values will thus likely lead to overestimation. " "Consider chosing a smaller resolution or filter out the short lines. ", failing_res_check_count, ) From dae314964faf293b1de25cf08a2a7b14074f02a6 Mon Sep 17 00:00:00 2001 From: luseverin Date: Wed, 5 Feb 2025 11:22:46 +0100 Subject: [PATCH 4/4] Revert changes --- climada/util/lines_polys_handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index 632c6a9b49..38d913d17c 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -228,7 +228,7 @@ def _aggregate_impact_mat(imp_pnt, gdf_pnt, agg_met): col_geom = gdf_pnt.index.get_level_values(level=0) # Converts string multi-index level 0 to integer index - # col_geom = np.sort(np.unique(col_geom, return_inverse=True)[1]) + col_geom = np.sort(np.unique(col_geom, return_inverse=True)[1]) row_pnt = np.arange(len(col_geom)) if agg_met is AggMethod.SUM: @@ -238,7 +238,7 @@ def _aggregate_impact_mat(imp_pnt, gdf_pnt, agg_met): f"The available aggregation methods are {AggMethod._member_names_}" ) # pylint: disable=no-member, protected-access csr_mask = sp.sparse.csr_matrix( - (mask, (row_pnt, row_pnt)), shape=(len(row_pnt), len(row_pnt)) + (mask, (row_pnt, row_pnt)), shape=(len(row_pnt), len(np.unique(row_pnt))) ) return imp_pnt.imp_mat.dot(csr_mask) @@ -962,7 +962,7 @@ def _line_to_pnts(gdf_lines, res, to_meters): LOGGER.warning( "%d lines with a length < 10*resolution were found. " "Each of these lines is disaggregate to one point. " - "Reaggregating values will thus likely lead to overestimation. " + "Reaggregatint values will thus likely lead to overestimattion. " "Consider chosing a smaller resolution or filter out the short lines. ", failing_res_check_count, )