bigtools
index
/.automount/ioasun3/root/disk/users/kybic/work/python_volumes/bigtools.py

 Module bigtools provides various auxiliary functions for
doing numerics and image processing with Python 
 
It contains some utility routines, e.g. converting
to/from PIL images, up/down sampling, ...
 
 
Jan Kybic, October 2000
$Id: bigtools.html,v 1.1 2002/08/26 14:11:16 jkybic Exp $

 
Modules
                      
Gnuplot
Image
ImageTk
Tkinter
bigsplines
copy
copy_reg
math
multiarray
new
operator
pickle
string
tempfile
threading
time
types
warnings

 
Classes
                      
ClassBag
ClassBagDispatcher
CombinedBase
Tkinter.Label(Tkinter.Widget)
ImageLabel
Parameters
ViewWindow

 
class ClassBag
            
  
__getattr__(self, name)
 Dispatching routines
__init__(*set, **kw)
 Initialize the ClassBag object

 
class ClassBagDispatcher
            
  
__init__(self, objects, fnname, accumulator)
doCall(*set, **kw)

 
class CombinedBase
            A mixin class for objects derived from several base classes. It
can discover its base classes and call its methods
 
  
callNames(self, prefix, args=(), kwds={})
 calls all methods with names prefix_BaseName, where BaseName is
taken from self.basenames. Returns a list of all results.
getBaseNames(self)
 Finds out base names (as strings) at puts them into
