Summary
climada.util.lines_polys_handler._line_to_pnts emits a warning that is meant to flag under-resolved line exposures (lines that are short relative to the chosen disaggregation resolution). The comparison used to build this warning is inverted, so the warning fires for the wrong set of lines: it counts lines that are longer than 10 * resolution and mislabels them as being shorter, while genuinely short, under-resolved lines are skipped silently.
Location
climada/util/lines_polys_handler.py, in _line_to_pnts:
# Add warning if lines are too short w.r.t. resolution
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. ",
failing_res_check_count,
)
Why this is wrong
When a line exposure (e.g. a road, pipeline, transmission line, or river reach) is disaggregated into points, the number of points is round(length / res) (see _pnts_per_line). A line that is short relative to res collapses to very few points — in the limit, a single representative point. Re-aggregating an impact computed on too few points typically overestimates the impact for that feature. The warning exists precisely to alert the user to this situation.
Both the inline comment ("lines are too short w.r.t. resolution") and the log message ("lines with a length < 10*resolution", "disaggregated to one point") describe short lines. The mask, however, selects long lines:
line_lengths[line_lengths > 10 * res] # selects long, well-resolved lines
The net effect is a genuine geospatial/analysis defect:
- False negatives (the real hazard): users whose line exposures are actually under-resolved receive no warning and may unknowingly work with overestimated impacts.
- False positives (noise): users with well-resolved long lines receive a warning that contradicts its own text.
This is confirmed by the existing test test_resolution_warning, which itself encodes the contradiction: it feeds lines of length [2, 12, 20] with res = 1 (so 10 * res = 10) and asserts that 2 lines were found "with a length < 10*resolution" — but the two counted lines (lengths 12 and 20) are in fact longer than 10 * res, not shorter.
Reproduction
import numpy as np
line_lengths = np.array([2.0, 12.0, 20.0]) # degrees
res = 1 # 10 * res == 10
# current (buggy) mask
print(len(line_lengths[line_lengths > 10 * res])) # -> 2 (the LONG lines 12, 20)
# intended mask, matching the message text
print(len(line_lengths[line_lengths < 10 * res])) # -> 1 (the short line 2)
Expected behavior
The warning should count lines whose length is below 10 * res, matching the comment and the message text, so that under-resolved line exposures are the ones flagged.
Proposed fix
Change the comparison from > to <, and correct the message wording and typos ("disaggregate" → "disaggregated", "Reaggregatint" → "Reaggregating", "overestimattion" → "overestimation", "chosing" → "choosing"). The existing test_resolution_warning is updated accordingly (the expected count becomes 1).
A pull request implementing this fix follows.
Environment
- CLIMADA
6.1.0 (also present on main / develop)
Summary
climada.util.lines_polys_handler._line_to_pntsemits a warning that is meant to flag under-resolved line exposures (lines that are short relative to the chosen disaggregation resolution). The comparison used to build this warning is inverted, so the warning fires for the wrong set of lines: it counts lines that are longer than10 * resolutionand mislabels them as being shorter, while genuinely short, under-resolved lines are skipped silently.Location
climada/util/lines_polys_handler.py, in_line_to_pnts:Why this is wrong
When a line exposure (e.g. a road, pipeline, transmission line, or river reach) is disaggregated into points, the number of points is
round(length / res)(see_pnts_per_line). A line that is short relative torescollapses to very few points — in the limit, a single representative point. Re-aggregating an impact computed on too few points typically overestimates the impact for that feature. The warning exists precisely to alert the user to this situation.Both the inline comment ("lines are too short w.r.t. resolution") and the log message ("lines with a length < 10*resolution", "disaggregated to one point") describe short lines. The mask, however, selects long lines:
The net effect is a genuine geospatial/analysis defect:
This is confirmed by the existing test
test_resolution_warning, which itself encodes the contradiction: it feeds lines of length[2, 12, 20]withres = 1(so10 * res = 10) and asserts that 2 lines were found "with a length < 10*resolution" — but the two counted lines (lengths 12 and 20) are in fact longer than10 * res, not shorter.Reproduction
Expected behavior
The warning should count lines whose length is below
10 * res, matching the comment and the message text, so that under-resolved line exposures are the ones flagged.Proposed fix
Change the comparison from
>to<, and correct the message wording and typos ("disaggregate" → "disaggregated", "Reaggregatint" → "Reaggregating", "overestimattion" → "overestimation", "chosing" → "choosing"). The existingtest_resolution_warningis updated accordingly (the expected count becomes1).A pull request implementing this fix follows.
Environment
6.1.0(also present onmain/develop)