-
Notifications
You must be signed in to change notification settings - Fork 95
[Future Spherical Class] Add SPoint and SMultiPoint #465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
45e5b18
Add SPoint and SMultiPoint
ghiggi 881ed4c
Update __str__ method
ghiggi 2208589
Update __repr__ method
ghiggi fd27e14
Improve docs and small refactor
ghiggi d2581ae
Fix sphinx problem
ghiggi 9f9599d
Fix sphinx problem
ghiggi 73d9a1b
Hopefully finally maybe fix sphinx building
ghiggi 6d65d22
Remove else if else in CCoordinate.normalize
ghiggi fbe8c05
Update copyright
ghiggi 51b259a
Update file description
ghiggi 86ff4fb
Update SPoint docstring
ghiggi 5938cea
Update SMultiPoint docstring
ghiggi fef04b4
Update SPoint docstring
ghiggi ae18d6d
Update _xyz_to_vertices docstring
ghiggi f52ae78
Replace [None,:] with [np.newaxis, :]
ghiggi b2cd0ba
Update information for installing cartopy
ghiggi 0ebbe49
Address review remarks
ghiggi b8f14c2
Update repr docstring
ghiggi cd23b3c
Update str docstring
ghiggi a48ac65
Add from_degrees class method
ghiggi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) 2021 Pyresample developers | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the Free | ||
| # Software Foundation, either version 3 of the License, or (at your option) any | ||
| # later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
| # details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License along | ||
| # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| """Future features that are backwards incompatible with current functionality.""" | ||
|
|
||
| from .point import SMultiPoint, SPoint # noqa |
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,88 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) 2022 Pyresample developers | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| """Define single and multiple points on the sphere through SPoint and SMultiPoint classes.""" | ||
| import numpy as np | ||
|
|
||
| from pyresample.spherical import SCoordinate | ||
|
|
||
|
|
||
| class SPoint(SCoordinate): | ||
| """Object representing a single point on a sphere. | ||
|
|
||
| The ``lon`` and ``lat`` coordinates must be provided in radians. | ||
| """ | ||
|
|
||
| def __init__(self, lon, lat): | ||
| lon = np.asarray(lon) | ||
| lat = np.asarray(lat) | ||
| if lon.size > 1 or lat.size > 1: | ||
| raise ValueError("Use SMultiPoint to define multiple points.") | ||
| super().__init__(lon, lat) | ||
|
|
||
| @classmethod | ||
| def from_degrees(cls, lon, lat): | ||
| """Create SPoint from lon/lat coordinates in degrees.""" | ||
| return cls(np.deg2rad(lon), np.deg2rad(lat)) | ||
|
|
||
| def __str__(self): | ||
| """Get simplified representation of lon/lat arrays in radians.""" | ||
| return str((float(self.lon), float(self.lat))) | ||
|
|
||
| def __repr__(self): | ||
| """Get simplified representation of lon/lat arrays in radians.""" | ||
| return str((float(self.lon), float(self.lat))) | ||
|
|
||
| def to_shapely(self): | ||
| """Convert the SPoint to a shapely Point (in lon/lat degrees).""" | ||
| from shapely.geometry import Point | ||
| point = Point(*self.vertices_in_degrees[0]) | ||
| return point | ||
|
|
||
|
|
||
| class SMultiPoint(SCoordinate): | ||
| """Object representing multiple points on a sphere.""" | ||
|
|
||
| def __init__(self, lon, lat): | ||
| lon = np.asarray(lon) | ||
| lat = np.asarray(lat) | ||
| if lon.ndim == 0 or lat.ndim == 0: | ||
| raise ValueError("Use SPoint to define single points.") | ||
| super().__init__(lon, lat) | ||
|
|
||
| @classmethod | ||
| def from_degrees(cls, lon, lat): | ||
| """Create SMultiPoint from lon/lat coordinates in degrees.""" | ||
| return cls(np.deg2rad(lon), np.deg2rad(lat)) | ||
|
|
||
| def __eq__(self, other): | ||
| """Check equality.""" | ||
| return np.allclose(self.lon, other.lon) and np.allclose(self.lat, other.lat) | ||
|
|
||
| def __str__(self): | ||
| """Get simplified representation of lon/lat arrays in radians.""" | ||
| return str(self.vertices) | ||
|
|
||
| def __repr__(self): | ||
| """Get simplified representation of lon/lat arrays in radians.""" | ||
| return str(self.vertices) | ||
|
|
||
| def to_shapely(self): | ||
| """Convert the SMultiPoint to a shapely MultiPoint (in lon/lat degrees).""" | ||
| from shapely.geometry import MultiPoint | ||
| point = MultiPoint(self.vertices_in_degrees) | ||
| return point | ||
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.
Uh oh!
There was an error while loading. Please reload this page.