self.basenames. If a getNickname_<BaseName> method exists,
the nickname returned is used insted

 
class ImageLabel(Tkinter.Label)
            
  
_Misc__winfo_getint = __winfo_getint(self, x) from Tkinter.Misc
_Misc__winfo_parseitem = __winfo_parseitem(self, t) from Tkinter.Misc
__getitem__ = cget(self, key) from Tkinter.Misc
__init__(self, master, im)
__setitem__(self, key, value) from Tkinter.Misc
__str__(self) from Tkinter.Misc
_bind(self, what, sequence, func, add, needcleanup=1) from Tkinter.Misc
_displayof(self, displayof) from Tkinter.Misc
_do(self, name, args=()) from Tkinter.BaseWidget
_getboolean(self, string) from Tkinter.Misc
_getdoubles(self, string) from Tkinter.Misc
_getints(self, string) from Tkinter.Misc
_grid_configure(self, command, index, cnf, kw) from Tkinter.Misc
_nametowidget = nametowidget(self, name) from Tkinter.Misc
_options(self, cnf, kw=None) from Tkinter.Misc
_register(self, func, subst=None, needcleanup=1) from Tkinter.Misc
_report_exception(self) from Tkinter.Misc
_root(self) from Tkinter.Misc
_setup(self, master, cnf) from Tkinter.BaseWidget
_substitute(self, *args) from Tkinter.Misc
after(self, ms, func=None, *args) from Tkinter.Misc
after_cancel(self, id) from Tkinter.Misc
after_idle(self, func, *args) from Tkinter.Misc
bbox = grid_bbox(self, column=None, row=None, col2=None, row2=None) from Tkinter.Misc
bell(self, displayof=0) from Tkinter.Misc
bind(self, sequence=None, func=None, add=None) from Tkinter.Misc
bind_all(self, sequence=None, func=None, add=None) from Tkinter.Misc
bind_class(self, className, sequence=None, func=None, add=None) from Tkinter.Misc
bindtags(self, tagList=None) from Tkinter.Misc
cget(self, key) from Tkinter.Misc
clipboard_append(self, string, **kw) from Tkinter.Misc
clipboard_clear(self, **kw) from Tkinter.Misc
colormodel(self, value=None) from Tkinter.Misc
columnconfigure = grid_columnconfigure(self, index, cnf={}, **kw) from Tkinter.Misc
config = configure(self, cnf=None, **kw) from Tkinter.Misc
configure(self, cnf=None, **kw) from Tkinter.Misc
deletecommand(self, name) from Tkinter.Misc
destroy(self) from Tkinter.BaseWidget
event_add(self, virtual, *sequences) from Tkinter.Misc
event_delete(self, virtual, *sequences) from Tkinter.Misc
event_generate(self, sequence, **kw) from Tkinter.Misc
event_info(self, virtual=None) from Tkinter.Misc
focus = focus_set(self) from Tkinter.Misc
focus_displayof(self) from Tkinter.Misc
focus_force(self) from Tkinter.Misc
focus_get(self) from Tkinter.Misc
focus_lastfor(self) from Tkinter.Misc
focus_set(self) from Tkinter.Misc
forget = pack_forget(self) from Tkinter.Pack
getboolean(self, s) from Tkinter.Misc
getvar(self, name='PY_VAR') from Tkinter.Misc
grab_current(self) from Tkinter.Misc
grab_release(self) from Tkinter.Misc
grab_set(self) from Tkinter.Misc
grab_set_global(self) from Tkinter.Misc
grab_status(self) from Tkinter.Misc
grid = grid_configure(self, cnf={}, **kw) from Tkinter.Grid
grid_bbox(self, column=None, row=None, col2=None, row2=None) from Tkinter.Misc
grid_columnconfigure(self, index, cnf={}, **kw) from Tkinter.Misc
grid_configure(self, cnf={}, **kw) from Tkinter.Grid
grid_forget(self) from Tkinter.Grid
grid_info(self) from Tkinter.Grid
grid_location(self, x, y) from Tkinter.Grid
grid_propagate(self, flag=['_noarg_']) from Tkinter.Misc
grid_remove(self) from Tkinter.Grid
grid_rowconfigure(self, index, cnf={}, **kw) from Tkinter.Misc
grid_size(self) from Tkinter.Misc
grid_slaves(self, row=None, column=None) from Tkinter.Misc
image_names(self) from Tkinter.Misc
image_types(self) from Tkinter.Misc
info = pack_info(self) from Tkinter.Pack
keys(self) from Tkinter.Misc
lift = tkraise(self, aboveThis=None) from Tkinter.Misc
location = grid_location(self, x, y) from Tkinter.Grid
lower(self, belowThis=None) from Tkinter.Misc
mainloop(self, n=0) from Tkinter.Misc
nametowidget(self, name) from Tkinter.Misc
option_add(self, pattern, value, priority=None) from Tkinter.Misc
option_clear(self) from Tkinter.Misc
option_get(self, name, className) from Tkinter.Misc
option_readfile(self, fileName, priority=None) from Tkinter.Misc
pack = pack_configure(self, cnf={}, **kw) from Tkinter.Pack
pack_configure(self, cnf={}, **kw) from Tkinter.Pack
pack_forget(self) from Tkinter.Pack
pack_info(self) from Tkinter.Pack
pack_propagate(self, flag=['_noarg_']) from Tkinter.Misc
pack_slaves(self) from Tkinter.Misc
place = place_configure(self, cnf={}, **kw) from Tkinter.Place
place_configure(self, cnf={}, **kw) from Tkinter.Place
place_forget(self) from Tkinter.Place
place_info(self) from Tkinter.Place
place_slaves(self) from Tkinter.Misc
propagate = pack_propagate(self, flag=['_noarg_']) from Tkinter.Misc
quit(self) from Tkinter.Misc
register = _register(self, func, subst=None, needcleanup=1) from Tkinter.Misc
rowconfigure = grid_rowconfigure(self, index, cnf={}, **kw) from Tkinter.Misc
selection_clear(self, **kw) from Tkinter.Misc
selection_get(self, **kw) from Tkinter.Misc
selection_handle(self, command, **kw) from Tkinter.Misc
selection_own(self, **kw) from Tkinter.Misc
selection_own_get(self, **kw) from Tkinter.Misc
send(self, interp, cmd, *args) from Tkinter.Misc
setvar(self, name='PY_VAR', value='1') from Tkinter.Misc
size = grid_size(self) from Tkinter.Misc
slaves = pack_slaves(self) from Tkinter.Misc
tk_bisque(self) from Tkinter.Misc
tk_focusFollowsMouse(self) from Tkinter.Misc
tk_focusNext(self) from Tkinter.Misc
tk_focusPrev(self) from Tkinter.Misc
tk_menuBar(self, *args) from Tkinter.Misc
tk_setPalette(self, *args, **kw) from Tkinter.Misc
tk_strictMotif(self, boolean=None) from Tkinter.Misc
tkraise(self, aboveThis=None) from Tkinter.Misc
unbind(self, sequence, funcid=None) from Tkinter.Misc
unbind_all(self, sequence) from Tkinter.Misc
unbind_class(self, className, sequence) from Tkinter.Misc
update(self) from Tkinter.Misc
update_idletasks(self) from Tkinter.Misc
wait_variable(self, name='PY_VAR') from Tkinter.Misc
wait_visibility(self, window=None) from Tkinter.Misc
wait_window(self, window=None) from Tkinter.Misc
waitvar = wait_variable(self, name='PY_VAR') from Tkinter.Misc
winfo_atom(self, name, displayof=0) from Tkinter.Misc
winfo_atomname(self, id, displayof=0) from Tkinter.Misc
winfo_cells(self) from Tkinter.Misc
winfo_children(self) from Tkinter.Misc
winfo_class(self) from Tkinter.Misc
winfo_colormapfull(self) from Tkinter.Misc
winfo_containing(self, rootX, rootY, displayof=0) from Tkinter.Misc
winfo_depth(self) from Tkinter.Misc
winfo_exists(self) from Tkinter.Misc
winfo_fpixels(self, number) from Tkinter.Misc
winfo_geometry(self) from Tkinter.Misc
winfo_height(self) from Tkinter.Misc
winfo_id(self) from Tkinter.Misc
winfo_interps(self, displayof=0) from Tkinter.Misc
winfo_ismapped(self) from Tkinter.Misc
winfo_manager(self) from Tkinter.Misc
winfo_name(self) from Tkinter.Misc
winfo_parent(self) from Tkinter.Misc
winfo_pathname(self, id, displayof=0) from Tkinter.Misc
winfo_pixels(self, number) from Tkinter.Misc
winfo_pointerx(self) from Tkinter.Misc
winfo_pointerxy(self) from Tkinter.Misc
winfo_pointery(self) from Tkinter.Misc
winfo_reqheight(self) from Tkinter.Misc
winfo_reqwidth(self) from Tkinter.Misc
winfo_rgb(self, color) from Tkinter.Misc
winfo_rootx(self) from Tkinter.Misc
winfo_rooty(self) from Tkinter.Misc
winfo_screen(self) from Tkinter.Misc
winfo_screencells(self) from Tkinter.Misc
winfo_screendepth(self) from Tkinter.Misc
winfo_screenheight(self) from Tkinter.Misc
winfo_screenmmheight(self) from Tkinter.Misc
winfo_screenmmwidth(self) from Tkinter.Misc
winfo_screenvisual(self) from Tkinter.Misc
winfo_screenwidth(self) from Tkinter.Misc
winfo_server(self) from Tkinter.Misc
winfo_toplevel(self) from Tkinter.Misc
winfo_viewable(self) from Tkinter.Misc
winfo_visual(self) from Tkinter.Misc
winfo_visualid(self) from Tkinter.Misc
winfo_visualsavailable(self, includeids=0) from Tkinter.Misc
winfo_vrootheight(self) from Tkinter.Misc
winfo_vrootwidth(self) from Tkinter.Misc
winfo_vrootx(self) from Tkinter.Misc
winfo_vrooty(self) from Tkinter.Misc
winfo_width(self) from Tkinter.Misc
winfo_x(self) from Tkinter.Misc
winfo_y(self) from Tkinter.Misc

 
class Parameters
            An object of class Parameters is a collection of parameters.
