Skip to content

Commit

Permalink
Merge branch 'pixelfunctions-integration' into enhance-complex-datase…
Browse files Browse the repository at this point in the history
…ts-with-pf
  • Loading branch information
jmichel-otb committed Jul 7, 2016
2 parents 2162049 + de301c3 commit db55680
Showing 1 changed file with 63 additions and 54 deletions.
117 changes: 63 additions & 54 deletions autotest/gdrivers/pixfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
###############################################################################

import sys
import numpy

try:
import numpy
numpy_available = True
except ImportError:
numpy_available = False

from osgeo import gdal

sys.path.append('../pymod')
Expand All @@ -55,7 +61,7 @@ def pixfun_real_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata.real):
if numpy_available and not numpy.alltrue(data == refdata.real):
return 'fail'

return 'success'
Expand All @@ -80,7 +86,7 @@ def pixfun_real_r():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata.real):
if numpy_available and not numpy.alltrue(data == refdata.real):
return 'fail'

return 'success'
Expand All @@ -105,7 +111,7 @@ def pixfun_imag_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata.imag):
if numpy_available and not numpy.alltrue(data == refdata.imag):
return 'fail'

return 'success'
Expand All @@ -123,7 +129,7 @@ def pixfun_imag_r():
return 'fail'
data = ds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == 0):
if numpy_available and not numpy.alltrue(data == 0):
return 'fail'

return 'success'
Expand All @@ -148,7 +154,7 @@ def pixfun_complex():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.allclose(data, refdata + 1j * refdata):
if numpy_available and not numpy.allclose(data, refdata + 1j * refdata):
return 'fail'

return 'success'
Expand All @@ -173,7 +179,7 @@ def pixfun_mod_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.abs(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.abs(refdata)):
return 'fail'

return 'success'
Expand All @@ -198,7 +204,7 @@ def pixfun_mod_r():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.abs(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.abs(refdata)):
return 'fail'

return 'success'
Expand All @@ -225,7 +231,7 @@ def pixfun_phase_c():
refdata = refdata.astype('complex128')

#if not numpy.allclose(data, numpy.arctan2(refdata.imag, refdata.real)):
if not numpy.alltrue(data == numpy.arctan2(refdata.imag, refdata.real)):
if numpy_available and not numpy.alltrue(data == numpy.arctan2(refdata.imag, refdata.real)):
return 'fail'

return 'success'
Expand All @@ -250,7 +256,7 @@ def pixfun_phase_r():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.arctan2(0, refdata)):
if numpy_available and not numpy.alltrue(data == numpy.arctan2(0, refdata)):
return 'fail'

return 'success'
Expand All @@ -275,7 +281,7 @@ def pixfun_conj_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.conj(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.conj(refdata)):
return 'fail'

return 'success'
Expand All @@ -300,7 +306,7 @@ def pixfun_conj_r():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.conj(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.conj(refdata)):
return 'fail'

return 'success'
Expand All @@ -318,17 +324,18 @@ def pixfun_sum_r():
return 'fail'
data = ds.GetRasterBand(1).ReadAsArray()

refdata = numpy.zeros(data.shape, 'float')
for reffilename in ('data/uint16.tif', 'data/int32.tif',
'data/float32.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
if numpy_available:
refdata = numpy.zeros(data.shape, 'float')
for reffilename in ('data/uint16.tif', 'data/int32.tif',
'data/float32.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
return 'fail'
refdata += refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata):
return 'fail'
refdata += refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata):
return 'fail'

return 'success'

Expand All @@ -345,17 +352,18 @@ def pixfun_sum_c():
return 'fail'
data = ds.GetRasterBand(1).ReadAsArray()

