-
Notifications
You must be signed in to change notification settings - Fork 178
Planetary radius #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maureenjcohen
wants to merge
16
commits into
Parcels-code:main
Choose a base branch
from
maureenjcohen:planetary-radius
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Planetary radius #2739
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0c4fa45
Added SphericalMesh object to new mesh.py module. Contains only plane…
maureenjcohen 3ddff60
Add SphericalMesh object to imports in __init__.py.
maureenjcohen ffa6d85
Added SphericalMesh object unpacking to Xgrid.
maureenjcohen f566fe1
Switched self._radius = mesh.radius to None in second branch of if/el…
maureenjcohen 69fa293
Applied SphericalMesh/radius imports to Uxgrid as well.
maureenjcohen 6ec7382
Adjust assert_valid_mesh in typing to allow SphericalMesh to pass.
maureenjcohen b10e32c
Bugfix: missed colon in if isinstance(value, SphericalMesh) statement.
maureenjcohen 493ef8f
Moved SphericalMesh import to top rather than within function.
maureenjcohen 08fec2c
Replaced hard-coded instances of 1852 * 60 with calls to deg2m attrib…
maureenjcohen a277913
Added three tests: test that deg2m calculation works, test calculatio…
maureenjcohen da32a50
Added a check to SphericalMesh init to catch bad values of radius: no…
maureenjcohen 72be313
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0c3c1f0
Update src/parcels/_core/mesh.py
maureenjcohen ddac215
Update src/parcels/_core/mesh.py
maureenjcohen d28fa4c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ce76ee3
Update src/parcels/_core/uxgrid.py
maureenjcohen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import numpy as np | ||
|
|
||
|
|
||
| class SphericalMesh: | ||
| """Spherical mesh object with configurable planetary radius. | ||
|
|
||
| Pass to FieldSet object as ``mesh=SphericalMesh(radius=...)``. | ||
| radius is in meters; None reverts to default for Earth, where | ||
| arcdegree to meter conversion is defined as 1852 * 60 | ||
| (1852 meters per arcminute * 60 arcminutes per arcdegree). | ||
| """ | ||
|
|
||
| def __init__(self, radius: float | None = None): | ||
| if radius is not None and not isinstance(radius, (int, float, np.number)): | ||
| raise TypeError(f"radius must be a number or None, got {type(radius).__name__}") | ||
| if radius is not None and radius <= 0: | ||
| raise ValueError(f"radius must be positive, got {radius}") | ||
| self.radius = radius | ||
|
|
||
| @property | ||
| def deg2m(self) -> float: | ||
| """Meters per degree of arc.""" | ||
| if self.radius is None: | ||
| return 1852 * 60.0 | ||
| else: | ||
| return self.radius * np.pi / 180.0 | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"SphericalMesh(radius={self.radius})" |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
| import numpy as np | ||
| from cftime import datetime as cftime_datetime | ||
|
|
||
| from parcels._core.mesh import SphericalMesh | ||
|
|
||
| if TYPE_CHECKING: | ||
| import xgcm | ||
|
|
||
|
|
@@ -73,4 +75,6 @@ def _validate_against_pure_literal(value, typing_literal): | |
|
|
||
| # Assertion functions to clean user input | ||
| def assert_valid_mesh(value: Any): | ||
| if isinstance(value, SphericalMesh): | ||
| return | ||
|
Comment on lines
+78
to
+79
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VeckoTheGecko, can you check if this is correct behaviour for typing? |
||
| _validate_against_pure_literal(value, Mesh) | ||
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
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 itsdeg2mends up being 1852 * 60? (same for xgrid below)There was a problem hiding this comment.
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 Nonecould indicate a flat Mesh, so that we don't need to check for the stringmesh == flatbut insteadradius is None? But that may be another PR?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Parcels/src/parcels/_core/model.py
Line 320 in a6bb153