Commit 66cb7b38 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

added output creation options to COREG, COREG_LOCAL and DESHIFTER (keyword...

added output creation options to COREG, COREG_LOCAL and DESHIFTER (keyword 'out_crea_options'); edited some docstrings

components.CoReg.COREG:
- implemented new keyword 'out_crea_options' for specifying GDAL output creation options
- __init__(): edited docstring

components.CoReg_local.COREG_LOCAL:
- implemented new keyword 'out_crea_options' for specifying GDAL output creation options
- __init__(): edited docstring

components.DeShifter.DESHIFTER:
- implemented new keyword 'out_crea_options' for specifying GDAL output creation options

coreg_cmd:
- added parameter '-fmt_out' to global coregistration subparser as well as to COREG call

- updated __version__
parent af659b8a
......@@ -9,7 +9,7 @@ from .components import utilities
from .components import geometry
__author__ = 'Daniel Scheffler'
__version__= '2016-11-08_02'
__version__= '2016-11-09_01'
__all__=['COREG',
'COREG_LOCAL',
......
......@@ -115,12 +115,12 @@ class imParamObj(object):
class COREG(object):
"""See help(COREG) for documentation!"""
def __init__(self, im_ref, im_tgt, path_out=None, fmt_out='ENVI', r_b4match=1, s_b4match=1, wp=(None,None),
ws=(512, 512), max_iter=5, max_shift=5, align_grids=False, match_gsd=False, out_gsd=None,
resamp_alg_deshift='cubic', resamp_alg_calc='cubic', footprint_poly_ref=None, footprint_poly_tgt=None,
data_corners_ref=None, data_corners_tgt=None,
nodata=(None,None), calc_corners=True, multiproc=True, binary_ws=True, force_quadratic_win=True,
progress=True, v=False, path_verbose_out=None, q=False, ignore_errors=False):
def __init__(self, im_ref, im_tgt, path_out=None, fmt_out='ENVI', out_crea_options=None, r_b4match=1, s_b4match=1,
wp=(None,None), ws=(512, 512), max_iter=5, max_shift=5, align_grids=False, match_gsd=False,
out_gsd=None, resamp_alg_deshift='cubic', resamp_alg_calc='cubic', footprint_poly_ref=None,
footprint_poly_tgt=None, data_corners_ref=None, data_corners_tgt=None, nodata=(None,None),
calc_corners=True, multiproc=True, binary_ws=True, force_quadratic_win=True, progress=True, v=False,
path_verbose_out=None, q=False, ignore_errors=False):
"""Detects and corrects global X/Y shifts between a target and refernce image. Geometric shifts are calculated
at a specific (adjustable) image position. Correction performs a global shifting in X- or Y direction.
......@@ -134,6 +134,8 @@ class COREG(object):
- if 'auto': /dir/of/im1/<im1>__shifted_to__<im0>.bsq
:param fmt_out(str): raster file format for output file. ignored if path_out is None. can be any GDAL
compatible raster file format (e.g. 'ENVI', 'GeoTIFF'; default: ENVI)
:param out_crea_options(list): GDAL creation options for the output image,
e.g. ["QUALITY=80", "REVERSIBLE=YES", "WRITE_METADATA=YES"]
:param r_b4match(int): band of reference image to be used for matching (starts with 1; default: 1)
:param s_b4match(int): band of shift image to be used for matching (starts with 1; default: 1)
:param wp(tuple): custom matching window position as map values in the same projection like the
......@@ -154,10 +156,16 @@ class COREG(object):
(valid algorithms: nearest, bilinear, cubic, cubic_spline, lanczos, average, mode,
max, min, med, q1, q3)
default: cubic (highly recommended)
:param footprint_poly_ref(str):
:param footprint_poly_tgt(str):
:param data_corners_ref(list): map coordinates of data corners within reference image
:param data_corners_tgt(list): map coordinates of data corners within image to be shifted
:param footprint_poly_ref(str): footprint polygon of the reference image (WKT string or shapely.geometry.Polygon),
e.g. 'POLYGON ((299999 6000000, 299999 5890200, 409799 5890200, 409799 6000000,
299999 6000000))'
:param footprint_poly_tgt(str): footprint polygon of the image to be shifted (WKT string or shapely.geometry.Polygon)
e.g. 'POLYGON ((299999 6000000, 299999 5890200, 409799 5890200, 409799 6000000,
299999 6000000))'
:param data_corners_ref(list): map coordinates of data corners within reference image.
ignored if footprint_poly_ref is given.
:param data_corners_tgt(list): map coordinates of data corners within image to be shifted.
ignored if footprint_poly_tgt is given.
:param nodata(tuple): no data values for reference image and image to be shifted
:param calc_corners(bool): calculate true positions of the dataset corners in order to get a useful
matching window position within the actual image overlap
......@@ -194,6 +202,7 @@ class COREG(object):
self.path_out = path_out # updated by self.set_outpathes
self.fmt_out = fmt_out
self.out_creaOpt = out_crea_options
self.win_pos_XY = wp # updated by self.get_opt_winpos_winsize()
self.win_size_XY = ws # updated by self.get_opt_winpos_winsize()
self.max_iter = max_iter
......@@ -959,17 +968,18 @@ class COREG(object):
def correct_shifts(self):
DS = DESHIFTER(self.shift.GeoArray, self.coreg_info,
path_out = self.path_out,
fmt_out = self.fmt_out,
out_gsd = self.out_gsd,
resamp_alg = self.rspAlg_DS,
align_grids = self.align_grids,
match_gsd = self.match_gsd,
nodata = self.shift.nodata,
CPUs = None if self.mp else 1,
progress = self.progress,
v = self.v,
q = self.q)
path_out = self.path_out,
fmt_out = self.fmt_out,
out_crea_options = self.out_creaOpt,
out_gsd = self.out_gsd,
resamp_alg = self.rspAlg_DS,
align_grids = self.align_grids,
match_gsd = self.match_gsd,
nodata = self.shift.nodata,
CPUs = None if self.mp else 1,
progress = self.progress,
v = self.v,
q = self.q)
self.deshift_results = DS.correct_shifts()
return self.deshift_results
......
......@@ -24,10 +24,11 @@ from py_tools_ds.ptds import GeoArray
class COREG_LOCAL(object):
"""See help(COREG_LOCAL) for documentation!"""
def __init__(self, im_ref, im_tgt, grid_res, window_size=(256,256), path_out=None, fmt_out='ENVI', projectDir=None,
r_b4match=1, s_b4match=1, max_iter=5, max_shift=5, footprint_poly_ref=None, footprint_poly_tgt=None,
data_corners_ref=None, data_corners_tgt=None, outFillVal=-9999, nodata=(None, None),
calc_corners=True, binary_ws=True, CPUs=None, progress=True, v=False, q=False, ignore_errors=False):
def __init__(self, im_ref, im_tgt, grid_res, window_size=(256,256), path_out=None, fmt_out='ENVI',
out_crea_options=None, projectDir=None, r_b4match=1, s_b4match=1, max_iter=5, max_shift=5,
footprint_poly_ref=None, footprint_poly_tgt=None, data_corners_ref=None, data_corners_tgt=None,
outFillVal=-9999, nodata=(None, None), calc_corners=True, binary_ws=True, CPUs=None, progress=True,
v=False, q=False, ignore_errors=False):
"""Applies the algorithm to detect spatial shifts to the whole overlap area of the input images. Spatial shifts
are calculated for each point in grid of which the parameters can be adjusted using keyword arguments. Shift
......@@ -43,7 +44,10 @@ class COREG_LOCAL(object):
- if 'auto': /dir/of/im1/<im1>__shifted_to__<im0>.bsq
:param fmt_out(str): raster file format for output file. ignored if path_out is None. can be any GDAL
compatible raster file format (e.g. 'ENVI', 'GeoTIFF'; default: ENVI)
:param projectDir:
:param out_crea_options(list): GDAL creation options for the output image,
e.g. ["QUALITY=80", "REVERSIBLE=YES", "WRITE_METADATA=YES"]
:param projectDir(str): name of a project directory where to store all the output results. If given,
name is inserted into all automatically generated output paths.
:param r_b4match(int): band of reference image to be used for matching (starts with 1; default: 1)
:param s_b4match(int): band of shift image to be used for matching (starts with 1; default: 1)
:param max_iter(int): maximum number of iterations for matching (default: 5)
......@@ -53,9 +57,11 @@ class COREG_LOCAL(object):
299999 6000000))'
:param footprint_poly_tgt(str): footprint polygon of the image to be shifted (WKT string or shapely.geometry.Polygon)
e.g. 'POLYGON ((299999 6000000, 299999 5890200, 409799 5890200, 409799 6000000,
299999 6000000))'
:param data_corners_ref(list): map coordinates of data corners within reference image
:param data_corners_tgt(list): map coordinates of data corners within image to be shifted
299999 6000000))'
:param data_corners_ref(list): map coordinates of data corners within reference image.
ignored if footprint_poly_ref is given.
:param data_corners_tgt(list): map coordinates of data corners within image to be shifted.
ignored if footprint_poly_tgt is given.
:param outFillVal(int): if given the generated geometric quality grid is filled with this value in case
no match could be found during co-registration (default: -9999)
:param nodata(tuple): no data values for reference image and image to be shifted
......@@ -78,31 +84,31 @@ class COREG_LOCAL(object):
if isinstance(im_ref, GeoArray) and nodata is not None: im_ref.nodata = nodata[0]
if isinstance(im_tgt, GeoArray) and nodata is not None: im_tgt.nodata = nodata[1]
self.imref = im_ref if isinstance(im_tgt, GeoArray) else GeoArray(im_ref, nodata=nodata[0])
self.im2shift = im_tgt if isinstance(im_tgt, GeoArray) else GeoArray(im_tgt, nodata=nodata[1])
self.imref = im_ref if isinstance(im_tgt, GeoArray) else GeoArray(im_ref, nodata=nodata[0])
self.im2shift = im_tgt if isinstance(im_tgt, GeoArray) else GeoArray(im_tgt, nodata=nodata[1])
self.imref.progress = progress
self.im2shift.progress = progress
self.imref.q = q
self.im2shift.q = q
self.path_out = path_out # updated by self.set_outpathes
self.fmt_out = fmt_out
self._projectDir = projectDir
self.grid_res = grid_res
self.window_size = window_size
self.max_shift = max_shift
self.max_iter = max_iter
self.calc_corners = calc_corners
self.nodata = nodata
self.outFillVal = outFillVal
self.bin_ws = binary_ws
self.CPUs = CPUs
self.path_verbose_out = '' # TODO
self.v = v
self.q = q if not v else False # overridden by v
self.progress = progress if not q else False # overridden by v
self.ignErr = ignore_errors
self.path_out = path_out # updated by self.set_outpathes
self.fmt_out = fmt_out
self.out_creaOpt = out_crea_options
self._projectDir = projectDir
self.grid_res = grid_res
self.window_size = window_size
self.max_shift = max_shift
self.max_iter = max_iter
self.calc_corners = calc_corners
self.nodata = nodata
self.outFillVal = outFillVal
self.bin_ws = binary_ws
self.CPUs = CPUs
self.path_verbose_out = '' # TODO
self.v = v
self.q = q if not v else False # overridden by v
self.progress = progress if not q else False # overridden by v
self.ignErr = ignore_errors
COREG.__dict__['_set_outpathes'](self, self.imref, self.im2shift)
# make sure that the output directory of coregistered image is the project directory if a project directory is given
......@@ -328,15 +334,16 @@ class COREG_LOCAL(object):
coreg_info['GCPList'] = coreg_info['GCPList'][:max_GCP_count] # TODO should be a random sample
DS = DESHIFTER(self.im2shift, coreg_info,
path_out = self.path_out,
fmt_out = self.fmt_out,
out_gsd = (self.im2shift.xgsd,self.im2shift.ygsd),
align_grids = True,
cliptoextent = cliptoextent,
#clipextent = self.im2shift.box.boxMapYX,
progress = self.progress,
v = self.v,
q = self.q)
path_out = self.path_out,
fmt_out = self.fmt_out,
out_crea_options = self.out_creaOpt,
out_gsd = (self.im2shift.xgsd,self.im2shift.ygsd),
align_grids = True,
cliptoextent = cliptoextent,
#clipextent = self.im2shift.box.boxMapYX,
progress = self.progress,
v = self.v,
q = self.q)
self.deshift_results = DS.correct_shifts()
return self.deshift_results
......
......@@ -36,6 +36,8 @@ class DESHIFTER(object):
- path_out(str): /output/directory/filename for coregistered results
- fmt_out (str): raster file format for output file. ignored if path_out is None. can be any GDAL
compatible raster file format (e.g. 'ENVI', 'GeoTIFF'; default: ENVI)
- out_crea_options(list): GDAL creation options for the output image,
e.g. ["QUALITY=20", "REVERSIBLE=YES", "WRITE_METADATA=YES"]
- band2process (int): The index of the band to be processed within the given array (starts with 1),
default = None (all bands are processed)
- nodata(int, float): no data value of the image to be de-shifted
......@@ -68,18 +70,19 @@ class DESHIFTER(object):
self.ref_prj = coreg_results['reference projection']
# unpack kwargs
self.path_out = kwargs.get('path_out' , None)
self.fmt_out = kwargs.get('fmt_out' , 'ENVI')
self.band2process = kwargs.get('band2process', None) # starts with 1 # FIXME warum?
self.nodata = kwargs.get('nodata' , self.im2shift.nodata)
self.align_grids = kwargs.get('align_grids' , False)
self.rspAlg = kwargs.get('resamp_alg' , 'cubic')
self.cliptoextent = kwargs.get('cliptoextent', True)
self.clipextent = kwargs.get('clipextent' , None)
self.CPUs = kwargs.get('CPUs' , None)
self.v = kwargs.get('v' , False)
self.q = kwargs.get('q' , False) if not self.v else False # overridden by v
self.progress = kwargs.get('progress' , True) if not self.q else False # overridden by q
self.path_out = kwargs.get('path_out' , None)
self.fmt_out = kwargs.get('fmt_out' , 'ENVI')
self.out_creaOpt = kwargs.get('out_crea_options', [])
self.band2process = kwargs.get('band2process' , None) # starts with 1 # FIXME warum?
self.nodata = kwargs.get('nodata' , self.im2shift.nodata)
self.align_grids = kwargs.get('align_grids' , False)
self.rspAlg = kwargs.get('resamp_alg' , 'cubic')
self.cliptoextent = kwargs.get('cliptoextent' , True)
self.clipextent = kwargs.get('clipextent' , None)
self.CPUs = kwargs.get('CPUs' , None)
self.v = kwargs.get('v' , False)
self.q = kwargs.get('q' , False) if not self.v else False # overridden by v
self.progress = kwargs.get('progress' , True) if not self.q else False # overridden by q
self.im2shift.nodata = kwargs.get('nodata', self.im2shift.nodata)
self.im2shift.q = self.q
......@@ -303,7 +306,7 @@ class DESHIFTER(object):
if self.path_out:
out_geoArr = GeoArray(out_arr, out_gt, out_prj, q=self.q)
out_geoArr.nodata = self.nodata # equals self.im2shift.nodata after __init__()
out_geoArr.save(self.path_out,fmt=self.fmt_out)
out_geoArr.save(self.path_out,fmt=self.fmt_out, creationOptions=self.out_creaOpt)
if self.v: print('Time for shift correction: %.2fs' %(time.time()-t_start))
return self.deshift_results
......
......@@ -42,6 +42,7 @@ def run_global_coreg(args):
COREG_obj = COREG(args.path_im0,
args.path_im1,
path_out = args.path_out,
fmt_out = args.fmt_out,
r_b4match = args.br,
s_b4match = args.bs,
wp = args.wp,
......@@ -156,6 +157,11 @@ if __name__ == '__main__':
gloArg('-o', nargs='?', dest='path_out', type=str, default='auto',
help="target path of the coregistered image (default: /dir/of/im1/<im1>__shifted_to__<im0>.bsq)")
gloArg('-fmt_out', nargs='?', type=str, help="raster file format for output file. ignored if path_out is None. can "
"be any GDAL compatible raster file format (e.g. 'ENVI', 'GeoTIFF'; default: ENVI)", default='ENVI')
gloArg('-br', nargs='?', type=int,
help='band of reference image to be used for matching (starts with 1; default: 1)', default=1)
......
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