Esempio n. 1
0
def view(arr,title="",autolevel=1):
    "show Numeric array"
    global root,saveimgs

    if not title:
        # automatic titles are the line of code used to call view()
        caller=sys._getframe(1)
        lines,startnum=inspect.getsourcelines(caller)
        title=lines[caller.f_lineno-startnum]

    # autoscale brightness
    arr=abs(arr) # take magnitude of complex values
    if autolevel:
        maxval=MLab.max(MLab.max(arr)) # find maximum
        if maxval>0:
            arr=arr*255/maxval # scale so 255 is the max
    arr=arr.astype(Numeric.UnsignedInt8)

    size=arr.shape[1],arr.shape[0]
    im=Image.fromstring("L",size,arr.tostring())
  
    #im=im.resize((500,500))
    
    image = ImageTk.PhotoImage(im)
    saveimgs.append(image)

    f=tk.Frame(root, relief='raised',bd=2)
    tk.Label(f,text=title).pack(side='bottom')
    x = tk.Label(f, image=image)
    x.pack(side='top')
    f.pack(side='left')
Esempio n. 2
0
def plot_matrix(z, r_x=0, r_y=0, filename=0, colorcode=0):

    if filename:
        print "Saving to file not supported."

    import MLab, Tkinter, ImageTk
        
    # Scale z and find appropriate colormap.
    
    zmax = MLab.max(MLab.max(z))
    zmin = MLab.min(MLab.min(z))

    if (zmin < 0) and (0 < zmax) :
        colormap = create_bipolar_colormap()
        zmax = MLab.max([-zmin, zmax])
        z += zmax
        z *= (len(colormap)-1)/(2*zmax)
    else:
        if colorcode == whiteblack:
            colormap = create_white_black_colormap()
        elif colorcode == blackwhite:
            colormap = create_black_white_colormap()    
        else:
            colormap = create_unipolar_colormap()

        z -= zmin
        if (zmax != zmin):
            z *= (len(colormap)-1)/(zmax-zmin)
            
    # Put picture on canvas.

    root = Tkinter.Tk()  
    pic = _plot_scaled_matrix(root, colormap, z, r_x, r_y)
    pic.pack()
    root.mainloop()
Esempio n. 3
0
 def MLab_minmax(self, x):
     """Use MLab's min/max functions repeatedly."""
     import MLab
     xmin = x; xmax = x
     for i in iseq(len(x.shape)-1,0,-1):
         xmin = MLab.min(xmin, i)
         xmax = MLab.max(xmax, i)
     return xmin, xmax
Esempio n. 4
0
def phasormovie(z, r_x=0, r_y=0, filename=0):

    if filename:
        print "Saving to file not supported."
        
    import MLab, Tkinter
    
    # Make movie memory.
    
    movie    = []
    frames   = 16
    colormap = create_bipolar_colormap()

    # Scale factors for z.

    zmax = MLab.max(MLab.max(abs(z)))
    z_scale = (len(colormap)-1)/(2*zmax)

    # Calculate each frame.
    
    root = Tkinter.Tk()    
    for Nr in range(0,frames):
        pic = _plot_scaled_matrix(root, colormap, ((z+zmax)*z_scale).real,
                                  r_x, r_y)
        movie.append(pic)
        z *= exp(2j*pi/frames)
        
    # Close window procedure.

    stop = [0]    
    def callback(): stop[0] = 1 
    root.protocol("WM_DELETE_WINDOW", callback)
            
    # Animate picture.

    while not stop[0]:
        for x in range(frames):
            if stop[0]: break
            movie[x].pack()
            root.update()
            root.after(int(100))
            movie[x].forget()

    root.destroy()  
Esempio n. 5
0
def plot_matrix(z, r_x=0, r_y=0, filename=0, colorcode=0):

    if filename:
        print "Saving to file not supported."
    
    matlab.put('z', z)
    if r_x:
        matlab.put('x', r_x)
    if r_y:
        matlab.put('y', r_y)

    if not r_x and not r_y:
        matlab("imagesc(z)")
    else:
        matlab("imagesc(x,y,z)")
   
    if (MLab.min(MLab.min(z)) < 0) and (0 < MLab.max(MLab.max(z))):
        create_bipolar_color_map()
    else:
        matlab("colormap jet")
        
    matlab("axis equal")
    matlab("axis off")
    matlab("shading flat")