Its instantiated as:
 
p=Parameters(x)
 
where x can be either another object of type Parameters,
or a dictionary, such as
 
p=Parameters({'tol':1e-6, 'startx':(0,0,0)})
 
Additional keyword parameters to the constructor include:
 
default: a dictionary with default values
keep:    a list of parameter names to keep. If given, all other
         parameters are discarded, except those given by
         'default'
discard: list of parameters to discard. This is done after
         'default' and 'keep' are processed.
override: these parameters are added as the last step
 
Once the object is instantiated, the values can be read by
as 'p.tol' or 'p.startx', they should not be changed this way
(although this cannot be enforced for types passed by reference)
For invalid names, KeyError is raised.
 
Policy: parameter values should be never changed.
 
Warning: Each subordinate module makes
 
  
__getattr__(self, name)
__init__(self, p, default=None, keep=None, discard=[], override=None)
isdef(self, name)
 Returns true if a parameter 'name' is defined

 
class ViewWindow
            
  
__del__(self)
__init__(self)
getRoot(self)

 
Functions
                      
ArrayToImage(a)
 converts array to greyscale or color image
ImageToArray(i)
 converts greyscale or color image to (byte) array
addmirrored(x, n)
 Take a 1D vector x and add n points at both ends, respecting the mirror
on boundary conditions.
aexp(x)
 Works just like an ordinary exp, except it returns zero for
