Commit 9851a494 authored by Laura, Jason R's avatar Laura, Jason R
Browse files

Merge branch 'main' into 'main'

Affine Update Test Fixes

See merge request astrogeology/autocnet!661
parents 05174db4 9011f095
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -348,8 +348,18 @@ class TestEdge(unittest.TestCase):
            e = edge.Edge(s, d)
            e.matches = ['a', 'b', 'c']

    @pytest.mark.parametrize("nmatches, nstrengths", [(10,1), (10,2)])
    def test_prep_subpixel(self, nmatches, nstrengths):
    def test_prep_subpixel_1(self):
        nmatches = 10
        nstrengths = 1
        e = edge.Edge()
        arrs = e._prep_subpixel(nmatches, nstrengths=nstrengths)
        assert len(arrs) == 5
        assert arrs[2].shape == (nmatches, nstrengths)
        assert arrs[0][0] == 0

    def test_prep_subpixel_2(self):
        nmatches = 10
        nstrengths = 2
        e = edge.Edge()
        arrs = e._prep_subpixel(nmatches, nstrengths=nstrengths)
        assert len(arrs) == 5
+6 −4
Original line number Diff line number Diff line
@@ -97,8 +97,10 @@ def subpixel_phase(reference_roi, moving_roi, affine=tf.AffineTransform(), **kwa
    : tuple
      With the RMSE error and absolute difference in phase
    """
    reference_image = reference_roi.clip()
    walking_template = moving_roi.clip(affine)
    reference_roi.clip()
    reference_image = reference_roi.clipped_array
    moving_roi.clip(affine=affine)
    walking_template = moving_roi.clipped_array

    if reference_image.shape != walking_template.shape:
        reference_size = reference_image.shape
@@ -199,7 +201,7 @@ def subpixel_template(reference_roi,
    if (ref_clip is None) or (moving_clip is None):
        return None, None, None

    matcher_shift_x, matcher_shift_y, metrics, corrmap = func(moving_clip, ref_clip, upsampling=16, **kwargs)
    matcher_shift_x, matcher_shift_y, metrics, corrmap = func(moving_clip, ref_clip, **kwargs)
    if matcher_shift_x is None:
        return None, None, None

+19 −20
Original line number Diff line number Diff line
@@ -79,8 +79,8 @@ class TestNaiveTemplate(unittest.TestCase):
        result_x, result_y, result_strength, _ = naive_template.pattern_match(self._t_shape,
                                                                           self._test_image, upsampling=1)
        # Test offsets
        self.assertEqual(result_x, -3)
        self.assertEqual(result_y, -3)
        self.assertEqual(result_x, 3)
        self.assertEqual(result_y, 3)
        # Test Correlation Strength: At least 0.8
        self.assertGreaterEqual(result_strength, 0.8, "Returned Correlation Strength of %d" % result_strength)

@@ -88,8 +88,8 @@ class TestNaiveTemplate(unittest.TestCase):
        result_x, result_y, result_strength, _ = naive_template.pattern_match(self._rect_shape,
                                                                           self._test_image, upsampling=1)
        # Test offsets
        self.assertEqual(result_x, 3)
        self.assertEqual(result_y, 4)
        self.assertEqual(result_x, -3)
        self.assertEqual(result_y, -4)
        # Test Correlation Strength: At least 0.8
        self.assertGreaterEqual(result_strength, 0.8, "Returned Correlation Strength of %d" % result_strength)

@@ -97,8 +97,8 @@ class TestNaiveTemplate(unittest.TestCase):
        result_x, result_y, result_strength, _ = naive_template.pattern_match(self._square_shape,
                                                                           self._test_image, upsampling=1)
        # Test offsets
        self.assertEqual(result_x, -2)
        self.assertEqual(result_y, 4)
        self.assertEqual(result_x, 2)
        self.assertEqual(result_y, -4)
        # Test Correlation Strength: At least 0.8
        self.assertGreaterEqual(result_strength, 0.8, "Returned Correlation Strength of %d" % result_strength)

@@ -106,11 +106,10 @@ class TestNaiveTemplate(unittest.TestCase):
        result_x, result_y, result_strength, _ = naive_template.pattern_match(self._vertical_line,
                                                                           self._test_image, upsampling=1)
        # Test offsets
        self.assertEqual(result_x, 3)
        self.assertEqual(result_y, -5)
        self.assertEqual(result_x, -3)
        self.assertEqual(result_y, 5)
        # Test Correlation Strength: At least 0.8
        self.assertGreaterEqual(result_strength, 0.8, "Returned Correlation Strength of %d" % result_strength)

    def tearDown(self):
        pass
+8 −2
Original line number Diff line number Diff line
@@ -170,7 +170,13 @@ class Roi():
        """
        if self.ndv == None:
            return True
        return np.isclose(self.ndv,self.array).all()
        if len(self.clipped_array) == 0:
            return False
        # Check if we have any ndv values this will return an inverted array
        # where all no data values are true, we need to then invert the array
        # and return the all result. This ensures that a valid array will return
        # True
        return np.invert(np.isclose(self.ndv, self.clipped_array)).all()


    @property
+37 −21
Original line number Diff line number Diff line
import numpy as np
import pytest

import unittest
from unittest.mock import patch, Mock

from plio.io.io_gdal import GeoDataset

from autocnet.transformation.roi import Roi

@pytest.fixture
@@ -10,26 +15,31 @@ def array_with_nodata():
    return arr

def test_geodata_with_ndv_is_valid(geodata_a):
    roi = Roi(geodata_a, 50, 50, size_x=2, size_y=2)
    roi = Roi(geodata_a, 7, 7, size_x=2, size_y=2)
    # Clip the ROI so that our clipped array is populated
    roi.clip()
    assert roi.is_valid == False

def test_geodata_is_valid(geodata_b):
    roi = Roi(geodata_b, 500, 500, size_x=200, size_y=200)
    roi.data.no_data_value = None  # Monkey patch in None (default on the Mock)
    roi.data.no_data_value = 2  # Monkey patch in None (default on the Mock)
    # Clip the ROI so that our clipped array is populated
    roi.clip()
    assert roi.is_valid == True

def test_center(array_with_nodata):
    roi = Roi(array_with_nodata, 5, 5, size_x=5, size_y=5, buffer=5)
    assert roi.center == (10.0,10.0)
def test_center(geodata_c):
    geodata_c.read_array.return_value = np.ones((20, 20))
    roi = Roi(geodata_c, 5, 5, size_x=5, size_y=5, buffer=5)
    assert roi.center == (5.0, 5.0)

@pytest.mark.parametrize("x, y, axr, ayr",[
                         (10.1, 10.1, .1, .1),
                         (10.5, 10.5, .5, .5),
                         (10.9, 10.9, .9, .9)
    ])
def test_roi_remainder(x, y, axr, ayr):
    gd = np.zeros((10,10))
    roi = Roi(gd, x, y)
def test_roi_remainder(x, y, axr, ayr, geodata_c):
    geodata_c.read_array.return_value = np.zeros((10,10))
    roi = Roi(geodata_c, x, y)
    pytest.approx(roi._remainder_x, axr)
    pytest.approx(roi._remainder_y, ayr)
    assert roi.x == x
@@ -40,9 +50,9 @@ def test_roi_remainder(x, y, axr, ayr):
    (15, 15, (100, 100), (15, 15), [0, 30, 0, 30]),
    (75, 75, (100,100), (25,25), [50, 100, 50, 100])
])
def test_extent_computation(x, y, size_arr, size_roi, expected):
    gd = np.zeros(size_arr)
    roi = Roi(gd, x, y, size_x=size_roi[0], size_y=size_roi[1])
