From 58dc8f49f1e145de5a616ad45afa460a1dd15216 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Thu, 20 Aug 2020 18:12:00 +0200 Subject: [PATCH 1/2] Fixed a bug which causes COREG.equalize_pixGrids() to run although the pixel grids of reference and target image are equal. Fixed ResourceWarning in COREG.show_matchWin() as well as in COREG.calculate_spatial_shifts(). Fixed exception in COREG.view_CoRegPoints_folium() in case of a recent version of folium. Signed-off-by: Daniel Scheffler --- arosics/CoReg.py | 14 ++++---------- arosics/CoReg_local.py | 4 +++- tests/test_COREG.py | 1 + 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/arosics/CoReg.py b/arosics/CoReg.py index 57e646e..8c974de 100755 --- a/arosics/CoReg.py +++ b/arosics/CoReg.py @@ -52,7 +52,7 @@ from py_tools_ds.geo.coord_calc import get_corner_coordinates from py_tools_ds.geo.vector.topology import get_overlap_polygon, get_smallest_boxImYX_that_contains_boxMapYX from py_tools_ds.geo.projection import prj_equal, get_proj4info from py_tools_ds.geo.vector.geometry import boxObj, round_shapelyPoly_coords -from py_tools_ds.geo.coord_grid import move_shapelyPoly_to_image_grid +from py_tools_ds.geo.coord_grid import move_shapelyPoly_to_image_grid, is_coord_grid_equal from py_tools_ds.geo.coord_trafo import reproject_shapelyGeometry, mapXY2imXY, imXY2mapXY from py_tools_ds.geo.raster.reproject import warp_ndarray from py_tools_ds.geo.map_info import geotransform2mapinfo @@ -463,7 +463,8 @@ class COREG(object): def equalize_pixGrids(self): """Equalize image grids and projections of reference and target image (align target to reference).""" - if not (prj_equal(self.ref.prj, self.shift.prj) and self.ref.xygrid_specs == self.shift.xygrid_specs): + if not (prj_equal(self.ref.prj, self.shift.prj) and + is_coord_grid_equal(self.ref.gt, *self.shift.xygrid_specs)): if not self.q: print("Equalizing pixel grids and projections of reference and target image...") @@ -528,7 +529,7 @@ class COREG(object): raise ImportError( "This method requires the library 'holoviews'. It can be installed for Anaconda with " "the shell command 'conda install -c ioam holoviews bokeh'.") - warnings.filterwarnings('ignore') + hv.notebook_extension('matplotlib') hv.Store.add_style_opts(hv.Image, ['vmin', 'vmax']) @@ -581,7 +582,6 @@ class COREG(object): # Construct a HoloMap by defining the sampling on the Dimension # dmap = hv.DynamicMap(image_slice, kdims=[hv.Dimension('z_axis', values=keys)]) - warnings.filterwarnings('default') return hmap @@ -1249,9 +1249,6 @@ class COREG(object): if self.success is False: return 'fail' - if self.q: - warnings.simplefilter('ignore') - # set self.matchWin and self.otherWin (GeoArray instances) self._get_image_windows_to_match() # 45-90ms @@ -1274,7 +1271,6 @@ class COREG(object): if scps is None: self.success = False - warnings.simplefilter('default') return 'fail' @@ -1364,8 +1360,6 @@ class COREG(object): self._validate_ssim_improvement() # FIXME uses the not updated matchWin size self.shift_reliability = self._calc_shift_reliability(scps) - warnings.simplefilter('default') - return 'success' def _get_updated_map_info(self): diff --git a/arosics/CoReg_local.py b/arosics/CoReg_local.py index db3008e..9afdf6a 100644 --- a/arosics/CoReg_local.py +++ b/arosics/CoReg_local.py @@ -548,7 +548,9 @@ class COREG_LOCAL(object): image=image2plot, bounds=[[lat_min, lon_min], [lat_max, lon_max]], ).add_to(map_osm) - folium.GeoJson(self.CoRegPoints_table.loc[:, ['geometry', attribute2plot]]).add_to(map_osm) + points_values = self.CoRegPoints_table[['geometry', attribute2plot]] + points_values.geometry.crs = points_values.crs + folium.GeoJson(points_values).add_to(map_osm) # add overlap polygon overlapPoly = reproject_shapelyGeometry(self.COREG_obj.overlap_poly, self.im2shift.epsg, 4326) diff --git a/tests/test_COREG.py b/tests/test_COREG.py index 43b5787..c687386 100644 --- a/tests/test_COREG.py +++ b/tests/test_COREG.py @@ -105,6 +105,7 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase): def test_shift_calculation_with_image_coords_only(self): """Test with default parameters - should compute X/Y shifts properly and write the de-shifted target image.""" + # FIXME fails when executed alone # overwrite gt and prj ref = GeoArray(self.ref_path) -- GitLab From a4acc938364afe7d265f46b6834e035126c82c1f Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Fri, 21 Aug 2020 15:56:11 +0200 Subject: [PATCH 2/2] Added tolerances to the window position validation to avoid float precision issues. Updated minimal version of geoarray. Signed-off-by: Daniel Scheffler --- .gitlab-ci.yml | 2 +- arosics/CoReg.py | 10 ++++++---- requirements.txt | 2 +- setup.py | 2 +- tests/CI_docker/context/environment_arosics.yml | 2 +- tests/test_COREG_LOCAL.py | 11 +++++++---- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5bdc910..0291f95 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,7 @@ test_arosics: script: - source /root/miniconda3/bin/activate ci_env - pip install "py_tools_ds>=0.14.28" # FIXME remove as soon as docker runner has been updated - - pip install "geoarray>=0.8.29" # FIXME remove as soon as docker runner has been updated + - pip install "geoarray>=0.8.30" # FIXME remove as soon as docker runner has been updated # run tests - make nosetests diff --git a/arosics/CoReg.py b/arosics/CoReg.py index 8c974de..9acf11c 100755 --- a/arosics/CoReg.py +++ b/arosics/CoReg.py @@ -648,7 +648,7 @@ class COREG(object): wp = (wp[0] if wp[0] else overlap_center_pos_x[0]), (wp[1] if wp[1] else overlap_center_pos_y[0]) # validate window position - if not self.overlap_poly.contains(Point(wp)): + if not self.overlap_poly.buffer(1e-5).contains(Point(wp)): # in case the centroid point is not within overlap area if not self.q: warnings.warn("The centroid point of the two input images could not be used as matching window " @@ -660,11 +660,11 @@ class COREG(object): overlap_center_pos_x, overlap_center_pos_y = self.overlap_poly.representative_point().coords.xy wp = overlap_center_pos_x[0], overlap_center_pos_y[0] - assert self.overlap_poly.contains(Point(wp)) + assert self.overlap_poly.buffer(1e-5).contains(Point(wp)) else: # validate window position - if not self.overlap_poly.contains(Point(wp)): + if not self.overlap_poly.buffer(1e-5).contains(Point(wp)): self._handle_error(ValueError('The provided window position %s/%s is outside of the overlap ' 'area of the two input images. Check the coordinates.' % wp)) @@ -767,7 +767,9 @@ class COREG(object): if self.success is not False: # check result -> ProgrammingError if not fulfilled - def within_equal(inner, outer): return inner.within(outer) or inner.equals(outer) + def within_equal(inner, outer): + return inner.within(outer.buffer(1e-5)) or inner.equals(outer) + assert within_equal(matchBox.mapPoly, otherBox.mapPoly) assert within_equal(otherBox.mapPoly, overlapWin.mapPoly) diff --git a/requirements.txt b/requirements.txt index 20f1e8a..49b3ef8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -geoarray>=0.8.17 +geoarray>=0.8.30 py_tools_ds>=0.14.28 cmocean numpy diff --git a/setup.py b/setup.py index 361ada6..9c78d3c 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ with open("arosics/version.py") as version_file: exec(version_file.read(), version) requirements = ['numpy', 'gdal', 'shapely', 'scikit-image', 'matplotlib', 'geopandas', 'pandas', - 'geoarray>=0.8.17', 'py_tools_ds>=0.14.28', 'plotly', 'cmocean', 'six', 'folium>=0.6.0', 'geojson' + 'geoarray>=0.8.30', 'py_tools_ds>=0.14.28', 'plotly', 'cmocean', 'six', 'folium>=0.6.0', 'geojson' # 'pykrige' # conda install --yes -c conda-forge pykrige # 'pyfftw', # conda install --yes -c conda-forge pyfftw=0.10.4 ; \ # 'basemap', # conda install --yes -c conda-forge basemap; \ diff --git a/tests/CI_docker/context/environment_arosics.yml b/tests/CI_docker/context/environment_arosics.yml index fb2dca7..62c238f 100644 --- a/tests/CI_docker/context/environment_arosics.yml +++ b/tests/CI_docker/context/environment_arosics.yml @@ -45,5 +45,5 @@ dependencies: - coverage - rednose - plotly - - geoarray>=0.8.17 + - geoarray>=0.8.30 - py_tools_ds>=0.14.28 diff --git a/tests/test_COREG_LOCAL.py b/tests/test_COREG_LOCAL.py index 9f6cd15..a168e6f 100644 --- a/tests/test_COREG_LOCAL.py +++ b/tests/test_COREG_LOCAL.py @@ -106,15 +106,18 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase): ref = GeoArray(self.ref_path) ref.to_mem() ref.filePath = None - ref.gt = [330000.19999996503, 0.6, 0.0, 5862000.7999997628, 0.0, -0.6] - # ref.gt = [330000.1, 10.1, 0.0, 5862000.1, 0.0, -10.1] tgt = GeoArray(self.tgt_path) tgt.to_mem() tgt.filePath = None - tgt.gt = [330000.19999996503, 0.6, 0.0, 5862000.7999997628, 0.0, -0.6] + + ref.gt = [330000.19999996503, 10.00000001, 0.0, 5862000.7999997628, 0.0, -10.00000001] + # ref.gt = [330000.1, 10.1, 0.0, 5862000.1, 0.0, -10.1] + tgt.gt = [335440.19999996503, 10.00000001, 0.0, 5866490.7999997628, 0.0, -10.00000001] + # tgt.gt = [330000.1, 10.1, 0.0, 5862000.1, 0.0, -10.1] # get instance of COREG_LOCAL object - CRL = COREG_LOCAL(ref, tgt, **dict(**self.coreg_kwargs)) + CRL = COREG_LOCAL(ref, tgt, **dict(CPUs=32, + **self.coreg_kwargs)) # use the getter of the CoRegPoints_table to calculate tie point grid # noinspection PyStatementEffect -- GitLab