fix: gridarea handles projected-CRS inputs#51
Merged
sibrenloos merged 1 commit intoJun 3, 2026
Conversation
raster_utils._reggrid_area assumes lat/lon in degrees; when fed projected coordinates in metres (SVY21, Mollweide, ...) sin(radians(Northing)) returns partly-negative cell areas. This silently corrupts: - mm -> m3/s hydrology forcing conversion (flips precip sign) - setup_emission_raster with area_division=True (banded artefacts) Fix: branch on crs.is_projected and delegate to ds.raster.area_grid().
Collaborator
|
fix tested succesfully, area grid is correct and resolved issues with other conversions using area grid |
sibrenloos
approved these changes
Jun 3, 2026
sibrenloos
left a comment
Collaborator
There was a problem hiding this comment.
succesfully tested for WGS84 and EPSG:3414 testcase
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.
workflows.emissions.gridareacalledraster_utils._reggrid_areaunconditionally. That helper is a spherical-cap calculation assuming lat/lon in degrees but for projected-CRS inputs in metres (SVY21/ EPSG:3414, ESRI:54009 Mollweide, etc.)sin(radians(Northing))of large angles returns partly-negative, periodic values silently corrupting downstream.Problem manifested in:
workflows.forcing.hydrology_forcing_emmultiplies a corrupted area calculation resulting in negative precipitation indynamicdata.nc/hydrology.binarea_division=Truegoing from projected to reprojected, an interleaving pattern, banding with negative values, is observed. Noted in Negative values in emission maps #20 and worsened by going from one projected crs to another, where ghs_pop_2015 had negative values and banding.Fix
gridareato handle projected crsadd regression test