Commit 0fd2eb30 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

added parameters for adjusting resampling techniques via console interface

components.CoReg.COREG:
- __init__(): now accepts also integer values as resampling techniques

components.DeShifter:
- revised _dict_rspAlg_rsp_Int

coreg_cmd:
- added new parameters for adjusting resampling technique

updated __version__
parent 1dd27111
......@@ -9,7 +9,7 @@ from .components import utilities
from .components import geometry
__author__ = 'Daniel Scheffler'
__version__= '2017-04-05_05'
__version__= '2017-04-26_01'
__all__=['COREG',
'COREG_LOCAL',
......
......@@ -220,7 +220,7 @@ class COREG(object):
"Got %s with length %s." %(type(nodata),len(nodata))
for rspAlg in [resamp_alg_deshift, resamp_alg_calc]:
assert rspAlg in _dict_rspAlg_rsp_Int.keys(), "'%s' is not a supported resampling algorithm." % rspAlg
if resamp_alg_calc=='average' and (v or not q):
if resamp_alg_calc in ['average', 5] and (v or not q):
warnings.warn("The resampling algorithm 'average' causes sinus-shaped patterns in fft images that will "
"affect the precision of the calculated spatial shifts! It is highly recommended to "
"choose another resampling algorithm.")
......@@ -236,8 +236,10 @@ class COREG(object):
self.match_gsd = match_gsd
self.out_gsd = out_gsd
self.target_xyGrid = target_xyGrid
self.rspAlg_DS = resamp_alg_deshift
self.rspAlg_calc = resamp_alg_calc
self.rspAlg_DS = resamp_alg_deshift \
if isinstance(resamp_alg_deshift, str) else _dict_rspAlg_rsp_Int[resamp_alg_deshift]
self.rspAlg_calc = resamp_alg_calc \
if isinstance(resamp_alg_calc, str) else _dict_rspAlg_rsp_Int[resamp_alg_calc]
self.calc_corners = calc_corners
self.CPUs = CPUs
self.bin_ws = binary_ws
......
......@@ -20,7 +20,9 @@ from py_tools_ds.ptds.geo.raster.reproject import warp_ndarray
from py_tools_ds.ptds.numeric.vector import find_nearest
_dict_rspAlg_rsp_Int = {'nearest': 0, 'bilinear': 1, 'cubic': 2, 'cubic_spline': 3, 'lanczos': 4, 'average': 5,
'mode': 6, 'max': 7, 'min': 8 , 'med': 9, 'q1':10, 'q2':11}
'mode': 6, 'max': 7, 'min': 8 , 'med': 9, 'q1':10, 'q2':11,
0:'nearest', 1:'bilinear', 2: 'cubic', 3:'cubic_spline', 4:'lanczos', 5:'average',
6:'mode', 7:'max', 8: 'min', 9:'med', 10:'q1', 11:'q2'}
class DESHIFTER(object):
"""See help(DESHIFTER) for documentation!"""
......
......@@ -751,12 +751,13 @@ class Tie_Point_Refiner(object):
self.ransac_model_robust = None
def run_filtering(self, level=2):
def run_filtering(self, level=2):#, min_reliability=60, rs_max_outlier=10, rs_tolerance=2.5, rs_max_iter=15,
#rs_exclude_previous_outliers=True, rs_timeout=20):
# TODO catch empty GDF
# RELIABILITY filtering
if level>0:
marked_recs = GeoSeries(self._reliability_thresholding())
marked_recs = GeoSeries(self._reliability_thresholding())
self.GDF['L1_OUTLIER'] = marked_recs
self.new_cols.append('L1_OUTLIER')
if not self.q:
......@@ -764,7 +765,7 @@ class Tie_Point_Refiner(object):
# SSIM filtering
if level>1:
marked_recs = GeoSeries(self._SSIM_filtering())
marked_recs = GeoSeries(self._SSIM_filtering())
self.GDF['L2_OUTLIER'] = marked_recs
self.new_cols.append('L2_OUTLIER')
if not self.q:
......@@ -772,7 +773,7 @@ class Tie_Point_Refiner(object):
# RANSAC filtering
if level>2:
marked_recs = GeoSeries(self._RANSAC_outlier_detection())
marked_recs = GeoSeries(self._RANSAC_outlier_detection())
if len(self.GDF)>4:
# running RANSAC with less than four tie points makes no sense
self.GDF['L3_OUTLIER'] = marked_recs.tolist() # we need to join a list here because otherwise it's merged by the 'index' column
......@@ -793,11 +794,8 @@ class Tie_Point_Refiner(object):
def _reliability_thresholding(self, min_reliability=60):
"""Exclude all records where estimated reliability of the calculated shifts is below the given threshold.
"""Exclude all records where estimated reliability of the calculated shifts is below the given threshold."""
:param min_reliability:
:return:
"""
return self.GDF.RELIABILITY < min_reliability
......
......@@ -48,6 +48,8 @@ def run_global_coreg(args):
align_grids = args.align_grids,
match_gsd = args.match_gsd,
out_gsd = args.out_gsd,
resamp_alg_calc = args.rsp_alg_deshift,
resamp_alg_deshift = args.rsp_alg_calc,
data_corners_ref = args.cor0,
data_corners_tgt = args.cor1,
nodata = args.nodata,
......@@ -81,6 +83,8 @@ def run_local_coreg(args):
#align_grids = args.align_grids,
#match_gsd = args.match_gsd,
#out_gsd = args.out_gsd,
resamp_alg_calc = args.rsp_alg_deshift,
resamp_alg_deshift = args.rsp_alg_calc,
data_corners_ref = args.cor0,
data_corners_tgt = args.cor1,
nodata = args.nodata,
......@@ -191,6 +195,16 @@ if __name__ == '__main__':
gloArg('-out_gsd', nargs=2, type=float, help='xgsd ygsd: set the output pixel size in map units'\
'(default: original pixel size of the image to be shifted)', metavar=('xgsd','ygsd'))
gloArg('-rsp_alg_deshift', nargs='?', type=int, choices=list(range(12)), default=2,
help="the resampling algorithm to be used for shift correction (if neccessary) "
"(valid algorithms: 0=nearest neighbour, 1=bilinear, 2=cubic, 3=cubic_spline, 4=lanczos, 5=average, "
"6=mode, 7=max, 8=min, 9=med, 10=q1, 11=q3), default: 2")
gloArg('-rsp_alg_calc', nargs='?', type=int, choices=list(range(12)), default=2,
help="the resampling algorithm to be used for all warping processes during calculation of spatial shifts "
"(valid algorithms: 0=nearest neighbour, 1=bilinear, 2=cubic, 3=cubic_spline, 4=lanczos, 5=average, "
"6=mode, 7=max, 8=min, 9=med, 10=q1, 11=q3), default: 2 (highly recommended)")
# TODO implement footprint_poly_ref, footprint_poly_tgt
gloArg('-cor0', nargs=8, type=float, help="map coordinates of data corners within reference image: ",
......@@ -293,6 +307,16 @@ if __name__ == '__main__':
# TODO implement footprint_poly_ref, footprint_poly_tgt
locArg('-rsp_alg_deshift', nargs='?', type=int, choices=list(range(12)), default=2,
help="the resampling algorithm to be used for shift correction (if neccessary) "
"(valid algorithms: 0=nearest neighbour, 1=bilinear, 2=cubic, 3=cubic_spline, 4=lanczos, 5=average, "
"6=mode, 7=max, 8=min, 9=med, 10=q1, 11=q3), default: 2")
locArg('-rsp_alg_calc', nargs='?', type=int, choices=list(range(12)), default=2,
help="the resampling algorithm to be used for all warping processes during calculation of spatial shifts "
"(valid algorithms: 0=nearest neighbour, 1=bilinear, 2=cubic, 3=cubic_spline, 4=lanczos, 5=average, "
"6=mode, 7=max, 8=min, 9=med, 10=q1, 11=q3), default: 2 (highly recommended)")
locArg('-cor0', nargs=8, type=float, help="map coordinates of data corners within reference image: ",
metavar=tuple("UL-X UL-Y UR-X UR-Y LR-X LR-Y LL-X LL-Y".split(' ')), default=None)
......
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