Fix inverted resolution check in _line_to_pnts (under-resolved line warning)#1303
Open
martinguthrie93 wants to merge 2 commits into
Open
Fix inverted resolution check in _line_to_pnts (under-resolved line warning)#1303martinguthrie93 wants to merge 2 commits into
_line_to_pnts (under-resolved line warning)#1303martinguthrie93 wants to merge 2 commits into
Conversation
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 CLIMADA-project#1302 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this PR:
climada.util.lines_polys_handler._line_to_pnts. The mask used to count under-resolved lines selected lines longer than10 * resolution(line_lengths > 10 * res), while the inline comment and the log message both describe lines shorter than10 * resolution. The comparison is now< 10 * res, so the warning is raised for the lines it is meant to flag.disaggregate→disaggregated,Reaggregatint→Reaggregating,overestimattion→overestimation,chosing→choosing).test_resolution_warning, which previously asserted the buggy behavior (it expected 2 flagged lines for input lengths[2, 12, 20]withres = 1, even though lengths 12 and 20 are longer than10 * res = 10). The expected count is now1, corresponding to the single genuinely under-resolved line (length 2).Why this matters
When a line exposure (road, pipeline, transmission line, river reach, …) is disaggregated into points, the number of points is
round(length / res). A line that is short relative torescollapses to very few points — in the limit, a single representative point — and re-aggregating an impact computed on too few points typically overestimates that feature's impact. The warning exists to alert users to this situation.Because the comparison was inverted:
Only the warning path is affected; the returned geometry is unchanged.
Verification
The existing test
test_resolution_warninghad encoded the contradiction (asserting "2 lines with a length < 10*resolution" for two lines that are in fact longer than10 * res). I reproduced the mask logic in isolation to confirm the corrected behavior:Note: the full CLIMADA test suite was not run in my local environment (CLIMADA and its geospatial dependencies were not installed there); the change is confined to the warning branch and its dedicated unit test, which I verified matches exactly.
This PR fixes #1302
PR Author Checklist
develop)blackreports both changed files unchanged)