refdata = numpy.zeros(data.shape, 'complex')
for reffilename in ('data/uint16.tif', 'data/cint_sar.tif',
'data/cfloat64.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
return 'fail'
if numpy_available:
refdata = numpy.zeros(data.shape, 'complex')
for reffilename in ('data/uint16.tif', 'data/cint_sar.tif',
'data/cfloat64.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
return 'fail'
refdata += refds.GetRasterBand(1).ReadAsArray(0, 0, 5, 6)

if not numpy.alltrue(data == refdata):
return 'fail'
if not numpy.alltrue(data == refdata):
return 'fail'

return 'success'

Expand Down Expand Up @@ -386,7 +394,7 @@ def pixfun_diff_r():
return 'fail'
refdata2 = refds.GetRasterBand(1).ReadAsArray(10, 10, 5, 6)

if not numpy.alltrue(data == refdata1-refdata2):
if numpy_available and not numpy.alltrue(data == refdata1-refdata2):
return 'fail'

return 'success'
Expand Down Expand Up @@ -418,7 +426,7 @@ def pixfun_diff_c():
return 'fail'
refdata2 = refds.GetRasterBand(1).ReadAsArray(0, 0, 5, 6)

if not numpy.alltrue(data == refdata1-refdata2):
if numpy_available and not numpy.alltrue(data == refdata1-refdata2):
return 'fail'

return 'success'
Expand All @@ -436,17 +444,18 @@ def pixfun_mul_r():
return 'fail'
data = ds.GetRasterBand(1).ReadAsArray()

refdata = numpy.ones(data.shape, 'float')
for reffilename in ('data/uint16.tif', 'data/int32.tif',
'data/float32.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
return 'fail'
if numpy_available:
refdata = numpy.ones(data.shape, 'float')
for reffilename in ('data/uint16.tif', 'data/int32.tif',
'data/float32.tif'):
refds = gdal.Open(reffilename)
if refds is None:
gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename)
return 'fail'
refdata *= refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata):
return 'fail'
if not numpy.alltrue(data == refdata):
return 'fail'

return 'success'

Expand All @@ -470,7 +479,7 @@ def pixfun_mul_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata*refdata):
if numpy_available and not numpy.alltrue(data == refdata*refdata):
return 'fail'

return 'success'
Expand All @@ -495,7 +504,7 @@ def pixfun_cmul_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == refdata*refdata.conj()):
if numpy_available and not numpy.alltrue(data == refdata*refdata.conj()):
return 'fail'

return 'success'
Expand Down Expand Up @@ -529,7 +538,7 @@ def pixfun_cmul_r():
refdata2 = refds.GetRasterBand(1).ReadAsArray()
refdata2 = refdata2.astype('float64')

if not numpy.alltrue(data == refdata1 * refdata2.conj()):
if numpy_available and not numpy.alltrue(data == refdata1 * refdata2.conj()):
return 'fail'

return 'success'
Expand All @@ -555,7 +564,7 @@ def pixfun_inv_r():
refdata = refds.GetRasterBand(1).ReadAsArray()
refdata = refdata.astype('float64')

if not numpy.alltrue(data == 1./refdata):
if numpy_available and not numpy.alltrue(data == 1./refdata):
return 'fail'

return 'success'
Expand All @@ -582,9 +591,9 @@ def pixfun_inv_c():
refdata = refdata.astype('complex')
delta = data - 1./refdata

if not numpy.alltrue(abs(delta.real) < 1e-13):
if numpy_available and not numpy.alltrue(abs(delta.real) < 1e-13):
return 'fail'
if not numpy.alltrue(abs(delta.imag) < 1e-13):
if numpy_available and not numpy.alltrue(abs(delta.imag) < 1e-13):
return 'fail'

return 'success'
Expand All @@ -609,7 +618,7 @@ def pixfun_intensity_c():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == (refdata*refdata.conj()).real):
if numpy_available and not numpy.alltrue(data == (refdata*refdata.conj()).real):
return 'fail'

return 'success'
Expand All @@ -634,7 +643,7 @@ def pixfun_intensity_r():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == (refdata*refdata.conj()).real):
if numpy_available and not numpy.alltrue(data == (refdata*refdata.conj()).real):
return 'fail'

return 'success'
Expand All @@ -659,7 +668,7 @@ def pixfun_sqrt():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.sqrt(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.sqrt(refdata)):
return 'fail'

return 'success'
Expand All @@ -684,7 +693,7 @@ def pixfun_log10():
return 'fail'
refdata = refds.GetRasterBand(1).ReadAsArray()

if not numpy.alltrue(data == numpy.log10(refdata)):
if numpy_available and not numpy.alltrue(data == numpy.log10(refdata)):
return 'fail'

return 'success'
Expand All @@ -710,7 +719,7 @@ def pixfun_dB2amp():
refdata = refds.GetRasterBand(1).ReadAsArray()

#if not numpy.alltrue(data == 10.**(refdata/20.)):
if not numpy.allclose(data, 10.**(refdata/20.)):
if numpy_available and not numpy.allclose(data, 10.**(refdata/20.)):
return 'fail'

return 'success'
Expand All @@ -737,7 +746,7 @@ def pixfun_dB2pow():
refdata = refdata.astype('float64')

#if not numpy.allclose(data, 10.**(refdata/10.)):
if not numpy.alltrue(data == 10.**(refdata/10.)):
if numpy_available and not numpy.alltrue(data == 10.**(refdata/10.)):
return 'fail'

return 'success'
Expand Down

0 comments on commit db55680

Please sign in to comment.