From 4800ae76687281e0639430a00be1ea79527d10da Mon Sep 17 00:00:00 2001 From: HoHo Date: Fri, 3 Jul 2026 15:09:43 +0200 Subject: [PATCH 1/2] Fix inverted resolution check in _line_to_pnts The warning meant to flag under-resolved line exposures in `climada.util.lines_polys_handler._line_to_pnts` used an inverted comparison: it counted lines *longer* than `10 * resolution` while its comment and message describe lines *shorter* than that. As a result, genuinely under-resolved lines (which collapse to too few points and overestimate the re-aggregated impact) were skipped silently, while well-resolved long lines produced a spurious, self-contradicting warning. Flip the comparison to `< 10 * res`, correct the message wording and typos, and update `test_resolution_warning` accordingly. Fixes #1302 Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 1 + climada/util/lines_polys_handler.py | 9 +++++---- climada/util/test/test_lines_polys_handler.py | 11 +++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3eb4e99e..dd97852cbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Code freeze date: YYYY-MM-DD - Fixed asset count in impact logging message [#1195](https://github.com/CLIMADA-project/climada_python/pull/1195). - `Hazard.from_raster_xarray` now returns a sparse matrix instead of a sparse array [#1261](https://github.com/CLIMADA-project/climada_python/pull/1261). - Fix TCTracks.from_FAST duplicate loading from year loop [#1269](github.com/CLIMADA-project/climada_python/pull/1269) +- Fixed inverted resolution check in `climada.util.lines_polys_handler._line_to_pnts`: the "under-resolved lines" warning was triggered for lines *longer* than `10 * resolution` instead of *shorter*, so genuinely under-resolved line exposures were silently disaggregated to too few points (overestimating the re-aggregated impact) while well-resolved lines produced a spurious warning. The warning message wording and typos were also corrected [#1303](https://github.com/CLIMADA-project/climada_python/issues/1302) ### Deprecated - `Impact.calc_freq_curve()` should not be given the parameter `return_per`. Use the parameter `return_periods` in `Impact.calc_freq_curve().interpolate()` instead. diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index ee2058a68d..90cc86a993 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -957,13 +957,14 @@ def _line_to_pnts(gdf_lines, res, to_meters): line_lengths = gdf_lines.length # Add warning if lines are too short w.r.t. resolution - failing_res_check_count = len(line_lengths[line_lengths > 10 * res]) + failing_res_check_count = len(line_lengths[line_lengths < 10 * res]) if failing_res_check_count > 0: 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. " - "Consider chosing a smaller resolution or filter out the short lines. ", + "Each of these lines is disaggregated to very few points, possibly " + "a single one. Reaggregating values will thus likely lead to " + "overestimation. Consider choosing a smaller resolution or filtering " + "out the short lines. ", failing_res_check_count, ) diff --git a/climada/util/test/test_lines_polys_handler.py b/climada/util/test/test_lines_polys_handler.py index c320e894ab..9b59fadd1a 100644 --- a/climada/util/test/test_lines_polys_handler.py +++ b/climada/util/test/test_lines_polys_handler.py @@ -1097,6 +1097,8 @@ def test_line_fractions(self): ) def test_resolution_warning(self): + # Only the first line is shorter than 10 * resolution (10 * 1 = 10) and is + # therefore under-resolved; the two longer lines must not trigger the warning. lines = [ LineString([[0, 0], [0, 2]]), LineString([[0, 0], [0, 12]]), @@ -1109,10 +1111,11 @@ def test_resolution_warning(self): u_lp._line_to_pnts(gdf_lines, 1, False) self.assertEqual( ctx.records[0].message, - f"{2} 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. " - "Consider chosing a smaller resolution or filter out the short lines. ", + f"{1} lines with a length < 10*resolution were found. " + "Each of these lines is disaggregated to very few points, possibly " + "a single one. Reaggregating values will thus likely lead to " + "overestimation. Consider choosing a smaller resolution or filtering " + "out the short lines. ", ) def test_gdf_to_grid(self): From 8bba5625681da85a4108c899be88a673bbfdfd13 Mon Sep 17 00:00:00 2001 From: HoHo Date: Fri, 3 Jul 2026 15:11:29 +0200 Subject: [PATCH 2/2] Point CHANGELOG entry to PR #1303 Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd97852cbd..a992d7aa3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ Code freeze date: YYYY-MM-DD - Fixed asset count in impact logging message [#1195](https://github.com/CLIMADA-project/climada_python/pull/1195). - `Hazard.from_raster_xarray` now returns a sparse matrix instead of a sparse array [#1261](https://github.com/CLIMADA-project/climada_python/pull/1261). - Fix TCTracks.from_FAST duplicate loading from year loop [#1269](github.com/CLIMADA-project/climada_python/pull/1269) -- Fixed inverted resolution check in `climada.util.lines_polys_handler._line_to_pnts`: the "under-resolved lines" warning was triggered for lines *longer* than `10 * resolution` instead of *shorter*, so genuinely under-resolved line exposures were silently disaggregated to too few points (overestimating the re-aggregated impact) while well-resolved lines produced a spurious warning. The warning message wording and typos were also corrected [#1303](https://github.com/CLIMADA-project/climada_python/issues/1302) +- Fixed inverted resolution check in `climada.util.lines_polys_handler._line_to_pnts`: the "under-resolved lines" warning was triggered for lines *longer* than `10 * resolution` instead of *shorter*, so genuinely under-resolved line exposures were silently disaggregated to too few points (overestimating the re-aggregated impact) while well-resolved lines produced a spurious warning. The warning message wording and typos were also corrected [#1303](https://github.com/CLIMADA-project/climada_python/pull/1303) ### Deprecated - `Impact.calc_freq_curve()` should not be given the parameter `return_per`. Use the parameter `return_periods` in `Impact.calc_freq_curve().interpolate()` instead.