Skip to content

Planetary radius#2739

Open
maureenjcohen wants to merge 16 commits into
Parcels-code:mainfrom
maureenjcohen:planetary-radius
Open

Planetary radius#2739
maureenjcohen wants to merge 16 commits into
Parcels-code:mainfrom
maureenjcohen:planetary-radius

Conversation

@maureenjcohen

Copy link
Copy Markdown

Description

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
    • Describe how you used it (e.g., by pasting your prompt):

I used Claude to explore the repo, find the locations with hardcoded 1852 * 60 conversion factor, and suggest code snippets. I wrote the code manually (even if suggested by Claude) and made the design choices. I ran the full test suite with and without a custom radius, plus a short Mars simulation with a Mars radius.

Note: I decided to unpack the SphericalMesh object into a string to maintain the mesh == "flat"/"spherical" string comparisons throughout. This minimizes the impact of the change on the existing code. Another option would be for all mesh types to be objects with a string/flat attribute that could be checked instead, which might be useful for adding further mesh-specific properties.

@erikvansebille erikvansebille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work, @maureenjcohen! Just a few comments and suggestions below

We should also make sure to highlight this new feature in the documentation; perhaps in the Grids tutorial that @michaeldenes is working on? Can you do that, @michaeldenes?

Comment thread src/parcels/_core/mesh.py Outdated
Comment thread src/parcels/_core/mesh.py Outdated
Comment thread src/parcels/_core/uxgrid.py Outdated
Comment on lines +85 to +88
if self._radius is None:
return 1852 * 60.0
else:
return self._radius * np.pi / 180.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This may be a bit overcomplicated. Why not simply use Earth radius as default (6366707.019493707?), so that its deg2m ends up being 1852 * 60? (same for xgrid below)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An advantage would then also be that a radius is None could indicate a flat Mesh, so that we don't need to check for the string mesh == flat but instead radius is None? But that may be another PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I wasn't sure if the exact 1852 * 60 was needed, or if using Earth radius might lead to small inconsistencies when switching between v3 and v4. I think your suggestion is good.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

But if the user doesn't specify a radius, should radius default to None (flat mesh) or to Earth's? Most people are working on Earth and it might be more convenient for users not to have to put in a radius every time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should keep the default as it is now (spherical Earth), but the idea is that the correct mesh is discovered when creating the FieldSet, see below

return "spherical" if _is_coordinate_in_degrees(ds_sgrid[fpoint_x]) else "flat"

Comment thread src/parcels/_typing.py
Comment on lines +78 to +79
if isinstance(value, SphericalMesh):
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@VeckoTheGecko, can you check if this is correct behaviour for typing?

Comment thread tests/test_mesh.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice tests!

maureenjcohen and others added 4 commits July 10, 2026 10:30
Co-authored-by: Erik van Sebille <e.vansebille@uu.nl>
Co-authored-by: Erik van Sebille <e.vansebille@uu.nl>
Co-authored-by: Erik van Sebille <e.vansebille@uu.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Make planetary radius configurable

2 participants