pbrod / nvector

Nvector is a suite of tools written in Python to solve geographical position calculations.
Other
57 stars 7 forks source link

Inconsistent return types in GeoPath.track_distance #10

Closed freol35241 closed 3 years ago

freol35241 commented 3 years ago

Hi, and thanks for this really nice concept and library. The paper is really interesting!

I ran into an inconsistency of return types from the GeoPath.track_distance-method:

From my point of view I would prefer it to consistently return scalars, that makes the most sense to me.

pbrod commented 3 years ago

Thanks for the notification on this inconsistency.

Actually, both GeoPath(pointA, pointB).track_distance(method='great_circle') and GeoPath(pointA, pointB).track_distance(method='euclidian') returns an array of m = max(len(pointA), len(pointB)) values.

Note this works either if len(pointA)==len(pointB) or len(pointA)==1 or len(pointB)==1. In other words it returns all paths between point A and B even if one or both are given as an vector of points.. However, GeoPath(pointA, pointB).track_distance(method='exact') raises a ValueError for m>1.

Also GeoPath(pointA, pointB).cross_track_distance(pointC, method='great_circle') and GeoPath(pointA, pointB).cross_track_distance(pointC, method='great_circle') both returns arrays of length m where m = max(len(pointA), len(pointB), len(pointC)) and either len(pointA)==len(pointB)==len(pointC) or len(pointA)==1 or len(pointB)==1 or len(pointC)==1.

Thus, I am inclined to document this vectorized behavior and make sure GeoPath.track_distance(method='exact') respond in the same way.

freol35241 commented 3 years ago

@pbrod

Thanks for the explanation! I actually had no idea GeoPath supported vectorized operations.

Still, in order to not confuse the user (me 😉) to much it would be nice to return scalars for the case where the input is not actually arrays of points but just single objects. Compare for example with numpy where functions such as numpy.add returns a scalar if it is provided with scalar inputs but an array if it is provided with arrays as input.

While on the topic of type inconsistencies, I also noticed that GeoPoint sometimes returns latitude and longitude as scalars and sometimes as length 1 arrays. I assume this has a similar reason/explanation?

pbrod commented 3 years ago

Ok. I fixed the issue in commit f9bfc79

Now GeoPath, GeoPoint, Nvector and ECEFvector and Pvector return scalars for the case where the input is not actually arrays of points but just single objects.