def test_extent_computation(x, y, size_arr, size_roi, expected, geodata_c):
    geodata_c.read_array.return_value = np.zeros(size_arr)
    roi = Roi(geodata_c, x, y, size_x=size_roi[0], size_y=size_roi[1])
    pixels = roi.image_extent
    assert pixels == expected

@@ -51,14 +61,14 @@ def test_extent_computation(x, y, size_arr, size_roi, expected):
    (20, 20, (100, 100), (20, 20), 0, (0,3030)),
    (69, 69, (100,100), (30,30), 3, (4545, 9999))
])
def test_array_extent_computation(x, y, size_arr, size_roi, buffer, expected):
    gd = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)
def test_array_extent_computation(x, y, size_arr, size_roi, buffer, expected, geodata_c):
    geodata_c.read_array.return_value = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)

    roi = Roi(gd, x, y, size_x=size_roi[0], size_y=size_roi[1], buffer=buffer)
    array = roi.clip()
    roi = Roi(geodata_c, x, y, size_x=size_roi[0], size_y=size_roi[1], buffer=buffer)
    roi.clip()

    assert array.dtype == np.float32
    assert (array.shape == np.asarray(size_roi) * 2 + 1).all()
    assert roi.clipped_array.dtype == np.float32
    assert (roi.clipped_array.shape == np.asarray(size_roi) * 2 + 1).all()

@pytest.mark.parametrize("x, y, x1, y1, xs, ys, size_arr, size_roi, expected",[
    (50, 50, 50, 50, -5, -5, (100, 100), (10, 10), (45, 45)),
@@ -66,8 +76,14 @@ def test_array_extent_computation(x, y, size_arr, size_roi, buffer, expected):
    (50, 50, 10, 10,  5,  5, (100, 100), (20, 20), (15, 15 ))
])
def test_subpixel_using_roi(x, y, x1, y1, xs, ys, size_arr, size_roi, expected):
    source = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)
    destination = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)
    source = Mock(GeoDataset)
    source_array = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)
    source.read_array.return_value = source_array

    destination = Mock(GeoDataset)
    destination_array = np.arange(size_arr[0]*size_arr[1]).reshape(size_arr)
    destination.read_array.return_value = destination_array

    s_roi = Roi(source, x, y, size_x=size_roi[0], size_y=size_roi[1])
    d_roi = Roi(destination, x1, y1, size_x=size_roi[0], size_y=size_roi[1])