Skip longitude normalisation for projected datasets in harmonise_dims (fixes #1476)#1479
Open
gaoflow wants to merge 2 commits into
Open
Skip longitude normalisation for projected datasets in harmonise_dims (fixes #1476)#1479gaoflow wants to merge 2 commits into
gaoflow wants to merge 2 commits into
Conversation
harmonise_dims unconditionally wrapped 0-360 longitudes to -180-180 for any dataset with x-coordinates greater than 180. For a projected dataset whose x is in metres (all values > 180), this silently subtracted 360 from every x, shifting the grid 360 m to the west. Because the source CRS was still unset, the displaced grid was then reprojected incorrectly, producing spatially shifted output. Only normalise longitudes when the dataset has a geographic CRS. Datasets with a projected CRS are left untouched, and datasets without any CRS are left unchanged with a warning rather than assuming geographic coordinates. Fixes Deltares#1476
|
Thanks for your attention on this issue @gaoflow |
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.
Problem
harmonise_dimsunconditionally wraps 0-360 longitudes to -180-180 for any dataset whose x-coordinates exceed 180:For a projected dataset whose x is in metres (e.g. SVY21 / EPSG:3414, where every x value is > 180), this subtracts 360 from every coordinate, silently shifting the grid 360 m to the west. As the source CRS is still unset, the displaced grid is then reprojected incorrectly, producing spatially shifted output. No warning is raised. (Reported in #1476.)
Fix
Normalise longitudes only when the dataset has a geographic CRS:
crsin the data catalog entry to opt in.This follows the direction in the issue discussion (thanks @alimeshgi, @michaelohanrahan): an unknown CRS should not be assumed geographic, since that is the exact scenario that corrupts projected data.
Reproduction (from #1476)
Verification
tests/data_catalog/drivers/test_preprocessing.pycover all three cases (geographic normalises, no-CRS left unchanged + warns, projected-CRS left unchanged). The two bug-targeting tests fail onmainand pass with this change; the geographic case is unchanged.tests/data_catalog/drivers/suite passes (112 passed, 15 skipped).ruff checkandruff format --checkclean.