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

Vectorized numpy operations #48

Open
shisha101 opened this issue Mar 8, 2021 · 4 comments
Open

Vectorized numpy operations #48

shisha101 opened this issue Mar 8, 2021 · 4 comments

Comments

@shisha101
Copy link

Hello, I have large vectors of lat, lon, alt that I would like to convert to a local coordinate system some "enu" frame such that I can do calculations the ecef.Cartesian and the ecef.EcefKarney are doing the job but it is insanely slow to iterate over such a large number ~400,000 points. I believe that this would be much much faster if it could be vectorized with numpy and accept numpy vectors as input. Is this in anyway planned ?

what kind of effort would you estimate it would be to make such a change ? is there an alternative lib that I missed ?

I was also curious to know why the internal data types and not depend on numpy under the hood :), thanks in advance and for the great development :)

@mrJean1
Copy link
Owner

mrJean1 commented Mar 8, 2021 via email

@mrJean1
Copy link
Owner

mrJean1 commented Mar 9, 2021

The pygeodesy.EcefKarney class is a Python version of the Geocentric class transcribed from Karney's GeographicLib library in C++. That is one library to look into and perhaps other ones like pymap3d and oyb .

The pymap3d package does support numpy arrays for several functions and uses You's ecef2geodetic conversion like pygeodesy.EcefYou.reverse, see references in pygeodesy.EcefYou. In the oyb package see especially the oyb.earth and oyb.rot modules.

One other comment. Adding a vectorized version of the forward and reverse methods to the pygeodesy.Ecef... classes would be straightforward and worthwhile, depending on the specific functional requirements.

For example, those vectorized methods would accept a list, tuple or iterable of arguments and yield the results. Or, the arguments could be a numpy array wrapped in something like Numpy2LatLon (but extended to support height, named Numpy2LatLonHeight, TBD) to iterate over the numpy array.

Also, to reduce the overhead, the vectorized methods would do little or no argument checking and return a fixed, minimally required result.

Note, vectorize does not mean numpy.vectorize.

However, it remains to be seen -and measured- what the actual performance difference would be, especially for the EcefKarney.reverse case. Because that method is far more complicated and compute-intensive than other reverse -and forward- methods.

@shisha101
Copy link
Author

I see, thanks for the response, I will show you an example to clarify the functional requirements.

The Idea would be IMO to have a function call that does all the computation using numpy under the hood, if a list, tuple is passed it can be converted to numpy and the operations needed to do the forward and backward operations would be done using numpy arrays, this would yield a significant speedup compared to the normal for loop approach. since numpy.vectorize is essentially a for loop under the hood.

@mrJean1
Copy link
Owner

mrJean1 commented Mar 16, 2021

Great, looking forward to that.

Also do check the PyMap3d package, it uses numpy provided that is installed. It wraps several Python functions with numpy.vectorize. However, it is unclear how much different/better that is versus calling the function from Python.

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

No branches or pull requests

2 participants