large negative arguments, not OverflowError :-(
 
no longer necessary in Python 2.1
alltrue = reduce(...)
applyforallrows(x, oper, ndim=None)
 Apply an operation for all rows of x. The operation oper
should take a 1D vector and return another 1D vector.
 
If passdim is true, the 'oper' is passed a keyword argument
'ndim' giving the dimension being processed.
array(...)
array(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode.  If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence.  If copy is zero and sequence is already an array, a reference will be returned.  If savespace is nonzero, the new array will maintain its precision in operations.
array2ppm(image)
basisv(shape, i, type='d')
 Return an  array of 'type' of shape 'shape', with all zeros except
one at index i.
calchist(x, h=1.0, minx=None, maxx=None)
 Given an array (or vector x), returns pair of vectors (t,cnt)
suitable for showing the histogram of x with plot. h is the spacing
and minx/maxx the lower and upper limits
choose(...)
choose(a, (b1,b2,...))
cross_correlate(...)
cross_correlate(a,v)
cumproduct = accumulate(...)
cumsum = accumulate(...)
dotrange(x, y, s, square=0)
 Compute the dot-product of x and y, taking advantage of the
fact that the only non-zero elements of y are in range s,
as returned by rangetoslice(r). If square==1, the second argument
is squared.
downsample(x, n)
 Downsample 1D array x by a factor of n, starting at the first
element
float_array(m)
 Makes a floating array out of m, accepting just about anything
Taken from Gnuplot.utils by
Michael Haggerty <mhagger@alum.mit.edu>
foldmirrored(x, n)
 Cut n points at the beginning and end of x, foldover and add
to the original vector
fromstring(...)
fromstring(string, count=None, typecode='l') returns a new 1d array initialized from the raw binary data in string.  If count is not equal to None, the new array will have count elements, otherwise it's size is determined by the size of string.
getindices(x=None, shape=None)
 Return a list of all indices of an array x. Usage:
 
for i in getindices(x): # print all elements
    print x[i]
int_array(m)
 Makes an int array out of m, accepting just about anything
keyboard()
 Debugging function. Stops the program  and lets you execute
commands from the keyboard until empty line is given.
maddmirrored(x, n)
 Apply addmirrored to a multidimensional x, extending
it in all directions
makeClassBag(classes=[], accumulators={})
 makeClassBag permits to create a bag object containing several
client objects. When a message is sent to the bag object, it is
resent to all clients. The response from clients is aggregated
using a user supplied accumulating functions.
 
Instantiation:
classbag=makeClassBag([classA,classB,classC],
             accumulators={'result': operator.add})
 
b=classbag(1,2,3) # instantiates all clients
 
Calling b.fun(1,2) then returns: classA(1,2)+classB(1,2)
Default operator is returning the list of all results.
 
Note that changing data members of the client objects is not supported
makeGrid(size, step=(20, 20))
 Returns an array with a grid pattern
maxelement(x)
 Returns the value of the largest element of x, regardless of the
dimensionality.
mdownsample(x, n)
 Downsample a multidimensional array x by a factor n[i] in
direction i. Uses downsample.
mfold(k, n)
 Calculates the real index corresponding to k mirrored for vector
length n
mfoldv(k, n)
 As mfold but accepts sequences as k and n
minelement(x)
 Returns the value of the smallest element of x, regardless of the
dimensionality.
mupsample(x, n)
 Upsample a multidimensional array x by a factor n[i] in
direction i. Uses upsample.
plot(*set, **kw)
 Plot function going through points x,y (Numeric arrays or other).
Only y can be given.
 
Usage: g=plot(y)  or g=plot(x,y)
 
Keyword parameters: title, gnupl, with, xlabel, ylabel, cmd
 
Returns the Gnuplot handle
printtofile(img, filename, size=None, scale='auto', resample=0)
 Save to a file a 2D array img, possibly scaled to 'size'
which should be a tuple (xsize,ysize). The filename should
already contain the extension. If no scaling is used (scale=None),
the range is 0..255
 
If img is 3D the first coordinate is assumed to be the color index,
i.e. img[0] is red, img[1] green, and img[2] is blue
 
resample defines the interpolation method, it can be NEAREST, BILINEAR,
or BICUBIC, see Image.py
prodall(x)
 Returns the product of all the elements of x, regardless of the
dimensionality.
product = reduce(...)
rangeisempty(r)
 Given a range r, return true if it is empty
rangesintersect(r, s)
 Given two ranges r,s
in the form (array(l1,l2,l3,...),array(h1,h2,h3,...)),
return their intersection
rangetoslice(r)
 Given the range as returned by the splinerange
in the form (array(l1,l2,l3,...),array(h1,h2,h3,...)),
return a list of slice objects to be used for slicing
repeat(...)
repeat(a, n, axis=0)
reshape(...)
reshape(a, (d1, d2, ..., dn)).  Change the shape of a to be an n-dimensional array with dimensions given by d1...dn.  One dimension is allowed to be None.  This dimension will be set to whatever value will make the size of the new array equal the size of the old one.  Note: the size specified for the new array must be exactly equal to the size of the  old one or an error will occur.  This returns a completely new array with the data of the old one copied.  Use a.shape=(...) for no data copying.
save_ppm(ppm, fname=None)
# --------------------------------------------------------------------
searchsorted = binarysearch(...)
binarysearch(a,v)
showContours(img, cont, size=None, scale='auto', title='showDif')
 Shows superposed contours cont in red over an image img in gray.
The two images must be of the same size.
Contours are plotted if bigger than 0.
Returns an image suitable for bigtools.view.
showDif(img1, img2, size=None)
 Shows a difference between two images. The two images must be
of the same size. Currently we put one in red and the other one in the
green channels. Returns an image suitable for bigtools.view.
showImgWithLandmarks(img, lnd, size=None, scale='auto', title='Landmarks', lndsize=2)
 Returns an image suitable for bigtools.view
    with superimposed landmarks in red.
WARNING: We do not check if the landmarks are too close to borders.
sometrue = reduce(...)
sum = reduce(...)
sumall(x)
 Returns the sum of all the elements of x, regardless of the
dimensionality.
sumforalldims(x, oper)
 Call operation on all transposes of x
and return the sum of the results
sumforallrows(x, oper)
 Call oper on all rows (including higher dimensions) of x
and return the sum of the results
superdiagonal(x)
 returns a superdiagonal of a matrix x, i.e. another matrix
y(i)=x(i,i), where i can be a vector index
take(...)
take(a, indices, axis=0).  Selects the elements in indices from array a along the given axis.
tensorprod(v)
 Calculates a tensor product of all elements of v, v is a list
of vectors
test_ClassBag()
test_CombinedBase()
test_Parameters()
timeop(oper, comm='Operation')
try_tensor()
upsample(x, n)
 Upsample 1D array x by a factor of n, starting at the first
element and filling gaps with zero. Returns a vector of length
len(x)*n
vectorsumforalldims(x, oper)
 Call operation (vector->vector) on all rows of all transposes of x
and return the sum of the results
view(img, size=None, scale='auto', title='view', resample=0)
 View a 2D array img as image, possibly scaled to 'size'
which should be a tuple (xsize,ysize). If no scaling is used (scale=None),
the range is 0..255
 
If img is 3D the first coordinate is assumed to be the color index,
i.e. img[0] is red, img[1] green, and img[2] is blue
 
It returns a handle to a ViewWindow object. When it is destroyed, the
window disappears.
 
resample defines the interpolation method, it can be NEAREST, BILINEAR,
or BICUBIC, see Image.py
viewimg(img, title='view')
 View a PIL image object img. It
returns a handle to a ViewWindow object. When it is destroyed, the
window disappears.
zeros(...)
zeros((d1,...,dn),typecode,savespace) will return a new array of shape (d1,...,dn) and type typecode (default 'l') with all it's entries initialized to zero.  If savespace (default 0) is nonzero the array will be a spacesaver array.

 
Constants
                      ArrayType = <type 'array'>
Complex = 'D'
Complex0 = 'F'
Complex16 = 'F'
Complex32 = 'F'
Complex64 = 'D'
Complex8 = 'F'
Float = 'd'
Float0 = 'f'
Float16 = 'f'
Float32 = 'f'
Float64 = 'd'
Float8 = 'f'
Int = 'l'
Int0 = '1'
Int16 = 's'
Int32 = 'i'
Int8 = '1'
LittleEndian = 1
PrecisionError = 'PrecisionError'
PyObject = 'O'
UnsignedInt8 = 'b'
arraytype = <type 'array'>
e = 2.7182818284590451
pi = 3.1415926535897931