Loading CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ release. - Added residual column information to the Points model ### Changed - Roi `is_valid` method changed to use np.isclose to ensure floating point tolerances when checking if the NDV is in the ROI. - `geom_match_simple` defaults to a 3rd order warp for interpolation - Speed improvements for place_points_from_cnet dependent on COPY method instead of ORM update - License from custom to CC0. Fixes [#607](https://github.com/USGS-Astrogeology/autocnet/issues/607) Loading autocnet/transformation/roi.py +5 −1 Original line number Diff line number Diff line Loading @@ -144,7 +144,11 @@ class Roi(): no null pixels (as defined by the no data value (ndv)) are present. """ return self.ndv not in self.array print(self.ndv) if self.ndv == None: return True return np.isclose(self.ndv,self.array).all() @property def variance(self): Loading autocnet/transformation/tests/test_roi.py +13 −16 Original line number Diff line number Diff line Loading @@ -10,22 +10,17 @@ def array_with_nodata(): return arr def test_geodata_with_ndv_is_valid(geodata_a): roi = Roi(geodata_a, 5, 5) roi = Roi(geodata_a, 50, 50, size_x=2, size_y=2) assert roi.is_valid == False def test_geodata_is_valid(geodata_b): roi = Roi(geodata_b, 5, 5) 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) assert roi.is_valid == True def test_center(array_with_nodata): roi = Roi(array_with_nodata, 5, 5) assert roi.center == (5.5,5.5) @pytest.mark.parametrize("ndv, truthy", [(None, True), (0, False)]) def test_is_valid(array_with_nodata, ndv, truthy): roi = Roi(array_with_nodata, 2.5, 2.5, ndv=ndv) assert roi.is_valid == truthy roi = Roi(array_with_nodata, 5, 5, size_x=5, size_y=5) assert roi.center == (5,5) @pytest.mark.parametrize("x, y, axr, ayr",[ (10.1, 10.1, .1, .1), Loading @@ -42,8 +37,8 @@ def test_roi_remainder(x, y, axr, ayr): @pytest.mark.parametrize("x, y, size_arr, size_roi, expected",[ (50, 50, (100,100), (10,10), [40,60,40,60]), (10, 10, (100, 100), (20, 20), [0, 30, 0, 30]), (75, 75, (100,100), (30,30), [45, 100, 45, 100]) (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) Loading @@ -53,15 +48,17 @@ def test_extent_computation(x, y, size_arr, size_roi, expected): @pytest.mark.parametrize("x, y, size_arr, size_roi, expected",[ (50, 50, (100,100), (10,10), (4040, 6060)), (10, 10, (100, 100), (20, 20), (0,3030)), (75, 75, (100,100), (30,30), (4545, 9999)) (20, 20, (100, 100), (20, 20), (0,3030)), (69, 69, (100,100), (30,30), (4545, 9999)) ]) def test_array_extent_computation(x, y, size_arr, size_roi, expected): gd = 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]) array = roi.clip() assert array.min() == expected[0] assert array.max() == expected[1] assert array.dtype == np.float32 assert (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)), Loading conftest.py +7 −5 Original line number Diff line number Diff line Loading @@ -150,17 +150,19 @@ def node_c(geodata_c): #TODO: Can these be a single parameterized fixture - so much boilerplate! @pytest.fixture(scope='session') def geodata_a(): arr = np.ones((100,100)) arr[5,5] = -3.40282266e+38 a = Mock(spec=GeoDataset, raster_size=[10,10], no_data_value=-3.40282266e+38) arr = np.ones((101,101)) ndv = -3.40282266e+38 arr[50,50] = ndv a = Mock(spec=GeoDataset, raster_size=[101,101], no_data_value=ndv) a.pixel_to_latlon = MagicMock(side_effect=lambda x, y: (x, y)) a.read_array = MagicMock(return_value=arr) a.array = MagicMock(return_value=arr) return a @pytest.fixture(scope='session') def geodata_b(): arr = np.ones((100,100)) b = Mock(spec=GeoDataset, raster_size=[10,10]) arr = np.ones((1000,1000), dtype=np.float32) b = Mock(spec=GeoDataset, raster_size=[1000,1000], ndv=None) b.pixel_to_latlon = MagicMock(side_effect=lambda x, y: (x, y)) b.read_array = MagicMock(return_value=arr) return b Loading Loading
CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ release. - Added residual column information to the Points model ### Changed - Roi `is_valid` method changed to use np.isclose to ensure floating point tolerances when checking if the NDV is in the ROI. - `geom_match_simple` defaults to a 3rd order warp for interpolation - Speed improvements for place_points_from_cnet dependent on COPY method instead of ORM update - License from custom to CC0. Fixes [#607](https://github.com/USGS-Astrogeology/autocnet/issues/607) Loading
autocnet/transformation/roi.py +5 −1 Original line number Diff line number Diff line Loading @@ -144,7 +144,11 @@ class Roi(): no null pixels (as defined by the no data value (ndv)) are present. """ return self.ndv not in self.array print(self.ndv) if self.ndv == None: return True return np.isclose(self.ndv,self.array).all() @property def variance(self): Loading
autocnet/transformation/tests/test_roi.py +13 −16 Original line number Diff line number Diff line Loading @@ -10,22 +10,17 @@ def array_with_nodata(): return arr def test_geodata_with_ndv_is_valid(geodata_a): roi = Roi(geodata_a, 5, 5) roi = Roi(geodata_a, 50, 50, size_x=2, size_y=2) assert roi.is_valid == False def test_geodata_is_valid(geodata_b): roi = Roi(geodata_b, 5, 5) 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) assert roi.is_valid == True def test_center(array_with_nodata): roi = Roi(array_with_nodata, 5, 5) assert roi.center == (5.5,5.5) @pytest.mark.parametrize("ndv, truthy", [(None, True), (0, False)]) def test_is_valid(array_with_nodata, ndv, truthy): roi = Roi(array_with_nodata, 2.5, 2.5, ndv=ndv) assert roi.is_valid == truthy roi = Roi(array_with_nodata, 5, 5, size_x=5, size_y=5) assert roi.center == (5,5) @pytest.mark.parametrize("x, y, axr, ayr",[ (10.1, 10.1, .1, .1), Loading @@ -42,8 +37,8 @@ def test_roi_remainder(x, y, axr, ayr): @pytest.mark.parametrize("x, y, size_arr, size_roi, expected",[ (50, 50, (100,100), (10,10), [40,60,40,60]), (10, 10, (100, 100), (20, 20), [0, 30, 0, 30]), (75, 75, (100,100), (30,30), [45, 100, 45, 100]) (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) Loading @@ -53,15 +48,17 @@ def test_extent_computation(x, y, size_arr, size_roi, expected): @pytest.mark.parametrize("x, y, size_arr, size_roi, expected",[ (50, 50, (100,100), (10,10), (4040, 6060)), (10, 10, (100, 100), (20, 20), (0,3030)), (75, 75, (100,100), (30,30), (4545, 9999)) (20, 20, (100, 100), (20, 20), (0,3030)), (69, 69, (100,100), (30,30), (4545, 9999)) ]) def test_array_extent_computation(x, y, size_arr, size_roi, expected): gd = 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]) array = roi.clip() assert array.min() == expected[0] assert array.max() == expected[1] assert array.dtype == np.float32 assert (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)), Loading
conftest.py +7 −5 Original line number Diff line number Diff line Loading @@ -150,17 +150,19 @@ def node_c(geodata_c): #TODO: Can these be a single parameterized fixture - so much boilerplate! @pytest.fixture(scope='session') def geodata_a(): arr = np.ones((100,100)) arr[5,5] = -3.40282266e+38 a = Mock(spec=GeoDataset, raster_size=[10,10], no_data_value=-3.40282266e+38) arr = np.ones((101,101)) ndv = -3.40282266e+38 arr[50,50] = ndv a = Mock(spec=GeoDataset, raster_size=[101,101], no_data_value=ndv) a.pixel_to_latlon = MagicMock(side_effect=lambda x, y: (x, y)) a.read_array = MagicMock(return_value=arr) a.array = MagicMock(return_value=arr) return a @pytest.fixture(scope='session') def geodata_b(): arr = np.ones((100,100)) b = Mock(spec=GeoDataset, raster_size=[10,10]) arr = np.ones((1000,1000), dtype=np.float32) b = Mock(spec=GeoDataset, raster_size=[1000,1000], ndv=None) b.pixel_to_latlon = MagicMock(side_effect=lambda x, y: (x, y)) b.read_array = MagicMock(return_value=arr) return b Loading