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

Added missing dependency. Some PEP8 editing. Updated version info.

parent 3b09778f
Pipeline #959 failed with stages
in 6 minutes and 54 seconds
# -*- coding: utf-8 -*-
__author__='Daniel Scheffler'
import collections
import time
......@@ -19,10 +18,13 @@ from py_tools_ds.geo.projection import prj_equal
from py_tools_ds.geo.raster.reproject import warp_ndarray
from py_tools_ds.numeric.vector import find_nearest
__author__ = 'Daniel Scheffler'
_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,
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'}
'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!"""
......@@ -88,7 +90,7 @@ class DESHIFTER(object):
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 why?
self.band2process = self.band2process-1 if self.band2process is not None else None # internally handled as band index
self.band2process = self.band2process-1 if self.band2process is not None else None # internally handled as band index
self.nodata = kwargs.get('nodata' , self.im2shift.nodata)
self.align_grids = kwargs.get('align_grids' , False)
self.min_points_local_corr = kwargs.get('min_points_local_corr', 5)
......@@ -105,7 +107,6 @@ class DESHIFTER(object):
self.shift_prj = self.im2shift.projection
self.shift_gt = list(self.im2shift.geotransform)
# in case of local shift correction and local coreg results contain less points than min_points_local_corr:
# force global correction based on mean X/Y shifts
if 'GCPList' in coreg_results and len(coreg_results['GCPList']) < self.min_points_local_corr:
......@@ -116,7 +117,6 @@ class DESHIFTER(object):
self.GCPList = None
coreg_results['updated map info'] = coreg_results['updated map info means']
# in case of global shift correction -> the updated map info from coreg_results already has the final map info
# BUT: this will updated in correct_shifts() if clipextent is given or warping is needed
if not self.GCPList:
......@@ -129,17 +129,15 @@ class DESHIFTER(object):
self.out_grid = self._get_out_grid() # needs self.ref_grid, self.im2shift
self.out_gsd = [abs(self.out_grid[0][1]-self.out_grid[0][0]), abs(self.out_grid[1][1]-self.out_grid[1][0])] # xgsd, ygsd
# assertions
assert self.rspAlg in _dict_rspAlg_rsp_Int.keys(), \
"'%s' is not a supported resampling algorithm." %self.rspAlg
"'%s' is not a supported resampling algorithm." % self.rspAlg
if self.band2process is not None:
assert self.im2shift.bands-1 >= self.band2process >= 0, "The %s '%s' has %s %s. So 'band2process' must be " \
assert self.im2shift.bands-1 >= self.band2process >= 0, "The %s '%s' has %s %s. So 'band2process' must be "\
"%s%s. Got %s." % (self.im2shift.__class__.__name__, self.im2shift.basename, self.im2shift.bands,
'bands' if self.im2shift.bands > 1 else 'band', 'between 1 and ' if self.im2shift.bands > 1 else '',
self.im2shift.bands, self.band2process+1)
# set defaults for general class attributes
self.is_shifted = False # this is not included in COREG.coreg_info
self.is_resampled = False # this is not included in COREG.coreg_info
......@@ -147,7 +145,6 @@ class DESHIFTER(object):
self.arr_shifted = None # set by self.correct_shifts
self.GeoArray_shifted = None # set by self.correct_shifts
def _get_out_grid(self):
# parse given params
out_gsd = self.init_kwargs.get('out_gsd' , None)
......@@ -197,15 +194,14 @@ class DESHIFTER(object):
return out_grid
@property
def warping_needed(self):
"""Returns True if image warping is needed in consideration of the input parameters of DESHIFTER."""
assert self.out_grid, 'Output grid must be calculated before.'
equal_prj = prj_equal(self.ref_prj, self.shift_prj)
return False if (equal_prj and not self.GCPList and is_coord_grid_equal(self.updated_gt, *self.out_grid)) else True
return \
False if (equal_prj and not self.GCPList and is_coord_grid_equal(self.updated_gt, *self.out_grid)) else True
def _are_grids_alignable(self, in_xgsd, in_ygsd, out_xgsd, out_ygsd):
"""Checks if the input image pixel grid is alignable to the output grid.
......@@ -231,7 +227,6 @@ class DESHIFTER(object):
return self._grids_alignable
def _get_out_extent(self):
if self.clipextent is None:
# no clip extent has been given
......@@ -251,7 +246,6 @@ class DESHIFTER(object):
ymax = find_nearest(self.out_grid[1], ymax, roundAlg='off', extrapolate=True)
return xmin, ymin, xmax, ymax
def correct_shifts(self):
# type: () -> collections.OrderedDict
......@@ -296,7 +290,7 @@ class DESHIFTER(object):
if self.path_out:
out_geoArr.save(self.path_out,fmt=self.fmt_out)
else: # FIXME equal_prj==False ist noch NICHT implementiert
else: # FIXME equal_prj==False ist noch NICHT implementiert
"""RESAMPLING NEEDED"""
# if self.warpAlg=='GDAL_cmd':
# warnings.warn('This method has not been tested in its current state!')
......@@ -390,11 +384,9 @@ class DESHIFTER(object):
'was %s. Output geotransform is %s.' % (str(self.out_grid), str(self.updated_gt)))
# TODO to be continued (extent, map info, ...)
if self.v: print('Time for shift correction: %.2fs' %(time.time()-t_start))
return self.deshift_results
@property
def deshift_results(self):
deshift_results = collections.OrderedDict()
......@@ -409,7 +401,6 @@ class DESHIFTER(object):
return deshift_results
def deshift_image_using_coreg_info(im2shift, coreg_results, path_out=None, fmt_out='ENVI', q=False):
"""Corrects a geometrically distorted image using previously calculated coregistration info. This function can be
used for example to corrects spatial shifts of mask files using the same transformation parameters that have been
......
This diff is collapsed.
......@@ -2,11 +2,6 @@
"""Top-level package for arosics."""
__author__ = """Daniel Scheffler"""
__email__ = 'daniel.scheffler@gfz-potsdam.de'
__version__ = '0.4.22'
__versionalias__ = '2017-09-05_02'
import warnings
from arosics.CoReg import COREG
......@@ -14,6 +9,11 @@ from arosics.CoReg_local import COREG_LOCAL
from arosics.DeShifter import DESHIFTER
from arosics.Tie_Point_Grid import Tie_Point_Grid
__author__ = """Daniel Scheffler"""
__email__ = 'daniel.scheffler@gfz-potsdam.de'
__version__ = '0.4.23'
__versionalias__ = '2017-09-05_03'
# check optional dependencies
try:
......
# -*- coding: utf-8 -*-
import ctypes
import multiprocessing
import os
......
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
......
# -*- coding: utf-8 -*-
import numpy as np
def get_image_tileborders(target_tileSize,shape_fullArr):
rows,cols = shape_fullArr[:2]
row_bounds=[0]
while row_bounds[-1]+target_tileSize[0] < rows:
row_bounds.append(row_bounds[-1] + target_tileSize[0]-1)
def get_image_tileborders(target_tileSize, shape_fullArr):
rows, cols = shape_fullArr[:2]
row_bounds = [0]
while row_bounds[-1] + target_tileSize[0] < rows:
row_bounds.append(row_bounds[-1] + target_tileSize[0] - 1)
row_bounds.append(row_bounds[-2] + target_tileSize[0])
else:
row_bounds.append(rows-1)
row_bounds.append(rows - 1)
col_bounds=[0]
while col_bounds[-1]+target_tileSize[1] < cols:
col_bounds.append(col_bounds[-1] + target_tileSize[1]-1)
col_bounds = [0]
while col_bounds[-1] + target_tileSize[1] < cols:
col_bounds.append(col_bounds[-1] + target_tileSize[1] - 1)
col_bounds.append(col_bounds[-2] + target_tileSize[1])
else:
col_bounds.append(cols-1)
return [[tuple([row_bounds[r], row_bounds[r+1]]), tuple([col_bounds[c], col_bounds[c+1]])] \
col_bounds.append(cols - 1)
return [[tuple([row_bounds[r], row_bounds[r + 1]]), tuple([col_bounds[c], col_bounds[c + 1]])]
for r in range(0, len(row_bounds), 2) for c in range(0, len(col_bounds), 2)]
def cornerPoints_to_listOfXYPairs(corYX,out_shape,out_resXY,shrinkSize=None):
def cornerPoints_to_listOfXYPairs(corYX, out_shape, out_resXY, shrinkSize=None):
"""
:param corYX: list of XY pairs in the order UL,UR,LR,LL
"""
Xarr = np.zeros(out_shape,np.float64)
Xarr[None,:] = np.arange(corYX[0][1],corYX[1][1],out_resXY[0])
Xarr = Xarr
Yarr = np.zeros(list(reversed(out_shape)),np.float64)
out_resY = out_resXY[1] if corYX[0][0]<corYX[2][0] else -out_resXY[1]
Yarr[None,:] = np.arange(corYX[0][0],corYX[2][0],out_resY)
Yarr = Yarr.T
Xarr = np.zeros(out_shape, np.float64)
Xarr[None, :] = np.arange(corYX[0][1], corYX[1][1], out_resXY[0])
Xarr = Xarr
Yarr = np.zeros(list(reversed(out_shape)), np.float64)
out_resY = out_resXY[1] if corYX[0][0] < corYX[2][0] else -out_resXY[1]
Yarr[None, :] = np.arange(corYX[0][0], corYX[2][0], out_resY)
Yarr = Yarr.T
Xarr = Xarr[shrinkSize:-shrinkSize,shrinkSize:-shrinkSize] if shrinkSize else Xarr
Yarr = Yarr[shrinkSize:-shrinkSize,shrinkSize:-shrinkSize] if shrinkSize else Yarr
Xarr = Xarr[shrinkSize:-shrinkSize, shrinkSize:-shrinkSize] if shrinkSize else Xarr
Yarr = Yarr[shrinkSize:-shrinkSize, shrinkSize:-shrinkSize] if shrinkSize else Yarr
XYarr = np.empty((Xarr.size,2),np.float64)
XYarr[:,0] = Xarr.flat
XYarr[:,1] = Yarr.flat
XYarr = np.empty((Xarr.size, 2), np.float64)
XYarr[:, 0] = Xarr.flat
XYarr[:, 1] = Yarr.flat
return XYarr
def get_coord_grid(ULxy,LRxy,out_resXY):
X_vec = np.arange(ULxy[0],LRxy[0],out_resXY[0])
Y_vec = np.arange(ULxy[1],LRxy[1],out_resXY[1])
return np.meshgrid(X_vec,Y_vec)
def get_coord_grid(ULxy, LRxy, out_resXY):
X_vec = np.arange(ULxy[0], LRxy[0], out_resXY[0])
Y_vec = np.arange(ULxy[1], LRxy[1], out_resXY[1])
return np.meshgrid(X_vec, Y_vec)
def convertGdalNumpyDataType(dType):
"""convertGdalNumpyDataType
......@@ -73,5 +78,5 @@ def convertGdalNumpyDataType(dType):
outdType = "Float32"
print(">>> Warning: %s is converted to GDAL_Type 'Float32'\n" % dType)
else:
raise Exception('GEOP.convertGdalNumpyDataType: Unexpected input data type %s.' %dType)
raise Exception('GEOP.convertGdalNumpyDataType: Unexpected input data type %s.' % dType)
return outdType
# -*- coding: utf-8 -*-
from __future__ import (division, print_function, absolute_import, unicode_literals) #unicode_literals cause GDAL not to work properly
__author__ = "Daniel Scheffler"
# unicode_literals cause GDAL not to work properly
from __future__ import (division, print_function, absolute_import, unicode_literals)
import time
import sys
......@@ -10,9 +9,10 @@ import argparse
from arosics import COREG, COREG_LOCAL, __version__
__author__ = "Daniel Scheffler"
#sub-command functions
# sub-command functions
def run_global_coreg(args):
COREG_obj = COREG(args.path_ref,
args.path_tgt,
......@@ -45,7 +45,7 @@ def run_global_coreg(args):
COREG_obj.correct_shifts()
#sub-command functions
# sub-command functions
def run_local_coreg(args):
CRL = COREG_LOCAL(args.path_ref,
args.path_tgt,
......
......@@ -13,7 +13,7 @@ with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = ['numpy', 'gdal', 'shapely', 'scikit-image', 'matplotlib', 'geopandas', 'spectral', 'geoarray>=0.5.8',
'py_tools_ds>=0.4.2', 'plotly'
'py_tools_ds>=0.4.2', 'plotly', 'cmocean'
# '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; \
......@@ -27,7 +27,7 @@ test_requirements = ['coverage']
setup(
name='arosics',
version='0.4.22',
version='0.4.23',
description="An Automated and Robust Open-Source Image Co-Registration Software for Multi-Sensor Satellite Data",
long_description=readme + '\n\n' + history,
author="Daniel Scheffler",
......
......@@ -14,7 +14,6 @@ from arosics import COREG_LOCAL
from geoarray import GeoArray
class COREG_LOCAL_init(unittest.TestCase):
"""Test case on object initialization of COREG_LOCAL."""
......@@ -56,7 +55,6 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
if os.path.isdir(dir_out):
shutil.rmtree(dir_out)
def test_calculation_of_tie_point_grid(self):
# get instance of COREG_LOCAL object
CRL = COREG_LOCAL(self.ref_path, self.tgt_path, **self.coreg_kwargs)
......@@ -65,7 +63,7 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
TPG = CRL.CoRegPoints_table
# test tie point grid visualization
#CRL.view_CoRegPoints() # only works if basemap is installed
# CRL.view_CoRegPoints() # only works if basemap is installed
# test shift correction and output writer
CRL.correct_shifts()
......@@ -74,11 +72,11 @@ class CompleteWorkflow_INTER1_S2A_S2A(unittest.TestCase):
'Output of local co-registration has not been written.')
#if __name__ == '__main__':
# unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
# if __name__ == '__main__':
# unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
#
# suite = unittest.TestLoader().loadTestsFromTestCase(eval("CompleteWorkflow_INTER1_S2A_S2A"))
# suite = unittest.TestLoader().loadTestsFromTestCase(eval("CompleteWorkflow_INTER1_S2A_S2A"))
# alltests = unittest.TestSuite(suite)
#
# # Part 2: Saving the results of each testsuite and the query for the job.status in individual variables.
# testResult = unittest.TextTestRunner(verbosity=2).run(alltests)
# # Part 2: Saving the results of each testsuite and the query for the job.status in individual variables.
# testResult = unittest.TextTestRunner(verbosity=2).run(alltests)
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