-
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
18
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
18 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 f781eeb
Modified radius setting so default is EARTH_RADIUS (specified in mesh…
maureenjcohen 9ac08fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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,26 @@ | ||
| import numpy as np | ||
|
|
||
| EARTH_RADIUS = 6366707.019493707 | ||
|
|
||
|
|
||
| class SphericalMesh: | ||
| """Spherical mesh object with configurable planetary radius. | ||
|
|
||
| Pass to FieldSet object as ``mesh=SphericalMesh(radius=...)``. | ||
| radius is in meters; defaults to Earth radius. | ||
| """ | ||
|
|
||
| def __init__(self, radius: float = EARTH_RADIUS): | ||
| if not isinstance(radius, (int, float, np.number)): | ||
| raise TypeError(f"radius must be a number, got {type(radius).__name__}") | ||
| if radius <= 0: | ||
| raise ValueError(f"radius must be positive, got {radius}") | ||
| self.radius = radius | ||
|
|
||
| @property | ||
| def deg2m(self) -> float: | ||
| """Meters per degree of arc.""" | ||
| 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.
PR looks good to me! The only question I have for @VeckoTheGecko is if this combination of
grid._meshas a string and theSphericalMeshclass is not too obfuscating/confusing. Would it be worth to streamline this and e.g. use the class throughout? Or shall we do that in a next PR?