Skip to content

Commit

Permalink
Merge pull request #7 from ocefpaf/fixes_4
Browse files Browse the repository at this point in the history
Fixes 4
  • Loading branch information
kwilcox authored Jun 27, 2022
2 parents a619298 + 7bf6890 commit b6da063
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 157 deletions.
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: check-ast
- id: debug-statements
- id: check-added-large-files
- id: requirements-txt-fixer
- id: file-contents-sorter

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
exclude: >
(?x)^(
.*\.yaml
)$
2 changes: 2 additions & 0 deletions pygc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pygc.gc import great_circle
from pygc.gc import great_distance

__all__ = ["great_circle", "great_distance"]

try:
from ._version import __version__
except ImportError:
Expand Down
7 changes: 6 additions & 1 deletion pygc/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ def vinc_dist(f, a, phi1, lembda1, phi2, lembda2):
# Iterate the following equations,
# until there is no significant change in lembda

max_loop = 100
count_loop = 0
while (last_lembda < -3000000.0 or lembda != 0 and np.absolute((last_lembda - lembda) / lembda) > 1.0e-9):

if count_loop > max_loop:
print("max loop reached, break")
break
count_loop += 1
sqr_sin_sigma = np.power( np.cos(U2) * np.sin(lembda), 2) + \
np.power((np.cos(U1) * np.sin(U2) -
np.sin(U1) * np.cos(U2) * np.cos(lembda)), 2)
Expand Down
123 changes: 71 additions & 52 deletions pygc/tests/test_gc.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,87 @@
import unittest
import numpy as np

from pygc import great_circle


class GreatCircleTest(unittest.TestCase):
def test_great_circle_scalars():
# One decimal degree is 111000m
latitude = 40.0
longitude = -76.0

def test_great_circle_scalars(self):
# One decimal degree is 111000m
latitude = 40.0
longitude = -76.0
azimuth = 90
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone to the right
assert new_gc["longitude"] > longitude + 0.9

azimuth = 90
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone to the right
assert new_gc["longitude"] > longitude + 0.9
azimuth = 270
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone to the left
assert new_gc["longitude"] < longitude - 0.9

azimuth = 270
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone to the left
assert new_gc["longitude"] < longitude - 0.9
azimuth = 180
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone down
assert new_gc["latitude"] < latitude - 0.9

azimuth = 180
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone down
assert new_gc["latitude"] < latitude - 0.9
azimuth = 0
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone up
assert new_gc["latitude"] > latitude + 0.9

azimuth = 0
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone up
assert new_gc["latitude"] > latitude + 0.9
azimuth = 315
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone up and to the left
assert new_gc["latitude"] > latitude + 0.45
assert new_gc["longitude"] < longitude - 0.45

azimuth = 315
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone up and to the left
assert new_gc["latitude"] > latitude + 0.45
assert new_gc["longitude"] < longitude - 0.45

def test_great_circle_numpy(self):
# One decimal degree is 111000m
latitude = np.asarray([40.0, 50.0, 60.0])
longitude = np.asarray([-76.0, -86.0, -96.0])
def test_great_circle_numpy():
# One decimal degree is 111000m
latitude = np.asarray([40.0, 50.0, 60.0])
longitude = np.asarray([-76.0, -86.0, -96.0])

azimuth = 90
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone to the right
assert (new_gc["longitude"] > longitude + 0.9).all()
azimuth = 90
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone to the right
assert (new_gc["longitude"] > longitude + 0.9).all()

azimuth = 270
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone to the left
assert (new_gc["longitude"] < longitude - 0.9).all()
azimuth = 270
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone to the left
assert (new_gc["longitude"] < longitude - 0.9).all()

azimuth = 180
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone down
assert (new_gc["latitude"] < latitude - 0.9).all()
azimuth = 180
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone down
assert (new_gc["latitude"] < latitude - 0.9).all()

azimuth = 0
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone up
assert (new_gc["latitude"] > latitude + 0.9).all()
azimuth = 0
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone up
assert (new_gc["latitude"] > latitude + 0.9).all()

azimuth = 315
new_gc = great_circle(distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude)
# We should have gone up and to the left
assert (new_gc["latitude"] > latitude + 0.45).all()
assert (new_gc["longitude"] < longitude - 0.45).all()
azimuth = 315
new_gc = great_circle(
distance=111000, azimuth=azimuth, latitude=latitude, longitude=longitude
)
# We should have gone up and to the left
assert (new_gc["latitude"] > latitude + 0.45).all()
assert (new_gc["longitude"] < longitude - 0.45).all()
Loading

0 comments on commit b6da063

Please sign in to comment.