Skip to content

Fix default bounds incorrect with Copernicus Marine EPSG:4326 data#32

Merged
Shane98c merged 1 commit intocarbonplan:mainfrom
james-willis:fix/issue-28-copernicus-bounds
Mar 6, 2026
Merged

Fix default bounds incorrect with Copernicus Marine EPSG:4326 data#32
Shane98c merged 1 commit intocarbonplan:mainfrom
james-willis:fix/issue-28-copernicus-bounds

Conversation

@james-willis
Copy link
Copy Markdown
Contributor

@james-willis james-willis commented Feb 18, 2026

Summary

Fix rendering issue where western hemisphere was missing when displaying Copernicus Marine EPSG:4326 data without explicit proj4 string.

Fixes #28

Root Cause

Copernicus Marine data has coordinates like xMin: -180.04166 due to half-pixel expansion at array edges. The lonToMercatorNorm() function was wrapping these values (-180.04+179.96), causing mercatorBounds to collapse to a tiny sliver instead of spanning the full globe.

Fix

Change lonToMercatorNorm() to clamp to [-180, 180] instead of wrapping.

Why removing wraparound is safe

The old wraparound logic (lon > 180lon - 360) was intended to handle datasets using 0-360° longitude conventions. However:

  1. It was already broken - wraparound only handled individual values, not the relationship between bounds. A dataset from 140° to 220° would produce x0 > x1, breaking bounds entirely.

  2. No real use case - Zarr datasets are typically regional (well within ±180°), global with standard coordinates, or use projected CRS. Antimeridian-crossing data would be stored as separate regions or in a projected CRS, not with wrapped longitudes.

  3. Clamping is correct - Values slightly outside [-180, 180] are due to half-pixel expansion or floating point precision, not actual wraparound.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

@james-willis is attempting to deploy a commit to the carbonplan Team on Vercel.

A member of the Team first needs to authorize it.

When rendering Copernicus Marine data without explicit proj4 string, the
western hemisphere was missing because coordinate arrays slightly exceed
[-180, 180] due to half-pixel expansion (e.g., xMin: -180.04166).

The lonToMercatorNorm() function was wrapping these values (e.g., -180.04
became +179.96), causing mercatorBounds to collapse to a tiny sliver.

Fix: Change lonToMercatorNorm() to always clamp to [-180, 180] instead of
wrapping. Wrapping doesn't make sense for real geographic data - values
outside the range are due to half-pixel expansion or floating point
precision, not actual wraparound.

Fixes carbonplan#28
@james-willis james-willis force-pushed the fix/issue-28-copernicus-bounds branch from 4862a94 to 317e8d9 Compare February 18, 2026 07:00
@james-willis james-willis marked this pull request as ready for review February 18, 2026 07:06
@adamshaylor
Copy link
Copy Markdown

Thanks for the quick turnaround! Looks good. This is without the proj4 workaround:

Screenshot 2026-02-18 at 10 10 56

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zarr-layer Ready Ready Preview, Comment Mar 6, 2026 9:29pm

Request Review

@Shane98c Shane98c merged commit 8e4b782 into carbonplan:main Mar 6, 2026
1 check failed
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.

Default bounds incorrect with Copernicus Marine data

3 participants