From 2efb9cd9863a34e8f467a2b0aabeadd2b846969f Mon Sep 17 00:00:00 2001 From: Kelvin Rodriguez <kr788@nau.edu> Date: Wed, 31 Jul 2019 13:15:44 -0700 Subject: [PATCH] add reproject code (#36) * add reproject code * test reproject not pointing to autocnet * get travis to work --- .travis.yml | 2 +- knoten/utils.py | 43 +++++++++++++++++++++++++++++++++++++++++ tests/test_reproject.py | 10 ++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 knoten/utils.py create mode 100644 tests/test_reproject.py diff --git a/.travis.yml b/.travis.yml index 215d630..48515d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ before_install: - conda env update -n test -f environment.yml script: - - pytest tests + - PYTHONPATH=. pytest tests after_success: - coveralls diff --git a/knoten/utils.py b/knoten/utils.py new file mode 100644 index 0000000..47bc704 --- /dev/null +++ b/knoten/utils.py @@ -0,0 +1,43 @@ +import pyproj + +def reproject(record, semi_major, semi_minor, source_proj, dest_proj, **kwargs): + """ + Thin wrapper around PyProj's Transform() function to transform 1 or more three-dimensional + point from one coordinate system to another. If converting between Cartesian + body-centered body-fixed (BCBF) coordinates and Longitude/Latitude/Altitude coordinates, + the values input for semi-major and semi-minor axes determine whether latitudes are + planetographic or planetocentric and determine the shape of the datum for altitudes. + If semi_major == semi_minor, then latitudes are interpreted/created as planetocentric + and altitudes are interpreted/created as referenced to a spherical datum. + If semi_major != semi_minor, then latitudes are interpreted/created as planetographic + and altitudes are interpreted/created as referenced to an ellipsoidal datum. + + Parameters + ---------- + record : object + Pandas series object + + semi_major : float + Radius from the center of the body to the equater + + semi_minor : float + Radius from the pole to the center of mass + + source_proj : str + Pyproj string that defines a projection space ie. 'geocent' + + dest_proj : str + Pyproj string that defines a project space ie. 'latlon' + + Returns + ------- + : list + Transformed coordinates as y, x, z + + """ + source_pyproj = pyproj.Proj(proj = source_proj, a = semi_major, b = semi_minor) + dest_pyproj = pyproj.Proj(proj = dest_proj, a = semi_major, b = semi_minor) + + y, x, z = pyproj.transform(source_pyproj, dest_pyproj, record[0], record[1], record[2], **kwargs) + + return y, x, z diff --git a/tests/test_reproject.py b/tests/test_reproject.py new file mode 100644 index 0000000..0b479af --- /dev/null +++ b/tests/test_reproject.py @@ -0,0 +1,10 @@ +from unittest import mock +import pytest + +from knoten import utils + +def test_reproject(): + with mock.patch('pyproj.transform', return_value=[1,1,1]) as mock_pyproj: + res = utils.reproject([1,1,1], 10, 10, 'geocent', 'latlon') + mock_pyproj.assert_called_once() + assert res == (1,1,1) -- GitLab