Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.3%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Calculate the distance between 2 points on Earth
Basic Info
Statistics
- Stars: 346
- Watchers: 11
- Forks: 64
- Open Issues: 5
- Releases: 0
Topics
Metadata Files
README.md
Haversine
Calculate the distance (in various units) between two points on Earth using their latitude and longitude.
Installation
sh
pip install haversine
Usage
Calculate the distance between Lyon and Paris
```python from haversine import haversine, Unit
lyon = (45.7597, 4.8422) # (lat, lon) paris = (48.8567, 2.3508)
haversine(lyon, paris)
392.2172595594006 # in kilometers
haversine(lyon, paris, unit=Unit.MILES)
243.71250609539814 # in miles
you can also use the string abbreviation for units:
haversine(lyon, paris, unit='mi')
243.71250609539814 # in miles
haversine(lyon, paris, unit=Unit.NAUTICAL_MILES)
211.78037755311516 # in nautical miles ```
The lat/lon values need to be provided in degrees of the ranges -90,90 and -180,180.
If values are outside their ranges, an error will be raised. This can be avoided by automatic normalization via the normalize parameter.
The haversine.Unit enum contains all supported units:
```python import haversine
print(tuple(haversine.Unit)) ```
outputs
text
(<Unit.KILOMETERS: 'km'>, <Unit.METERS: 'm'>, <Unit.MILES: 'mi'>,
<Unit.NAUTICAL_MILES: 'nmi'>, <Unit.FEET: 'ft'>, <Unit.INCHES: 'in'>,
<Unit.RADIANS: 'rad'>, <Unit.DEGREES: 'deg'>)
Note for radians and degrees
The radian and degrees returns the great circle distance between two points on a sphere.
Notes:
- on a unit-sphere the angular distance in radians equals the distance between the two points on the sphere (definition of radians)
- When using "degree", this angle is just converted from radians to degrees
Inverse Haversine Formula
Calculates a point from a given vector (distance and direction) and start point. Currently explicitly supports both cardinal (north, east, south, west) and intercardinal (northeast, southeast, southwest, northwest) directions. But also allows for explicit angles expressed in Radians.
Example: Finding arbitrary point from Paris
```python from haversine import inverse_haversine, Direction from math import pi paris = (48.8567, 2.3508) # (lat, lon)
Finding 32 km west of Paris
inverse_haversine(paris, 32, Direction.WEST)
returns tuple (48.85587279023947, 1.9134085092836945)
Finding 32 km southwest of Paris
inverse_haversine(paris, 32, pi * 1.25)
returns tuple (48.65279552300661, 2.0427666779658806)
Finding 50 miles north of Paris
inverse_haversine(paris, 50, Direction.NORTH, unit=Unit.MILES)
returns tuple (49.58035791599536, 2.3508)
Finding 10 nautical miles south of Paris
inversehaversine(paris, 10, Direction.SOUTH, unit=Unit.NAUTICALMILES)
returns tuple (48.690145868497645, 2.3508)
```
Performance optimisation for distances between all points in two vectors
You will need to install numpy in order to gain performance with vectors.
For optimal performance, you can turn off coordinate checking by adding check=False and install the optional packages numba and icc_rt.
You can then do this:
```python from haversine import haversine_vector, Unit
lyon = (45.7597, 4.8422) # (lat, lon) paris = (48.8567, 2.3508) new_york = (40.7033962, -74.2351462)
haversinevector([lyon, lyon], [paris, newyork], Unit.KILOMETERS)
array([ 392.21725956, 6163.43638211]) ```
It is generally slower to use haversine_vector to get distance between two points, but can be really fast to compare distances between two vectors.
Combine matrix
You can generate a matrix of all combinations between coordinates in different vectors by setting comb parameter as True.
```python from haversine import haversine_vector, Unit
lyon = (45.7597, 4.8422) # (lat, lon) london = (51.509865, -0.118092) paris = (48.8567, 2.3508) new_york = (40.7033962, -74.2351462)
haversinevector([lyon, london], [paris, newyork], Unit.KILOMETERS, comb=True)
array([[ 392.21725956, 343.37455271], [6163.43638211, 5586.48447423]]) ```
The output array from the example above returns the following table:
| | Paris | New York | | ------ | :---------------: | :------------------: | | Lyon | Lyon <-> Paris | Lyon <-> New York | | London | London <-> Paris | London <-> New York |
By definition, if you have a vector a with n elements, and a vector b with m elements. The result matrix M would be $n x m$ and a element M[i,j] from the matrix would be the distance between the ith coordinate from vector a and jth coordinate with vector b.
Contributing
Clone the project.
Install pipenv.
Run pipenv install --dev
Launch test with pipenv run pytest
Owner
- Name: Mapado
- Login: mapado
- Kind: organization
- Email: bonjour@mapado.com
- Location: France
- Website: https://www.mapado.com
- Twitter: mapado
- Repositories: 63
- Profile: https://github.com/mapado
Light, empowering and still refined ticketing & CRM tools to save time and increase sales of living arts venues, festivals, museums or large event organizers.
GitHub Events
Total
- Issues event: 5
- Watch event: 26
- Delete event: 2
- Issue comment event: 14
- Push event: 11
- Pull request review event: 2
- Pull request event: 12
- Fork event: 3
- Create event: 3
Last Year
- Issues event: 5
- Watch event: 26
- Delete event: 2
- Issue comment event: 14
- Push event: 11
- Pull request review event: 2
- Pull request event: 12
- Fork event: 3
- Create event: 3
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Julien Deniau | j****u@g****m | 114 |
| Marius Merschformann | m****n@g****m | 16 |
| Joachim B Haga | j****a@b****m | 8 |
| Joachim B Haga | j****h@s****o | 7 |
| Balthazar Rouberol | b****l@m****m | 5 |
| dependabot[bot] | 4****] | 5 |
| ccforgy | 4****y | 5 |
| Jan Schulz | j****c@g****t | 5 |
| Balthazar Rouberol | r****b@g****m | 4 |
| Fernando Dias | f****1@g****m | 4 |
| Noé | n****n@g****m | 3 |
| Carlos Losada | l****s@g****m | 2 |
| Paolo Lammens | l****o@g****m | 2 |
| ocefpaf | o****f@g****m | 1 |
| nonsignificantp | 3****p | 1 |
| maurycyp | g****m@w****m | 1 |
| Balthazar Rouberol | b****l@a****r | 1 |
| Jeroen Craps | j****s@f****m | 1 |
| Samuel Killin | s****m@c****m | 1 |
| kukiel | k****q@g****m | 1 |
| enagorny | i****k@g****m | 1 |
| Tony Hillerson | t****n@g****m | 1 |
| Khem Raj | r****m@g****m | 1 |
| Juan De Dios Santos | j****s | 1 |
| Jeroen Craps | j****s@y****m | 1 |
| Edward Betts | e****d@4****m | 1 |
| Colin Watson | c****n@d****g | 1 |
| Benjamin Le Forestier | l****r | 1 |
| Amin | a****h@g****m | 1 |
| Adam Johnson | me@a****u | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 28
- Total pull requests: 55
- Average time to close issues: 3 months
- Average time to close pull requests: about 1 month
- Total issue authors: 25
- Total pull request authors: 28
- Average comments per issue: 4.18
- Average comments per pull request: 1.62
- Merged pull requests: 48
- Bot issues: 0
- Bot pull requests: 6
Past Year
- Issues: 3
- Pull requests: 6
- Average time to close issues: 5 months
- Average time to close pull requests: 28 days
- Issue authors: 3
- Pull request authors: 5
- Average comments per issue: 1.67
- Average comments per pull request: 1.67
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 1
Top Authors
Issue Authors
- uri-rodberg (3)
- MuellerSeb (2)
- adsk2050 (1)
- fgregg (1)
- thillerson (1)
- jaysonsantos (1)
- 12rambau (1)
- yoramzarai (1)
- ol-freelance (1)
- roniemartinez (1)
- stanislavlevin (1)
- hodgesd (1)
- md384 (1)
- phillipuniverse (1)
- SumitKrGhosh (1)
Pull Request Authors
- jdeniau (16)
- dependabot[bot] (8)
- jankatins (5)
- thillerson (4)
- jobh (2)
- CrapsJeroen (2)
- cjwatson (2)
- plammens (2)
- EdwardBetts (2)
- merschformann (2)
- SuperAmin (1)
- carlosloslas (1)
- martinmiglio (1)
- ccforgy (1)
- kukiel (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- pypi 3,147,591 last-month
- Total docker downloads: 757,198,820
-
Total dependent packages: 70
(may contain duplicates) -
Total dependent repositories: 741
(may contain duplicates) - Total versions: 41
- Total maintainers: 2
pypi.org: haversine
Calculate the distance between 2 points on Earth.
- Homepage: https://github.com/mapado/haversine
- Documentation: https://haversine.readthedocs.io/
- License: MIT
-
Latest release: 2.9.0
published about 1 year ago
Rankings
conda-forge.org: haversine
- Homepage: https://github.com/mapado/haversine
- License: MIT
-
Latest release: 2.7.0
published over 3 years ago
Rankings
Dependencies
- actions/checkout v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/autobuild v2 composite
- github/codeql-action/init v2 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- numpy * develop
- pytest ~=7.1 develop
- attrs ==21.4.0 develop
- iniconfig ==1.1.1 develop
- numpy ==1.22.0 develop
- packaging ==21.3 develop
- pluggy ==1.0.0 develop
- py ==1.11.0 develop
- pyparsing ==3.0.9 develop
- pytest ==7.1.2 develop
- tomli ==2.0.1 develop
- actions/checkout v3 composite
- actions/setup-python v4 composite