Skip to content
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

Use geographiclib in lieu of pyproj #75

Merged
merged 2 commits into from
Sep 22, 2022
Merged

Conversation

ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Jun 27, 2022

Geographiclib is a stable, well maintained, and pure python library. We only use pyproj here for the great_distance calculation, so we should be OK with this change.

The results are similar and geographiclib algorithms do not suffer from this issue. See for a poor man's comparison https://nbviewer.org/gist/ocefpaf/7d290f94e5ffec1af560ded41d8c0dd1

Closes #72.

PS: only the doc build is failing. That should be fixed in #73.

_, _, dist[1:] = g.inv(lon_arr[:-1], lat_arr[:-1], lon_arr[1:], lat_arr[1:])
positions = list(zip(lat_arr, lon_arr))
positions_pairs = list(zip(positions[:-1], positions[1:]))
dist[1:] = [Geodesic.WGS84.Inverse(*pair[0], *pair[1])["s12"] for pair in positions_pairs]
Copy link
Member Author

Choose a reason for hiding this comment

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

@kwilcox I'm pretty sure you have a thousand more efficient ways for doing this 😬. Feel free to change it to a way that suits ioos_qc better.

Copy link
Member

Choose a reason for hiding this comment

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

Vectorizing speeds it up a tiny bit. I played with numba but the optimization isn't good using Inverse in the loop and it ends up being slower.

def great_circle_distance_vectorize(lat_arr, lon_arr):
    def gc(y1, x1, y2, x2):
        return Geodesic.WGS84.Inverse(y1, x1, y2, x2)["s12"]
    dist = np.ma.zeros(lon_arr.size, dtype=np.float64)
    dv = np.vectorize(gc)
    dist[1:] = dv(lat_arr[:-1], lon_arr[:-1], lat_arr[1:], lon_arr[1:])
    return dist

@ocefpaf ocefpaf requested a review from kwilcox June 27, 2022 14:09
@ocefpaf ocefpaf mentioned this pull request Jul 21, 2022
@kwilcox kwilcox merged commit ae79f36 into ioos:master Sep 22, 2022
@ocefpaf ocefpaf deleted the drop_pyproj branch September 22, 2022 16:01
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.

Drop pyproj
2 participants