Commit c274c1ea authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Disabled coverage for deprecated funcs. Too small SCPS is now catched....

Disabled coverage for deprecated funcs. Too small SCPS is now catched. Tie_Point_Grid.get_CoRegPoints_table(): local CS not rejectd anymore. Fixed test_shift_calculation_with_image_coords_only(). Fixed flake8 issues.
parent 80122871
Pipeline #1301 failed with stages
in 12 minutes
......@@ -1052,6 +1052,11 @@ class COREG(object):
scps = self._calc_shifted_cross_power_spectrum(gdsh_im0, crsp_im1)
if scps is not None:
if scps.shape[0] < 3 or scps.shape[1] < 3:
self._handle_error(RuntimeError('Shifted cross power spectrum became too small for computing the '
'point of registration. Matching failed.'))
return 'invalid', None, None, scps
peakpos = self._get_peakpos(scps)
x_shift, y_shift = self._get_shifts_from_peakpos(peakpos, scps.shape)
if (x_shift, y_shift) == (0, 0):
......@@ -1402,7 +1407,7 @@ class COREG(object):
self.deshift_results = DS.correct_shifts()
return self.deshift_results
def _correct_shifts_OLD(self):
def _correct_shifts_OLD(self): # pragma: no cover
if self.success:
if not os.path.exists(os.path.dirname(self.path_out)):
os.makedirs(os.path.dirname(self.path_out))
......@@ -1418,7 +1423,7 @@ class COREG(object):
else:
warnings.warn('No result written because detection of image displacements failed.')
def _shift_image_by_updating_map_info(self):
def _shift_image_by_updating_map_info(self): # pragma: no cover
if not self.q:
print('\nWriting output...')
ds_im2shift = gdal.Open(self.shift.path)
......@@ -1466,7 +1471,7 @@ class COREG(object):
if not self.q:
print('\nCoregistered image written to %s.' % self.path_out)
def _align_coordinate_grids(self):
def _align_coordinate_grids(self): # pragma: no cover
xgsd, ygsd = (self.ref.xgsd, self.ref.ygsd) if self.match_gsd else self.out_gsd if self.out_gsd \
else (self.shift.xgsd, self.shift.ygsd) # self.match_gsd overrides self.out_gsd in __init__
......@@ -1518,7 +1523,7 @@ class COREG(object):
print(output)
self._handle_error(RuntimeError('Resampling failed.'))
def _resample_without_grid_aligning(self):
def _resample_without_grid_aligning(self): # pragma: no cover
xgsd, ygsd = (self.ref.xgsd, self.ref.ygsd) if self.match_gsd else self.out_gsd if self.out_gsd \
else (self.shift.xgsd, self.shift.ygsd) # self.match_gsd overrides self.out_gsd in __init__
......
......@@ -4,6 +4,7 @@ import warnings
import os
from copy import copy
from six import PY2
from importlib import util
# custom
try:
......@@ -474,16 +475,14 @@ class COREG_LOCAL(object):
warnings.warn(UserWarning('This function is still under construction and may not work as expected!'))
assert self.CoRegPoints_table is not None, 'Calculate tie point grid first!'
try:
import folium
import geojson
from folium import plugins
except ImportError:
folium, geojson, plugins = [None] * 3
if not folium or not geojson:
if not all([util.find_spec('folium'), util.find_spec('geojson')]):
raise ImportError("This method requires the libraries 'folium' and 'geojson'. They can be installed with "
"the shell command 'pip install folium geojson'.")
import folium
import geojson
from folium import plugins
lon_min, lat_min, lon_max, lat_max = \
reproject_shapelyGeometry(self.im2shift.box.mapPoly, self.im2shift.projection, 4326).bounds
center_lon, center_lat = (lon_min + lon_max) / 2, (lat_min + lat_max) / 2
......
......@@ -21,13 +21,13 @@ from skimage.transform import AffineTransform, PolynomialTransform
# internal modules
from .CoReg import COREG
from . import io as IO
from py_tools_ds.geo.projection import isProjectedOrGeographic, get_UTMzone, dict_to_proj4, proj4_to_WKT
from py_tools_ds.geo.projection import isProjectedOrGeographic, isLocal, get_UTMzone, dict_to_proj4, proj4_to_WKT
from py_tools_ds.io.pathgen import get_generic_outpath
from py_tools_ds.processing.progress_mon import ProgressBar
from py_tools_ds.geo.vector.conversion import points_to_raster
from geoarray import GeoArray
from .CoReg import GeoArray_CoReg
from .CoReg import GeoArray_CoReg # noqa F401 # flake8 issue
__author__ = 'Daniel Scheffler'
......@@ -278,7 +278,9 @@ class Tie_Point_Grid(object):
XYarr2PointGeom = np.vectorize(lambda X, Y: Point(X, Y), otypes=[Point])
geomPoints = np.array(XYarr2PointGeom(self.XY_mapPoints[:, 0], self.XY_mapPoints[:, 1]))
if isProjectedOrGeographic(self.COREG_obj.shift.prj) == 'geographic':
if isLocal(self.COREG_obj.shift.prj):
crs = None
elif isProjectedOrGeographic(self.COREG_obj.shift.prj) == 'geographic':
crs = dict(ellps='WGS84', datum='WGS84', proj='longlat')
elif isProjectedOrGeographic(self.COREG_obj.shift.prj) == 'projected':
UTMzone = abs(get_UTMzone(prj=self.COREG_obj.shift.prj))
......@@ -622,7 +624,7 @@ class Tie_Point_Grid(object):
print('Writing %s ...' % path_out)
GDF2pass.to_file(path_out)
def _to_PointShapefile(self, skip_nodata=True, skip_nodata_col='ABS_SHIFT'):
def _to_PointShapefile(self, skip_nodata=True, skip_nodata_col='ABS_SHIFT'): # pragma: no cover
warnings.warn(DeprecationWarning(
"'_tiepoints_grid_to_PointShapefile' is deprecated." # TODO delete if other method validated
" 'tiepoints_grid_to_PointShapefile' is much faster."))
......@@ -677,7 +679,7 @@ class Tie_Point_Grid(object):
return out_GA
def _to_Raster_using_KrigingOLD(self, attrName, skip_nodata=1, skip_nodata_col='ABS_SHIFT', outGridRes=None,
path_out=None, tilepos=None):
path_out=None, tilepos=None): # pragma: no cover
warnings.warn(DeprecationWarning("'to_Raster_using_KrigingOLD' is deprecated. Use to_Raster_using_Kriging "
"instead.")) # TODO delete
......@@ -920,7 +922,7 @@ class Tie_Point_Refiner(object):
raise ValueError
min_inlier_percentage = 100 - self.rs_max_outlier_percentage
class PolyTF_1(PolynomialTransform):
class PolyTF_1(PolynomialTransform): # pragma: no cover
def estimate(*data):
return PolynomialTransform.estimate(*data, order=1)
......
......@@ -97,6 +97,7 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
CR = self.run_shift_detection_correction(ref, tgt,
**dict(self.coreg_kwargs,
wp=(1200, -1600),
footprint_poly_ref=None,
footprint_poly_tgt=None))
self.assertTrue(CR.success)
......
......@@ -6,6 +6,7 @@
import unittest
import shutil
import os
from importlib import util
# custom
from .cases import test_cases
......@@ -63,12 +64,8 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
CRL.CoRegPoints_table
# test tie point grid visualization
try:
# noinspection PyUnresolvedReferences
from mpl_toolkits.basemap import Basemap
CRL.view_CoRegPoints() # only works if basemap is installed
except ImportError:
pass
if util.find_spec('mpl_toolkits.basemap'): # only works if basemap is installed
CRL.view_CoRegPoints()
# test shift correction and output writer
CRL.correct_shifts()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment