[Matrix-SIG] fromfunction broke in LLNL10??
Les Schaffer
godzilla@netmeg.net (Les Schaffer)
Wed, 24 Mar 1999 11:11:00 -0500 (EST)
I just was using some old code with a Numeric.fromfunction, and now
its broke, after upgrade to LLNL10 from 9.
did something change in Numeric.py?
Traceback (innermost last):
File "/usr/lib/python1.5/lib-tk/Tkinter.py", line 761, in __call__
return apply(self.func, args)
File "testImage.py", line 58, in update
ra = fromfunction(self.func, (101, 101))
File "/usr/lib/python1.5/site-packages/Numerical/Numeric.py", line 156, in fromfunction
return apply(function, tuple(indices(dimensions)))
File "/usr/lib/python1.5/site-packages/Numerical/Numeric.py", line 149, in indices
tmp = ones(dimensions, typecode)
File "/usr/lib/python1.5/site-packages/Numerical/Numeric.py", line 306, in ones
return zeros(shape, typecode)+array(1, typecode)
TypeError: argument 2: expected string, None found
this code worked flawlessly before 10:
===============================
#!/usr/bin/python
from Tkinter import *
from ImageTk import PhotoImage
import Image
from Numeric import *
def normalize(a):
a = array(a, copy=1)
a = (a - min(a.flat))/(max(a.flat) - min(a.flat))
return a
def ArrayToImage(a, height=200, scale=1):
if len(a.shape) == 2:
a = (normalize(a)*254).astype('b')
i = Image.new("L", (a.shape[1], a.shape[0]), color=255)
i.fromstring(a.tostring())
elif len(a.shape) == 1:
a = 1-normalize(a)
a = array(a*height).astype('i')
i = Image.new("L", (a.shape[0], height), color=255)
id = ImageDraw.ImageDraw(i)
id.setink(0)
def map_xandy_to_xy(x, y):
import _imaging
return _imaging.path(ravel(transpose(array((x, y)))).tolist())
id.line(xy=map_xandy_to_xy(arange(a.shape[0]), a))
if scale != 1:
i = i.resize((i.size[0]*scale, i.size[1]*scale))
return i
def ImageToArray(i):
a = fromstring(i.tostring(), 'b')
a.shape = i.im.size[1], i.im.size[0]
return a
class MatrixDisplay:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red",
command=frame.quit)
self.button.pack(side=TOP)
self.test_B = Button(frame, text="Update", command=self.update)
self.test_B.pack(side=TOP)
self.img = Image.new("L",(100,100))
self.photo = PhotoImage(image=self.img)
self.canvas = Canvas(frame, width=100, height=100)
self.canvas.create_image(0, 0, anchor=NW, image=self.photo)
self.canvas.pack()
def update(self):
ra = fromfunction(self.func, (101, 101))
self.img = ArrayToImage(ra)
#self.photo = PhotoImage(self.img)
self.photo.paste(self.img)
self.canvas.create_image(0, 0, anchor=NW, image=self.photo)
self.canvas.update()
def func(self, i,j):
return cos( 4*2*3.1415926*i / 100. ) * cos( 4*2*3.1415926*(j / 100. ))
root = Tk()
app = MatrixDisplay(root)
root.mainloop()
==============================
--
____ Les Schaffer ___| --->> Engineering R&D <<---
Theoretical & Applied Mechanics | Designspring, Inc.
Center for Radiophysics & Space Research | http://www.designspring.com/
Cornell Univ. schaffer@tam.cornell.edu | les@designspring.com