On 03.04.2009 04:59, santosh panda wrote: > Dear List Members, > > I am using Landsat single band image as input and I want to apply the > equation shown below in the script and write the output to a new raster file. > > 1. The below pasted script works fine without 'cos' term but it fails with > 'cos' term even if I imported python math module. Should I import any other > module so that the script will recognize 'cos' term? > > 2. I want my output data to be in same projection and pixel size as my input > data. What command do I have to use to maintain the projection details and > pixel size? > > 3. My input data is 8 bit and I want my output data also in 8 bit. How can I > maintain the data mode? > > script: > from PIL import Image, ImageMath > import os, math > os.curdir = 'C:/temp' > im = Image.open("testraster.tif") > out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", > im=im, lmax= 30, lmin= 0.37) > out.save("outRaster.tif") > > print 'All done...' > > Traceback (most recent call last): > File "C:\temp\reflectance.py", line 7, in <module> > out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* > 0.0174)))", im=im, lmax= 30, lmin= 0.37) > File "C:\Python25\Lib\site-packages\PIL\ImageMath.py", line 203, in eval > out =__builtin__.eval(expression, args) > File "<string>", line 1, in <module> > NameError: name 'cos' is not defined > > I looked in the Imaginbook and its tutorial section, but didn't find the > exact answer to my questions. I would appreciate any suggestion or help to > solve my problem.
Use either: from math import cos x = cos(1) or import math x = math.cos(1) Abel _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig