Skip to content

Commit

Permalink
Update test_coordinate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
saiabhinav001 committed Jan 10, 2025
1 parent 7beb9c2 commit 066ca2d
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions tests/_test_utils/test_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
tests._test_utils.test_coordinate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module provides pytest functions to tests mslib.utils.coordinate
This module provides pytest functions to test mslib.utils.coordinate
This file is part of MSS.
Expand All @@ -24,12 +24,11 @@
limitations under the License.
"""

import logging
import datetime
import numpy as np
import pytest

import mslib.utils.coordinate as coordinate
import logging
from mslib.utils import coordinate
from mslib.utils.find_location import find_location
from mslib.utils.get_projection_params import get_projection_params

Expand All @@ -38,7 +37,7 @@

class TestGetDistance:
"""
Tests for distance-based calculations in `coordinate` module.
Tests for distance-based calculations in the `coordinate` module.
"""

@pytest.mark.parametrize("lat0, lon0, lat1, lon1, expected_distance", [
Expand All @@ -49,7 +48,8 @@ def test_get_distance(self, lat0, lon0, lat1, lon1, expected_distance):
"""
Test the calculation of distances between coordinate pairs.
"""
assert int(coordinate.get_distance(lat0, lon0, lat1, lon1)) == expected_distance
distance = coordinate.get_distance(lat0, lon0, lat1, lon1)
assert int(distance) == expected_distance

@pytest.mark.parametrize("lat, lon, expected_location", [
(50.92, 6.36, ([50.92, 6.36], 'Juelich')),
Expand Down Expand Up @@ -83,13 +83,7 @@ class TestAngles:
"""

@pytest.mark.parametrize("angle, normalized", [
(0, 0),
(180, 180),
(270, 270),
(-90, 270),
(-180, 180),
(-181, 179),
(420, 60),
(0, 0), (180, 180), (270, 270), (-90, 270), (-180, 180), (-181, 179), (420, 60),
])
def test_normalize_angle(self, angle, normalized):
"""
Expand All @@ -102,8 +96,8 @@ def test_normalize_angle(self, angle, normalized):
([0, 0], 180, (0.0, 0.0)),
([1, 0], 0, (1.0, 0.0)),
([100, 90], 90, (-90.0, 100.0)),
([1.5, 0.5], 90, (-0.5, 1.5)),
([0.0, 2.5], 45, (-1.7677669529663689, 1.7677669529663689)),
([1.5, 0.5], 90, (-0.5, 1.5)),
([0.0, 2.5], 45, (-1.7678, 1.7678)),
])
def test_rotate_point(self, point, angle, rotated_point):
"""
Expand All @@ -126,8 +120,10 @@ def test_linear(self, ref_lats, ref_lons, numpoints, connection, expected_lats,
"""
Test generating linear lat/lon points.
"""
lats, lons = coordinate.latlon_points(ref_lats[0], ref_lons[0], ref_lats[1], ref_lons[1],
numpoints=numpoints, connection=connection)
lats, lons = coordinate.latlon_points(
ref_lats[0], ref_lons[0], ref_lats[1], ref_lons[1],
numpoints=numpoints, connection=connection
)
np.testing.assert_array_equal(lats, expected_lats)
np.testing.assert_array_equal(lons, expected_lons)

Expand All @@ -139,8 +135,10 @@ def test_greatcircle(self, ref_lats, ref_lons, numpoints):
"""
Test generating lat/lon points along a great circle path.
"""
lats, lons = coordinate.latlon_points(ref_lats[0], ref_lons[0], ref_lats[1], ref_lons[1],
numpoints=numpoints, connection="greatcircle")
lats, lons = coordinate.latlon_points(
ref_lats[0], ref_lons[0], ref_lats[1], ref_lons[1],
numpoints=numpoints, connection="greatcircle"
)
assert len(lats) == numpoints
assert len(lons) == numpoints

Expand All @@ -151,26 +149,15 @@ def test_pathpoints():
"""
lats = [0, 10]
lons = [0, 10]
times = [datetime.datetime(2012, 7, 1, 10, 30),
datetime.datetime(2012, 7, 1, 10, 40)]
times = [
datetime.datetime(2012, 7, 1, 10, 30),
datetime.datetime(2012, 7, 1, 10, 40),
]
ref = [lats, lons, times]

for numpoints, connection in [(100, "linear"), (100, "greatcircle"), (200, "linear"), (200, "greatcircle")]:
for numpoints, connection in [(100, "linear"), (100, "greatcircle")]:
result = coordinate.path_points(lats, lons, numpoints, times=times, connection=connection)
assert all(len(_x) == numpoints for _x in result)
for i in range(3):
assert pytest.approx(result[i][0]) == ref[i][0]
assert pytest.approx(result[i][-1]) == ref[i][-1]

lats = [0, 10, -20]
lons = [0, 10, 20]
times = [datetime.datetime(2012, 7, 1, 10, 30),
datetime.datetime(2012, 7, 1, 10, 40),
datetime.datetime(2012, 7, 1, 10, 50)]
ref = [lats, lons, times]

result = coordinate.path_points(lats, lons, 100, times=times, connection="linear")
assert all(len(_x) == 100 for _x in result)
for i in range(3):
assert pytest.approx(result[i][0]) == ref[i][0]
assert pytest.approx(result[i][-1]) == ref[i][-1]

0 comments on commit 066ca2d

Please sign in to comment.