Skip to content

feat: add spherical coordinate support via coords_crs parameter#136

Closed
opeblow wants to merge 1 commit into
mllam:mainfrom
opeblow:feat/spherical-coordinates-support
Closed

feat: add spherical coordinate support via coords_crs parameter#136
opeblow wants to merge 1 commit into
mllam:mainfrom
opeblow:feat/spherical-coordinates-support

Conversation

@opeblow

@opeblow opeblow commented Apr 11, 2026

Copy link
Copy Markdown

Describe your changes

This PR adds spherical coordinate support to weather-model-graphs,
enabling the library to work with lat/lon coordinates (EPSG:4326)
instead of only flat Cartesian coordinates.

Changes made in src/weather_model_graphs/create/base.py:

  • Added coords_crs parameter to accept input coordinate reference system
  • Added graph_crs parameter to specify projection for graph construction
  • When coords_crs is provided, coordinates are automatically projected
    from lat/lon degrees to a metre-based CRS before graph construction
  • Fixed bug where max_num_neighbours=1 caused a TypeError because
    numpy returned a scalar instead of an array — fixed with np.atleast_1d()

Added tests in tests/test_spherical_coords.py:

  • Test 1: Flat Cartesian coordinates still work (backwards compatible)
  • Test 2: Spherical/geographic coordinates work with real metre-based
    edge distances (e.g. 394,581m, 789,163m) proving haversine projection

Issue Link

closes #42

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)

@opeblow

opeblow commented May 1, 2026

Copy link
Copy Markdown
Author

Hello 👋🏿🤗

@opeblow

opeblow commented May 1, 2026

Copy link
Copy Markdown
Author

Hi, just checking in on this PR.
Happy to make any changes if needed.
Let me know if there's anything
blocking the review.

@sadamov

sadamov commented May 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution @opeblow. Closing this in favour of existing PRs that cover the same ground:

The np.atleast_1d fix for max_num_neighbours=1 (#83) is already addressed in #90 and #113.
Orphan/disconnected node detection is covered more thoroughly by #132, which also handles geometric and hierarchical consistency checks.
The PR description (spherical coordinate support) also doesn't match the actual diff - coords_crs/graph_crs have been in main for a while already.

If you want to stay involved, #90 has a change request from @leifdenby that could use a follow-up, or #132 could use review attention.

@sadamov sadamov closed this May 5, 2026
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.

Assert that all nodes are in g2m

2 participants