diff --git a/geodepy/convert.py b/geodepy/convert.py old mode 100755 new mode 100644 diff --git a/geodepy/statistics.py b/geodepy/statistics.py index ddb685f..27903a7 100644 --- a/geodepy/statistics.py +++ b/geodepy/statistics.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import sys from math import radians, sin, cos, sqrt, atan2, degrees import numpy as np @@ -99,7 +98,7 @@ def error_ellipse(vcv): :param vcv: a VCV (3x3) :return: a, semi-major axis :return: b, semi-minor axis - :return: orientation, the orientation of the rorr ellipse + :return: orientation, the orientation of the error ellipse """ z = sqrt((vcv[0, 0] - vcv[1, 1])**2 + 4 * vcv[0, 1]**2) a = sqrt(0.5 * (vcv[0, 0] + vcv[1, 1] + z)) diff --git a/geodepy/tests/test_height.py b/geodepy/tests/test_height.py index 529f06b..2d48bcd 100644 --- a/geodepy/tests/test_height.py +++ b/geodepy/tests/test_height.py @@ -24,17 +24,21 @@ class TestHeights(unittest.TestCase): def test_AVWS_H(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.GPS_to_AVWS(Lat, Long, Height)[0]), AVWS_H, 7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.GPS_to_AVWS(Lat, Long, Height)[0]), AVWS_H, 7) def test_AVWS_H_STD(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.GPS_to_AVWS(Lat, Long, Height)[1]), AVWS_H_STD, 7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.GPS_to_AVWS(Lat, Long, Height)[1]), AVWS_H_STD, 7) def test_DOVPV(self): self.assertAlmostEqual(np.asscalar(geodepy.height.DOV(Lat, Long)[1]), DOVPV, 7) def test_DOVPM(self): self.assertAlmostEqual(np.asscalar(geodepy.height.DOV(Lat, Long)[0]), DOVPM, 7) def test_AHD_H(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.GPS_to_AHD(Lat, Long, Height)[0]), AHD_H, 7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.GPS_to_AHD(Lat, Long, Height)[0]), AHD_H, 7) def test_AHD_H_STD(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.GPS_to_AHD(Lat, Long, Height)[1]), AHD_H_STD, 7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.GPS_to_AHD(Lat, Long, Height)[1]), AHD_H_STD, 7) #___________________________________________________________________________# ## Some test Cases to run, check againts ga.gov.au/ausgeoid @@ -51,9 +55,11 @@ def test_AHD_H_STD(self): class TestNC(unittest.TestCase): def test_NC(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.normal_correction(Lat1,Long1,Height1,Lat2,Long2,Height2)[0]),NC,7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.normal_correction(Lat1, Long1, Height1, Lat2, Long2, Height2)[0]), NC, 7) def test_Grav(self): - self.assertAlmostEqual(np.asscalar(geodepy.height.normal_correction(Lat1,Long1,Height1,Lat2,Long2,Height2)[1]),RECOVERED_GRAV,7) + self.assertAlmostEqual(np.asscalar( + geodepy.height.normal_correction(Lat1, Long1, Height1, Lat2, Long2, Height2)[1]), RECOVERED_GRAV, 7) if __name__ == '__main__': unittest.main() diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py index a0bbfd4..c4a329e 100644 --- a/geodepy/tests/test_statistics.py +++ b/geodepy/tests/test_statistics.py @@ -1,125 +1,112 @@ import unittest from geodepy import statistics -from geodepy.statistics import np +import numpy as np + +lat = 19.4792453 +lon = 70.69315634 +vcv = np.array([ + [1.44, -1.32, 1.32], + [-1.32, 1.22, -1.20], + [1.32, -1.20, 1.20] +]) +var = np.array([ + [1.44], [1.20], [1.20] +]) class TestStatistics(unittest.TestCase): def test_rotation_matrix(self): - lat = 19.4792 - lon = 70.6931 - expected_result = np.array([ - [-0.94376114, -0.11025276, 0.31170376], - [0.33062805, -0.31471096, 0.88974272], - [0.0, 0.94276261, 0.33346463], + [-0.94376147, -0.1102527, 0.3117028], + [0.33062712, -0.31471177, 0.88974278], + [0.0, 0.94276235, 0.33346538], ]) result = statistics.rotation_matrix(lat, lon) - np.array_equal(expected_result, result) + np.testing.assert_almost_equal(expected_result, result) self.assertEqual(type(expected_result), type(result)) - def test_vcv_cart2local_and_vcv_local2cart2_3X3(self): - lat = 19.4792453 - lon = 70.69315634 - v_cart = np.array([ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - ]) + def test_vcv_cart2local_3x3(self): expected_result = np.array([ - [0., 0., 0.], - [0., 0., 0.], - [0., 0., 0.], + [2.23971834, -1.86955194, 0.3599339], + [-1.86955194, 1.55096504, -0.29615085], + [0.3599339, -0.29615085, 0.06931662] ]) - result_cart2local = statistics.vcv_cart2local(v_cart, lat, lon) - result_local2cart = statistics.vcv_local2cart(v_cart, lat, lon) - - np.testing.assert_array_equal(expected_result, result_cart2local) - np.testing.assert_array_equal(expected_result, result_local2cart) - self.assertEqual(type(expected_result), type(result_cart2local)) - self.assertEqual(type(expected_result), type(result_local2cart)) - - def test_vcv_cart2local_and_vcv_local2cart2_3X2(self): - lat = 0.0 - lon = 0.0 - v_cart = np.array([ - [0.0, 0.0], - [0.0, 0.0], - [0.0, 0.0], + result = statistics.vcv_cart2local(vcv, lat, lon) + + np.testing.assert_almost_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) + + def test_vcv_cart2local_3x1(self): + expected_result = np.array([ + [1.41376457], [1.20291736], [1.22331807] ]) - with self.assertRaises(SystemExit): - statistics.vcv_cart2local(v_cart, lat, lon) + result = statistics.vcv_cart2local(var, lat, lon) - with self.assertRaises(SystemExit): - statistics.vcv_local2cart(v_cart, lat, lon) + np.testing.assert_almost_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) + + def test_vcv_cart2local_3X2(self): + v_cart = np.zeros((3, 2)) + + with self.assertRaises(ValueError): + statistics.vcv_cart2local(v_cart, 0.0, 0.0) - def test_vcv_cart2local_and_vcv_local2cart2_2X3(self): - lat = 0.0 - lon = 0.0 - v_cart = np.array([ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], + def test_vcv_local2cart_3X3(self): + expected_result = np.array([ + [0.44517136, -1.15507667, 0.44844663], + [-1.15507667, 2.95156126, -1.15249271], + [0.44844663, -1.15249271, 0.46326737] ]) - with self.assertRaises(SystemExit): - statistics.vcv_cart2local(v_cart, lat, lon) + result = statistics.vcv_local2cart(vcv, lat, lon) - with self.assertRaises(SystemExit): - statistics.vcv_local2cart(v_cart, lat, lon) + np.testing.assert_almost_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) - def test_vcv_cart2local_and_vcv_local2cart2_1X3(self): - lat = 0.0 - lon = 0.0 - v_cart = np.array([ - [0.0], - [0.0], - [0.0], - ]) + def test_vcv_local2cart_3X1(self): expected_result = np.array([ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], + [1.41376457], [1.20291736], [1.22331807] ]) - result_cart2local = statistics.vcv_cart2local(v_cart, lat, lon) - result_local2cart = statistics.vcv_local2cart(v_cart, lat, lon) + result = statistics.vcv_cart2local(var, lat, lon) + + np.testing.assert_almost_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) - np.testing.assert_array_equal(expected_result, result_cart2local) - np.testing.assert_array_equal(expected_result, result_local2cart) - self.assertEqual(type(expected_result), type(result_cart2local)) - self.assertEqual(type(expected_result), type(result_local2cart)) + def test_vcv_local2cart_3X2(self): + v_cart = np.zeros((3, 2)) + + with self.assertRaises(ValueError): + statistics.vcv_local2cart(v_cart, lat, lon) def test_error_ellipse(self): - vcv = np.array([ - [90, 0, 0], - [0, 90, 0], - [0, 0, 90], - ]) - expected_result = (9.486832980505138, 9.486832980505138, 90.0) + expected_result = (1.6292867776015223, 0.07365185899111726, + 132.61817915463692) result = statistics.error_ellipse(vcv) - self.assertEqual(expected_result, result) + np.testing.assert_almost_equal(expected_result, result) self.assertEqual(type(expected_result), type(result)) def test_circ_hz_pu(self): a = 1 b = 0 - expeted_result = 1.96079 + expected_result = 1.96079 result = statistics.circ_hz_pu(a, b) - self.assertEqual(expeted_result, result) + self.assertEqual(expected_result, result) def test_k_val95_typeError(self): dof = [[], {}, ""] for item in dof: with self.assertRaises(TypeError): - statistics.k_val95(dof) + statistics.k_val95(item) def test_k_val95_less_1(self): dof = -1 diff --git a/setup.py b/setup.py index a662067..4bbebc4 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup(name='geodepy', - version='0.0.10', + version='0.0.11', description='GA Geodesy Package', long_description='A toolkit for Geodesy and Surveying in Python', url='https://github.com/GeoscienceAustralia/GeodePy',