Skip to content

Commit 4800ae7

Browse files
HoHoclaude
authored andcommitted
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) <noreply@anthropic.com>
1 parent 222a6e5 commit 4800ae7

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Code freeze date: YYYY-MM-DD
2828
- Fixed asset count in impact logging message [#1195](https://github.com/CLIMADA-project/climada_python/pull/1195).
2929
- `Hazard.from_raster_xarray` now returns a sparse matrix instead of a sparse array [#1261](https://github.com/CLIMADA-project/climada_python/pull/1261).
3030
- Fix TCTracks.from_FAST duplicate loading from year loop [#1269](github.com/CLIMADA-project/climada_python/pull/1269)
31+
- 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)
3132

3233
### Deprecated
3334
- `Impact.calc_freq_curve()` should not be given the parameter `return_per`. Use the parameter `return_periods` in `Impact.calc_freq_curve().interpolate()` instead.

climada/util/lines_polys_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,13 +957,14 @@ def _line_to_pnts(gdf_lines, res, to_meters):
957957
line_lengths = gdf_lines.length
958958

959959
# Add warning if lines are too short w.r.t. resolution
960-
failing_res_check_count = len(line_lengths[line_lengths > 10 * res])
960+
failing_res_check_count = len(line_lengths[line_lengths < 10 * res])
961961
if failing_res_check_count > 0:
962962
LOGGER.warning(
963963
"%d lines with a length < 10*resolution were found. "
964-
"Each of these lines is disaggregate to one point. "
965-
"Reaggregatint values will thus likely lead to overestimattion. "
966-
"Consider chosing a smaller resolution or filter out the short lines. ",
964+
"Each of these lines is disaggregated to very few points, possibly "
965+
"a single one. Reaggregating values will thus likely lead to "
966+
"overestimation. Consider choosing a smaller resolution or filtering "
967+
"out the short lines. ",
967968
failing_res_check_count,
968969
)
969970

climada/util/test/test_lines_polys_handler.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,8 @@ def test_line_fractions(self):
10971097
)
10981098

10991099
def test_resolution_warning(self):
1100+
# Only the first line is shorter than 10 * resolution (10 * 1 = 10) and is
1101+
# therefore under-resolved; the two longer lines must not trigger the warning.
11001102
lines = [
11011103
LineString([[0, 0], [0, 2]]),
11021104
LineString([[0, 0], [0, 12]]),
@@ -1109,10 +1111,11 @@ def test_resolution_warning(self):
11091111
u_lp._line_to_pnts(gdf_lines, 1, False)
11101112
self.assertEqual(
11111113
ctx.records[0].message,
1112-
f"{2} lines with a length < 10*resolution were found. "
1113-
"Each of these lines is disaggregate to one point. "
1114-
"Reaggregatint values will thus likely lead to overestimattion. "
1115-
"Consider chosing a smaller resolution or filter out the short lines. ",
1114+
f"{1} lines with a length < 10*resolution were found. "
1115+
"Each of these lines is disaggregated to very few points, possibly "
1116+
"a single one. Reaggregating values will thus likely lead to "
1117+
"overestimation. Consider choosing a smaller resolution or filtering "
1118+
"out the short lines. ",
11161119
)
11171120

11181121
def test_gdf_to_grid(self):

0 commit comments

Comments
 (0)