[gdal-dev] module of a complex dataset

Frank Warmerdam warmerdam at pobox.com
Tue Sep 2 09:18:28 EDT 2008


Antonio Valentino wrote:
> Is it possible to extract the module (and possibly the phase) of a
> complex dataset using GDAL utilities or playing with the virtual driver?
> 
> If I use 
> 
>   $ gdal_translate -ot Float64 src_dataset dst_dataset
> 
> on a complex src_dataset it seems to extract the real part.

Antonio,

I am not aware of any way to accomplish this with the virtual driver
or the commandline utilities. But I have added a small sample script doing
this with numpy and python if you would be interested in working from that.

   http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/samples/magphase.py

import gdal
import gdalnumeric
try:
     import numpy
except:
     import Numeric as numpy


src_ds = gdal.Open('complex.tif')
xsize = src_ds.RasterXSize
ysize = src_ds.RasterYSize

src_image = src_ds.GetRasterBand(1).ReadAsArray()
mag_image = pow(numpy.real(src_image)*numpy.real(src_image) \
                 + numpy.imag(src_image)*numpy.imag(src_image),0.5)
gdalnumeric.SaveArray( mag_image, 'magnitude.tif' )

phase_image = numpy.angle(src_image)
gdalnumeric.SaveArray( phase_image, 'phase.tif' )


I was also impressed to discover today that the numpy manual is now
finally free.

   http://www.tramy.us/numpybook.pdf

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list