Commit 10ca789e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

added check if fttw transformation works

components.CoReg.COREG:
- __init__(): added attribute 'fftw_works'
- _calc_shifted_cross_power_spectrum():
    - added fallback for fourier transformation if output is empty

components.CoReg_local.COREG_LOCAL:
- __init__(): added check if fttw transformation works
- added check_if_fftw_works()

components.Geom_Quality_Grid.Geom_Quality_Grid:
- _get_spatial_shifts(): now sets attribute 'fftw_works' before running shift calculation
- get_CoRegPoints_table(): added 'fftw_works' to kwargs for _get_spatial_shifts()

updated __version__
parent 4acfd791
......@@ -9,7 +9,7 @@ from .components import utilities
from .components import geometry
__author__ = 'Daniel Scheffler'
__version__= '2016-11-25_01'
__version__= '2016-11-30_01'
__all__=['COREG',
'COREG_LOCAL',
......
......@@ -243,6 +243,7 @@ class COREG(object):
self.matchWin = None # set by self._get_image_windows_to_match() => GeoArray
self.otherWin = None # set by self._get_image_windows_to_match() => GeoArray
self.imfft_gsd = None # set by self.get_clip_window_properties()
self.fftw_works = None # set by self._calc_shifted_cross_power_spectrum()
self.fftw_win_size_YX = None # set by calc_shifted_cross_power_spectrum()
self.x_shift_px = None # always in shift image units (image coords) # set by calculate_spatial_shifts()
......@@ -766,9 +767,18 @@ class COREG(object):
PLT.subplot_imshow([in_arr0.astype(np.float32), in_arr1.astype(np.float32)],
['FFTin '+self.ref.title,'FFTin '+self.shift.title], grid=True)
if pyfftw: # if module is installed
if pyfftw and self.fftw_works is not False: # if module is installed and working
fft_arr0 = pyfftw.FFTW(in_arr0,np.empty_like(in_arr0), axes=(0,1))()
fft_arr1 = pyfftw.FFTW(in_arr1,np.empty_like(in_arr1), axes=(0,1))()
# catch empty output arrays (for some reason this happens sometimes..) -> use numpy fft
if self.fftw_works is None and (np.std(fft_arr0)==0 or np.std(fft_arr1)==0):
self.fftw_works = False
# recreate input arrays and use numpy fft as fallback
in_arr0 = im0[ymin:ymax, xmin:xmax].astype(precision)
in_arr1 = im1[ymin:ymax, xmin:xmax].astype(precision)
fft_arr0 = np.fft.fft2(in_arr0)
fft_arr1 = np.fft.fft2(in_arr1)
else:
fft_arr0 = np.fft.fft2(in_arr0)
fft_arr1 = np.fft.fft2(in_arr1)
......
......@@ -9,6 +9,10 @@ try:
import gdal
except ImportError:
from osgeo import gdal
try:
import pyfftw
except ImportError:
pyfftw = None
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
......@@ -189,6 +193,8 @@ class COREG_LOCAL(object):
v = v,
q = q,
ignore_errors = self.ignErr)
if pyfftw:
self.check_if_fftw_works()
# add bad data mask
# (mask is not added during initialization of COREG object in order to avoid bad data area errors there)
......@@ -202,6 +208,17 @@ class COREG_LOCAL(object):
self._success = None # set by self.success property
def check_if_fftw_works(self):
"""Assigns the attribute 'fftw_works' to self.COREG_obj by executing shift calculation once with muted output.
"""
# calculate global shift once in order to check is fftw works
self.COREG_obj.q = True
self.COREG_obj.v = False
self.COREG_obj.calculate_spatial_shifts()
self.COREG_obj.q = self.q
self.COREG_obj.v = self.v
@property
def projectDir(self):
if self._projectDir:
......
......@@ -193,12 +193,14 @@ class Geom_Quality_Grid(object):
@staticmethod
def _get_spatial_shifts(coreg_kwargs):
pointID = coreg_kwargs['pointID']
del coreg_kwargs['pointID']
pointID = coreg_kwargs['pointID']
fftw_works = coreg_kwargs['fftw_works']
del coreg_kwargs['pointID'], coreg_kwargs['fftw_works']
assert global_shared_imref is not None
assert global_shared_im2shift is not None
CR = COREG(global_shared_imref, global_shared_im2shift, multiproc=False, **coreg_kwargs)
CR.fftw_works = fftw_works
CR.calculate_spatial_shifts()
last_err = CR.tracked_errors[-1] if CR.tracked_errors else None
win_sz_y, win_sz_x = CR.matchBox.imDimsYX if CR.matchBox else (None, None)
......@@ -255,6 +257,7 @@ class Geom_Quality_Grid(object):
# get all variations of kwargs for coregistration
get_coreg_kwargs = lambda pID, wp: dict(
pointID = pID,
fftw_works = self.COREG_obj.fftw_works,
wp = wp,
ws = self.COREG_obj.win_size_XY,
resamp_alg_calc = self.rspAlg_calc,
......
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