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

add default value of Earth's radius to Haversine #176

Merged
merged 5 commits into from
Jan 20, 2021

Conversation

mkborregaard
Copy link
Contributor

I don't think it should be necessary to look up the radius of Earth every time one wants to use the Haversine formula, so I've added the equatorial radius of Earth in meters as a default. I hope most imperial unit users will agree that metric is a reasonable default for scientific libraries. Of course Earth has different radii depending on where it is measured, as it isn't a perfect sphere. Uses sensitive to this should use more specific values. FYI this same default value is used in R. source https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html

@mkborregaard
Copy link
Contributor Author

An additional concern could be that the function assumes the first point to be longitude, the second latitude, but that's not documented anywhere. Add to readme?

@dkarrasch
Copy link
Member

An additional concern could be that the function assumes the first point to be longitude, the second latitude, but that's not documented anywhere. Add to readme?

I think it's mentioned in the docstring? But adding a short remark to the README may be helpful as well. Also, the default value including its unit should be stated in the docstring.

src/haversine.jl Outdated Show resolved Hide resolved
src/haversine.jl Outdated
@@ -9,6 +9,7 @@ The computed distance has the same units as that of the radius.
struct Haversine{T<:Real} <: Metric
radius::T
end
Haversine() = Haversine(6378137.0)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to make this a Float32 or an Int32 to avoid promoting Float32 values to Float64 unnecessarily?

src/haversine.jl Show resolved Hide resolved
@nalimilan
Copy link
Member

@codecov-io
Copy link

codecov-io commented Dec 12, 2020

Codecov Report

Merging #176 (5df46ef) into master (e7e8070) will decrease coverage by 0.13%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
- Coverage   97.99%   97.86%   -0.14%     
==========================================
  Files           8        8              
  Lines         748      749       +1     
==========================================
  Hits          733      733              
- Misses         15       16       +1     
Impacted Files Coverage Δ
src/haversine.jl 95.83% <50.00%> (-4.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7e8070...5df46ef. Read the comment docs.

@dkarrasch
Copy link
Member

I didn't look too closely, but I agree that, in my area, people seem to use 6371 km, which, according to the Earth Fact Sheet linked in the OP, corresponds to the volumetric mean radius.

mkborregaard and others added 5 commits January 15, 2021 09:14
I don't think it should be necessary to look up the radius of Earth every time one wants to use the Haversine formula, so I've added the equatorial radius of Earth in meters as a default. I hope most imperial unit users will agree that metric is a reasonable default for scientific libraries. Of course Earth has different radii depending on where it is measured, as it isn't a perfect sphere. Uses sensitive to this should use more specific values. FYI this same default value is used in R. source https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
@mkborregaard
Copy link
Contributor Author

Sorry for delay - I've edited as requested

@dkarrasch dkarrasch merged commit 23b0023 into JuliaStats:master Jan 20, 2021
@nalimilan
Copy link
Member

Sorry for not commenting earlier, but this needs a test.

@dkarrasch
Copy link
Member

I have tests in #203.

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.

4 participants