Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
.idea
__pycache__

# Compiled python modules.
*.pyc

# Setuptools distribution folder.
/dist/
env

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info

# Ignore test-related files
/coverage.data
/coverage/
/coverage/

# IDEs
.vscode
.idea

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NumPy

### Testing

Run: `python -m unittest discover geodepy/tests/`
Run: `python -m unittest discover geodepy/tests/ --verbose`

### Tutorials

Expand Down
1 change: 1 addition & 0 deletions geodepy/statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import sys
from math import radians, sin, cos, sqrt, atan2, degrees
import numpy as np

Expand Down
150 changes: 150 additions & 0 deletions geodepy/tests/test_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import unittest
from geodepy import statistics
from geodepy.statistics import np


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],
])

result = statistics.rotation_matrix(lat, lon)

np.array_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],
])
expected_result = np.array([
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
])

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],
])

with self.assertRaises(SystemExit):
statistics.vcv_cart2local(v_cart, lat, lon)

with self.assertRaises(SystemExit):
statistics.vcv_local2cart(v_cart, lat, lon)

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],
])

with self.assertRaises(SystemExit):
statistics.vcv_cart2local(v_cart, lat, lon)

with self.assertRaises(SystemExit):
statistics.vcv_local2cart(v_cart, lat, lon)

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],
])
expected_result = np.array([
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
])

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_error_ellipse(self):
vcv = np.array([
[90, 0, 0],
[0, 90, 0],
[0, 0, 90],
])
expected_result = (9.486832980505138, 9.486832980505138, 90.0)

result = statistics.error_ellipse(vcv)

self.assertEqual(expected_result, result)
self.assertEqual(type(expected_result), type(result))

def test_circ_hz_pu(self):
a = 1
b = 0

expeted_result = 1.96079

result = statistics.circ_hz_pu(a, b)
self.assertEqual(expeted_result, result)

def test_k_val95_typeError(self):
dof = [[], {}, ""]

for item in dof:
with self.assertRaises(TypeError):
statistics.k_val95(dof)

def test_k_val95_less_1(self):
dof = -1

expected_result = statistics.ttable_p95[0]

result = statistics.k_val95(dof)
self.assertEqual(expected_result, result)

def test_k_val95_greater_120(self):
dof = 121

expected_result = 1.96

result = statistics.k_val95(dof)
self.assertEqual(expected_result, result)

def test_k_val95_between_1_and_120(self):
dof = 100

expected_result = statistics.ttable_p95[dof - 1]

result = statistics.k_val95(dof)
self.assertEqual(expected_result, result)


if __name__ == '__main__':
unittest.main()