Loading knoten/shape.py +5 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ class Ellipsoid: A biaxial ellipsoid shape model. """ def __init__(self, semi_major, semi_minor = None): def __init__(self, semi_major, semi_minor=None, median=None): """ Create an ellipsoid shape model from a set of radii Loading @@ -23,9 +23,13 @@ class Ellipsoid: self.b = semi_major self.c = semi_major if median is not None: self.b = median if semi_minor is not None: self.c = semi_minor @classmethod def from_csm_sensor(cls, sensor): semi_major, semi_minor = csm.get_radii(sensor) Loading knoten/utils.py +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ def sep_angle(a_vec, b_vec): : np.ndarray """ dot_prod = a_vec.x * b_vec.x + a_vec.y * b_vec.y + a_vec.z * b_vec.z print(dot_prod) dot_prod /= magnitude(a_vec) * magnitude(b_vec) if(dot_prod >= 1.0): return 0.0 Loading tests/test_csm.py +1 −9 Original line number Diff line number Diff line Loading @@ -86,11 +86,3 @@ def test_get_state(mock_sensor, pt): } assert state == expected No newline at end of file @mock.patch.object(csm, 'get_radii', return_value=(10, 10)) def test_get_surface_normal(mock_sensor): ground_pt = utils.Point(1, 0, 0) normal = csm.get_surface_normal(mock_sensor, ground_pt) assert normal == (1.0, 0.0, 0.0) No newline at end of file tests/test_illuminator.py 0 → 100644 +24 −0 Original line number Diff line number Diff line import unittest from unittest import mock import csmapi from knoten import utils from knoten.illuminator import Illuminator class TestIlluminator(unittest.TestCase): def test_get_position_from_csm_sensor(self): mock_sensor = mock.MagicMock(spec=csmapi.RasterGM) mock_sensor.getIlluminationDirection.return_value = utils.Point(1.0, 10.0, 0.0) test_illum = Illuminator() ground_pt = utils.Point(10.0, 10.0, 0.0) position = test_illum.get_position_from_csm_sensor(mock_sensor, ground_pt) self.assertEqual(position, (9.0, 0.0, 0.0)) def tearDown(self): pass No newline at end of file tests/test_sensorutils.py +66 −42 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ import pytest import numpy as np import csmapi from knoten import csm, sensor_utils, utils, bundle from knoten import csm, sensor_utils, utils, bundle, shape, illuminator @pytest.fixture def mock_sensor(): Loading @@ -14,30 +14,44 @@ def mock_sensor(): def pt(): return csmapi.ImageCoord(0.0, 0.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_phase_angle(mock_sensor, pt): mock_sensor.getIlluminationDirection.return_value = utils.Point(100.0, 100.0, 0.0) phase_angle = sensor_utils.phase_angle(pt, mock_sensor) @pytest.fixture def test_shape(): return shape.Ellipsoid(0, 0) @pytest.fixture def test_illuminator(): return illuminator.Illuminator(0, 0) np.testing.assert_array_equal(phase_angle, 135.0) def test_phase_angle(mock_sensor, pt, test_shape, test_illuminator): with ( mock.patch.object(illuminator.Illuminator, 'get_position_from_csm_sensor', return_value=utils.Point(100.0, 100.0, 0.0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)) ): phase_angle = sensor_utils.phase_angle(pt, mock_sensor, test_shape, test_illuminator) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_emission_angle(mock_sensor, pt): with mock.patch.object(csm, 'get_surface_normal', return_value=utils.Point(-1,0,0)) as mock_normal: emission_angle = sensor_utils.emission_angle(pt, mock_sensor) np.testing.assert_allclose(phase_angle, 45.0) mock_normal.assert_called() def test_emission_angle(mock_sensor, pt, test_shape): with ( mock.patch.object(shape.Ellipsoid, 'get_surface_normal', return_value=utils.Point(-1,0,0)), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(illuminator.Illuminator, 'get_position_from_csm_sensor', return_value=utils.Point(100.0, 100.0, 0.0)) ): emission_angle = sensor_utils.emission_angle(pt, mock_sensor, test_shape) np.testing.assert_array_equal(emission_angle, 180.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(-100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_slant_distance(mock_sensor, pt): slant_distance = sensor_utils.slant_distance(pt, mock_sensor) def test_slant_distance(mock_sensor, pt, test_shape): with ( mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)) ): slant_distance = sensor_utils.slant_distance(pt, mock_sensor, test_shape) np.testing.assert_array_equal(slant_distance, 100.0) Loading @@ -56,18 +70,18 @@ def test_sub_spacecraft_point(mock_sensor, pt): np.testing.assert_array_equal(sub_spacecraft_point, [90.0, 0.0]) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_intersection(mock_sensor, pt): local_radius = sensor_utils.local_radius(pt, mock_sensor) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) @mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_intersection(mock_sensor, pt, test_shape): local_radius = sensor_utils.local_radius(pt, mock_sensor, test_shape) np.testing.assert_array_equal(local_radius, 10.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(-1000.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_ground(mock_sensor, pt): local_radius = sensor_utils.local_radius(pt, mock_sensor) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(1000.0, 0.0, 0.0), 'lookVec': utils.Point(-1000.0, 0.0, 0.0)}) @mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_ground(mock_sensor, pt, test_shape): local_radius = sensor_utils.local_radius(pt, mock_sensor, test_shape) np.testing.assert_array_equal(local_radius, 10.0) Loading @@ -79,25 +93,35 @@ def test_right_ascension_declination(mock_sensor, pt): np.testing.assert_array_equal(right_ascension_declination, [180.0, 0.0]) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_line_resolution(mock_sensor, pt): line_resolution = sensor_utils.line_resolution(pt, mock_sensor) def test_line_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): line_resolution = sensor_utils.line_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(line_resolution, 6.0) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_sample_resolution(mock_sensor, pt): sample_resolution = sensor_utils.sample_resolution(pt, mock_sensor) def test_sample_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): sample_resolution = sensor_utils.sample_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(sample_resolution, 9.0) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_pixel_resolution(mock_sensor, pt): pixel_resolution = sensor_utils.pixel_resolution(pt, mock_sensor) def test_pixel_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): pixel_resolution = sensor_utils.pixel_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(pixel_resolution, 7.5) No newline at end of file Loading
knoten/shape.py +5 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ class Ellipsoid: A biaxial ellipsoid shape model. """ def __init__(self, semi_major, semi_minor = None): def __init__(self, semi_major, semi_minor=None, median=None): """ Create an ellipsoid shape model from a set of radii Loading @@ -23,9 +23,13 @@ class Ellipsoid: self.b = semi_major self.c = semi_major if median is not None: self.b = median if semi_minor is not None: self.c = semi_minor @classmethod def from_csm_sensor(cls, sensor): semi_major, semi_minor = csm.get_radii(sensor) Loading
knoten/utils.py +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ def sep_angle(a_vec, b_vec): : np.ndarray """ dot_prod = a_vec.x * b_vec.x + a_vec.y * b_vec.y + a_vec.z * b_vec.z print(dot_prod) dot_prod /= magnitude(a_vec) * magnitude(b_vec) if(dot_prod >= 1.0): return 0.0 Loading
tests/test_csm.py +1 −9 Original line number Diff line number Diff line Loading @@ -86,11 +86,3 @@ def test_get_state(mock_sensor, pt): } assert state == expected No newline at end of file @mock.patch.object(csm, 'get_radii', return_value=(10, 10)) def test_get_surface_normal(mock_sensor): ground_pt = utils.Point(1, 0, 0) normal = csm.get_surface_normal(mock_sensor, ground_pt) assert normal == (1.0, 0.0, 0.0) No newline at end of file
tests/test_illuminator.py 0 → 100644 +24 −0 Original line number Diff line number Diff line import unittest from unittest import mock import csmapi from knoten import utils from knoten.illuminator import Illuminator class TestIlluminator(unittest.TestCase): def test_get_position_from_csm_sensor(self): mock_sensor = mock.MagicMock(spec=csmapi.RasterGM) mock_sensor.getIlluminationDirection.return_value = utils.Point(1.0, 10.0, 0.0) test_illum = Illuminator() ground_pt = utils.Point(10.0, 10.0, 0.0) position = test_illum.get_position_from_csm_sensor(mock_sensor, ground_pt) self.assertEqual(position, (9.0, 0.0, 0.0)) def tearDown(self): pass No newline at end of file
tests/test_sensorutils.py +66 −42 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ import pytest import numpy as np import csmapi from knoten import csm, sensor_utils, utils, bundle from knoten import csm, sensor_utils, utils, bundle, shape, illuminator @pytest.fixture def mock_sensor(): Loading @@ -14,30 +14,44 @@ def mock_sensor(): def pt(): return csmapi.ImageCoord(0.0, 0.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_phase_angle(mock_sensor, pt): mock_sensor.getIlluminationDirection.return_value = utils.Point(100.0, 100.0, 0.0) phase_angle = sensor_utils.phase_angle(pt, mock_sensor) @pytest.fixture def test_shape(): return shape.Ellipsoid(0, 0) @pytest.fixture def test_illuminator(): return illuminator.Illuminator(0, 0) np.testing.assert_array_equal(phase_angle, 135.0) def test_phase_angle(mock_sensor, pt, test_shape, test_illuminator): with ( mock.patch.object(illuminator.Illuminator, 'get_position_from_csm_sensor', return_value=utils.Point(100.0, 100.0, 0.0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)) ): phase_angle = sensor_utils.phase_angle(pt, mock_sensor, test_shape, test_illuminator) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_emission_angle(mock_sensor, pt): with mock.patch.object(csm, 'get_surface_normal', return_value=utils.Point(-1,0,0)) as mock_normal: emission_angle = sensor_utils.emission_angle(pt, mock_sensor) np.testing.assert_allclose(phase_angle, 45.0) mock_normal.assert_called() def test_emission_angle(mock_sensor, pt, test_shape): with ( mock.patch.object(shape.Ellipsoid, 'get_surface_normal', return_value=utils.Point(-1,0,0)), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(illuminator.Illuminator, 'get_position_from_csm_sensor', return_value=utils.Point(100.0, 100.0, 0.0)) ): emission_angle = sensor_utils.emission_angle(pt, mock_sensor, test_shape) np.testing.assert_array_equal(emission_angle, 180.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(-100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0,0,0)) def test_slant_distance(mock_sensor, pt): slant_distance = sensor_utils.slant_distance(pt, mock_sensor) def test_slant_distance(mock_sensor, pt, test_shape): with ( mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)) ): slant_distance = sensor_utils.slant_distance(pt, mock_sensor, test_shape) np.testing.assert_array_equal(slant_distance, 100.0) Loading @@ -56,18 +70,18 @@ def test_sub_spacecraft_point(mock_sensor, pt): np.testing.assert_array_equal(sub_spacecraft_point, [90.0, 0.0]) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_intersection(mock_sensor, pt): local_radius = sensor_utils.local_radius(pt, mock_sensor) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) @mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_intersection(mock_sensor, pt, test_shape): local_radius = sensor_utils.local_radius(pt, mock_sensor, test_shape) np.testing.assert_array_equal(local_radius, 10.0) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(-1000.0, 0.0, 0.0)}) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_ground(mock_sensor, pt): local_radius = sensor_utils.local_radius(pt, mock_sensor) @mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(1000.0, 0.0, 0.0), 'lookVec': utils.Point(-1000.0, 0.0, 0.0)}) @mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(10.0, 0.0, 0.0)) def test_local_radius_ground(mock_sensor, pt, test_shape): local_radius = sensor_utils.local_radius(pt, mock_sensor, test_shape) np.testing.assert_array_equal(local_radius, 10.0) Loading @@ -79,25 +93,35 @@ def test_right_ascension_declination(mock_sensor, pt): np.testing.assert_array_equal(right_ascension_declination, [180.0, 0.0]) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_line_resolution(mock_sensor, pt): line_resolution = sensor_utils.line_resolution(pt, mock_sensor) def test_line_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): line_resolution = sensor_utils.line_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(line_resolution, 6.0) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_sample_resolution(mock_sensor, pt): sample_resolution = sensor_utils.sample_resolution(pt, mock_sensor) def test_sample_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): sample_resolution = sensor_utils.sample_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(sample_resolution, 9.0) @mock.patch.object(csm, 'generate_ground_point', return_value=utils.Point(0.0, 0.0, 0.0)) @mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])) def test_pixel_resolution(mock_sensor, pt): pixel_resolution = sensor_utils.pixel_resolution(pt, mock_sensor) def test_pixel_resolution(mock_sensor, pt, test_shape): with ( mock.patch.object(bundle, 'compute_image_partials', return_value=np.array([2, 1, 4, 4, 4, 8])), mock.patch.object(shape.Ellipsoid, 'intersect_surface', return_value=utils.Point(0,0,0)), mock.patch.object(csm, 'get_state', return_value={'sensorPos': utils.Point(100.0, 0.0, 0.0), 'lookVec': utils.Point(-1.0, 0.0, 0.0)}) ): pixel_resolution = sensor_utils.pixel_resolution(pt, mock_sensor, test_shape) np.testing.assert_array_equal(pixel_resolution, 7.5) No newline at end of file