Skip to content

fix: gridarea handles projected-CRS inputs#51

Merged
sibrenloos merged 1 commit into
Deltares:mainfrom
michaelohanrahan:fix/gridarea-projected-crs
Jun 3, 2026
Merged

fix: gridarea handles projected-CRS inputs#51
sibrenloos merged 1 commit into
Deltares:mainfrom
michaelohanrahan:fix/gridarea-projected-crs

Conversation

@michaelohanrahan

Copy link
Copy Markdown
Collaborator

workflows.emissions.gridarea called raster_utils._reggrid_area unconditionally. 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:

  1. Hydrology forcing sign flip: workflows.forcing.hydrology_forcing_em multiplies a corrupted area calculation resulting in negative precipitation in dynamicdata.nc / hydrology.bin
  2. setup_emission_raster: with area_division=True going 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

gridarea to handle projected crs
add regression test

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().
@sibrenloos sibrenloos requested a review from evetion June 3, 2026 13:47
@sibrenloos sibrenloos self-assigned this Jun 3, 2026
@sibrenloos sibrenloos removed the request for review from evetion June 3, 2026 13:48
@sibrenloos

Copy link
Copy Markdown
Collaborator

fix tested succesfully, area grid is correct and resolved issues with other conversions using area grid

@sibrenloos sibrenloos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

succesfully tested for WGS84 and EPSG:3414 testcase

@sibrenloos sibrenloos merged commit 84e4954 into Deltares:main Jun 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants