shipgrav 1.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
shipgrav/nav.py ADDED
@@ -0,0 +1,91 @@
1
+ import numpy as np
2
+
3
+ # impulse response of 10th order Taylor series differentiator
4
+ tay10 = [1/1260, -5/504, 5/84, -5/21, 5/6,
5
+ 0, -5/6, 5/21, -5/84, 5/504, -1/1260]
6
+
7
+
8
+ def latlon_to_EN(lon, lat, freq=1):
9
+ """ Convert a time series of geographic position to E/N velocities.
10
+
11
+ Coordinate time series should be at a constant sampling rate. The first and last five
12
+ values of the output arrays will be filled with Nan because the differencing scheme
13
+ has some edge effects.
14
+
15
+ :param lon: longitude points, decimal degrees
16
+ :type lon: ndarray
17
+ :param lat: latitude points, decimal degrees
18
+ :type lat: ndarray
19
+ :param freq: frequency of the position data, Hz (default: 1 Hz)
20
+ :type freq: float
21
+
22
+ :return:
23
+ - **vn** (*ndarray*) - north velocities, m/s
24
+ - **ve** (*ndarray*) - east velocities, m/s
25
+ """
26
+
27
+ assert hasattr(lon, '__len__') and hasattr(
28
+ lat, '__len__'), 'lon and lat must be lists or arrays'
29
+ assert len(lon) == len(lat), 'lon and lat must be the same length'
30
+ assert len(lon) > 10, 'at least 11 data points required'
31
+
32
+ a = 6378137.0 # WGS84 semi-major
33
+ b = 6356752.3142451 # WGS84 semi-minor
34
+ e2 = 1 - b**2/a**2 # ellipticity**2
35
+
36
+ # constants for radii of curvature
37
+ sin2lat = np.sin(np.deg2rad(lat))**2
38
+ e2term = np.sqrt(1 - e2*sin2lat)
39
+
40
+ # differentiate lat and lon using 10th order Taylor
41
+ dlat = np.deg2rad(np.convolve(lat, tay10, 'same'))
42
+ dlon = np.deg2rad(np.convolve(lon, tay10, 'same'))
43
+
44
+ # convert dlon/dlat to east and north velocity, scaled by sampling frequency
45
+ vn = a*(1 - e2)*(dlat/(e2term**3))*freq
46
+ ve = a*dlon*(np.cos(np.deg2rad(lat))/e2term)*freq
47
+
48
+ # Nan the edges bc they are unreliable
49
+ vn[:5] = np.nan
50
+ vn[-5:] = np.nan
51
+ ve[:5] = np.nan
52
+ ve[-5:] = np.nan
53
+
54
+ return vn, ve
55
+
56
+
57
+ def ENvel_to_course_heading(ve, vn):
58
+ """Calculate velocity and heading from east and north velocities.
59
+
60
+ :param ve: east velocity, m/s
61
+ :type ve: ndarray
62
+ :param vn: north velocity, m/s
63
+ :type vn: ndarray
64
+
65
+ :return:
66
+ - **heading** (*ndarray*) - track heading in degrees clockwise from N
67
+ - **vel** (*ndarray*) - velocity amplitude, m/s
68
+
69
+ """
70
+ heading = np.rad2deg(np.arctan2(ve, vn))
71
+ vel = np.sqrt(ve**2 + vn**2)
72
+ return heading, vel
73
+
74
+
75
+ def rotate_acceleration_EN_to_cl(heading, accE, accN):
76
+ """Rotate acceleration from East/North to Cross/Long reference frame.
77
+
78
+ :param heading: heading, in degrees clockwise from N
79
+ :type heading: ndarray
80
+ :param accE: east acceleration
81
+ :type accE: ndarray
82
+ :param accN: north acceleration
83
+ :type accN: ndarray
84
+
85
+ :return: **ac, al** (*ndarrays*) - cross and long accelerations
86
+ """
87
+ cosa = np.cos(np.deg2rad(heading))
88
+ sina = np.sin(np.deg2rad(heading))
89
+ ac = (accE*cosa) - (accN*sina)
90
+ al = (accE*sina) + (accN*cosa)
91
+ return ac, al
@@ -0,0 +1,16 @@
1
+ """
2
+ Tests for shipgrav
3
+ """
4
+
5
+ from pkg_resources import resource_filename
6
+ import sys
7
+ import unittest
8
+
9
+
10
+ def run():
11
+ loader = unittest.TestLoader()
12
+ test_dir = resource_filename('shipgrav', 'tests')
13
+ suite = loader.discover(test_dir)
14
+ runner = unittest.runner.TextTestRunner() # verbosity=2)
15
+ ret = not runner.run(suite).wasSuccessful()
16
+ sys.exit(ret)
@@ -0,0 +1,3 @@
1
+ from shipgrav.tests import run
2
+
3
+ run()
@@ -0,0 +1,4 @@
1
+ RGS 2022/07/01 00:00:00.445 980329.272 24980 1656633600.445 4.994070552 855577.390 BGM3 S210 GPS: 41.523386 -70.671852 1656633599.533 0 0 UNKNOWN_SRC 0.010 135.000 DEPTH: -999 -999 NONE HDG: 243.380 1656633599.855 SRC_GYRO NO_DNV_ERROR 1656633600.445 -999
2
+
3
+ RGS 2022/07/01 00:00:01.445 980284.326 24971 1656633601.445 4.994070552 855577.390 BGM3 S210 GPS: 41.523386 -70.671852 1656633600.536 0 0 UNKNOWN_SRC 0.010 18.400 DEPTH: -999 -999 NONE HDG: 243.370 1656633600.855 SRC_GYRO NO_DNV_ERROR 1656633601.445 -999
4
+