--- /home/sjplimp/oldpizza/src/gnu.py 2005-09-07 10:13:09.000000000 -0600 +++ /home/sjplimp/pizza/src/gnu.py 2005-09-12 16:39:05.000000000 -0600 @@ -17,9 +17,16 @@ g.plot(a) plot vector A against linear index g.plot(a,b) plot B against A g.plot(a,b,c,d,...) plot B against A, D against C, etc +g.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc + + each plot argument can be a tuple, list, or Numeric vector + mplot loops over range(M,N,S) and create one plot per iteration + last args are same as list of vectors for plot(), e.g. 1, 2, 4 vectors + each plot is made from a portion of the vectors, depending on loop index i + Ith plot is of b[0:i] vs a[0:i], etc + series of plots saved as file0000.eps, file0001.eps, etc + if use xrange(),yrange() then plot axes will be same for all plots - each argument can be a tuple, list, or Numeric vector - g("plot 'file.dat' using 2:3 with lines") execute string in GnuPlot g.enter() enter GnuPlot shell @@ -61,15 +68,14 @@ # History # 8/05, Matt Jones (BYU): original version +# 9/05, Steve Plimpton: added mplot() method # ToDo list # allow choice of JPG or PNG or GIF when saving ? # can this be done from GnuPlot or have to do via ImageMagick convert ? # way to trim EPS plot that is created ? # hide does not work on Mac aqua -# select does not pop window to fron on Mac aqua -# command to allow a plot to be drawn/saved incrementally -# e.g. 50 saved eps files that show plot growing to full data +# select does not pop window to front on Mac aqua # Variables # current = index of current figure (1-N) @@ -78,8 +84,7 @@ # Imports and external programs -from os import popen -import types +import types, os try: from DEFAULTS import PIZZA_GNUPLOT except: PIZZA_GNUPLOT = "gnuplot" @@ -93,7 +98,7 @@ # -------------------------------------------------------------------- def __init__(self): - self.GNUPLOT = popen(PIZZA_GNUPLOT,'w') + self.GNUPLOT = os.popen(PIZZA_GNUPLOT,'w') self.file = "tmp.gnu" self.figures = [] self.select(1) @@ -134,7 +139,28 @@ self.export(file,vectors[i],vectors[i+1]) self.figures[self.current-1].ncurves = len(vectors)/2 self.draw() - + + # -------------------------------------------------------------------- + # create multiple plots from growing vectors, save to numbered files + # don't plot empty vector, create a [0] instead + + def mplot(self,start,stop,skip,file,*vectors): + n = 0 + for i in range(start,stop,skip): + partial_vecs = [] + for vec in vectors: + if i: partial_vecs.append(vec[:i]) + else: partial_vecs.append([0]) + self.plot(*partial_vecs) + + if n < 10: newfile = file + "000" + str(n) + elif n < 100: newfile = file + "00" + str(n) + elif n < 1000: newfile = file + "0" + str(n) + else: newfile = file + str(n) + + self.save(newfile) + n += 1 + # -------------------------------------------------------------------- # write list of equal-length vectors to filename @@ -172,12 +198,18 @@ # -------------------------------------------------------------------- # save plot to file.eps # final re-select will reset terminal - + # do not continue until plot file is written out + # else script could go forward and change data file + # use tmp.done as semaphore to indicate plot is finished + def save(self,file): self.__call__("set terminal postscript enhanced solid lw 2 color portrait") - cmd = 'set output "' + file + '.eps"' + cmd = "set output '%s.eps'" % file self.__call__(cmd) + if os.path.exists("tmp.done"): os.remove("tmp.done") self.draw() + self.__call__("!touch tmp.done") + while not os.path.exists("tmp.done"): continue self.__call__("set output") self.select(self.current) @@ -281,7 +313,7 @@ # draw a plot with all its settings # just return if no files of vectors defined yet - def draw(self): + def draw(self): fig = self.figures[self.current-1] if not fig.ncurves: return @@ -304,7 +336,7 @@ self.__call__(cmd) else: self.__call__("set xr [*:*]") if fig.ylimit: - cmd = 'set yr [' + str(fig.xlimit[0]) + ':' + str(fig.xlimit[1]) + ']' + cmd = 'set yr [' + str(fig.ylimit[0]) + ':' + str(fig.ylimit[1]) + ']' self.__call__(cmd) else: self.__call__("set yr [*:*]") --- /home/sjplimp/oldpizza/src/matlab.py 2005-09-07 10:13:09.000000000 -0600 +++ /home/sjplimp/pizza/src/matlab.py 2005-09-12 15:04:36.000000000 -0600 @@ -17,9 +17,16 @@ m.plot(a) plot vector A against linear index m.plot(a,b) plot B against A m.plot(a,b,c,d,...) plot B against A, D against C, etc +m.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc + + each plot argument can be a tuple, list, or Numeric vector + mplot loops over range(M,N,S) and create one plot per iteration + last args are same as list of vectors for plot(), e.g. 1, 2, 4 vectors + each plot is made from a portion of the vectors, depending on loop index i + Ith plot is of b[0:i] vs a[0:i], etc + series of plots saved as file0000.eps, file0001.eps, etc + if use xrange(),yrange() then plot axes will be same for all plots - each argument can be a tuple, list, or Numeric vector - m("c = a + b") execute string in MatLab m.enter() enter MatLab shell @@ -75,8 +82,6 @@ # allow choice of JPG or PNG or GIF when saving via "saveas" command # have vec/array import/export functions to pass variables between # Pizza.py and MatLab and have them named in MatLab -# command to allow a plot to be drawn/saved incrementally -# e.g. 50 saved eps files that show plot growing to full data # Variables # current = index of current figure (1-N) @@ -88,8 +93,7 @@ # Imports and external programs -from os import popen -import types +import types, os try: from DEFAULTS import PIZZA_MATLAB except: PIZZA_MATLAB = "matlab -nosplash -nodesktop -nojvm" @@ -101,7 +105,7 @@ # -------------------------------------------------------------------- def __init__(self): - self.MATLAB = popen(PIZZA_MATLAB,'w') + self.MATLAB = os.popen(PIZZA_MATLAB,'w') self.file = "tmp.matlab" self.figures = [] self.select(1) @@ -142,7 +146,28 @@ self.export(file,vectors[i],vectors[i+1]) self.figures[self.current-1].ncurves = len(vectors)/2 self.draw() - + + # -------------------------------------------------------------------- + # create multiple plots from growing vectors, save to numbered files + # don't plot empty vector, create a [0] instead + + def mplot(self,start,stop,skip,file,*vectors): + n = 0 + for i in range(start,stop,skip): + partial_vecs = [] + for vec in vectors: + if i: partial_vecs.append(vec[:i]) + else: partial_vecs.append([0]) + self.plot(*partial_vecs) + + if n < 10: newfile = file + "000" + str(n) + elif n < 100: newfile = file + "00" + str(n) + elif n < 1000: newfile = file + "0" + str(n) + else: newfile = file + str(n) + + self.save(newfile) + n += 1 + # -------------------------------------------------------------------- # write list of equal-length vectors to filename @@ -177,10 +202,16 @@ # -------------------------------------------------------------------- # save plot to file.eps + # do not continue until plot file is written out + # else script could go forward and change data file + # use tmp.done as semaphore to indicate plot is finished def save(self,file): + if os.path.exists("tmp.done"): os.remove("tmp.done") cmd = "saveas(gcf,'%s.eps','psc2')" % file self.__call__(cmd) + self.__call__("!touch tmp.done") + while not os.path.exists("tmp.done"): continue # -------------------------------------------------------------------- # restore default attributes by creating a new fig object --- /home/sjplimp/oldpizza/scripts/logview.py 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/scripts/logview.py 2005-09-12 15:51:06.000000000 -0600 @@ -25,7 +25,7 @@ style = argv[1] files = ' '.join(argv[2:]) -lg = logview(files) +lg = log(files) exec "plot = %s()" % style p = plotview(lg,plot) --- /home/sjplimp/oldpizza/src/image.py 2005-09-07 10:13:09.000000000 -0600 +++ /home/sjplimp/pizza/src/image.py 2005-09-12 17:49:31.000000000 -0600 @@ -23,14 +23,26 @@ i.view("*.png *.gif") display thumbnails of matching images view arg is same as constructor arg + +i.convert("image*.svg","new*.png") each SVG file to PNG +i.convert("image*.svg","new*.jpg","-quality 50") 3rd arg is switch +i.convert("image*.png","movie.mpg") all PNGs to MPG movie +i.convert("image*.png","movie.mpg","-resize 128x128") 3rd arg is switch +i.montage("","image*.png","plot*.png","two*.png") image + plot = two +i.montage("-geometry 512x512","i*.png","new.png") 1st arg is switch + + convert with 2 wildcard args loops over 1st set of files to make 2nd set + convert with not all wildcard args will issue single convert command + montage with all wildcard args loops over 1st set of files, + combines with one file from other sets, to make last set of files + montage with not all wildcard args will issue single montage command """ # History # 8/05, Matt Jones (BYU): original version +# 9/05, Steve Plimpton: added convert() and montage() methods # ToDo list -# i.convert("image*gif","-crop 100x200","tmp*png") -# i.join("image*png","plot*gif","","new*png") # Variables @@ -42,6 +54,11 @@ import Pmw import Image,ImageTk +try: from DEFAULTS import PIZZA_CONVERT +except: PIZZA_CONVERT = "convert" +try: from DEFAULTS import PIZZA_MONTAGE +except: PIZZA_MONTAGE = "montage" + # Class definition class image: @@ -111,6 +128,73 @@ if len(files) % ncolumns != 0: rowframe.pack(side=TOP) scroll.pack(side=LEFT) + # -------------------------------------------------------------------- + # wrapper on ImageMagick convert command + + def convert(self,file1,file2,switch=""): + if file1.find('*') < 0 or file2.find('*') < 0: + cmd = "%s %s %s %s" % (PIZZA_CONVERT,switch,file1,file2) + commands.getoutput(cmd) + return + + index = file1.index('*') + pre1 = file1[:index] + post1 = file1[index+1:] + index = file2.index('*') + pre2 = file2[:index] + post2 = file2[index+1:] + expr = "%s(.*)%s" % (pre1,post1) + + filelist = glob.glob(file1) + for file1 in filelist: + middle = re.search(expr,file1).group(1) + file2 = "%s%s%s" % (pre2,middle,post2) + cmd = "%s %s %s %s" % (PIZZA_CONVERT,switch,file1,file2) + print middle, + sys.stdout.flush() + commands.getoutput(cmd) + print + + # -------------------------------------------------------------------- + # wrapper on ImageMagick montage command + + def montage(self,switch,*fileargs): + nsets = len(fileargs) + if nsets < 2: raise StandardError,"montage requires 2 or more file args" + + for i in range(nsets): + if fileargs[i].find('*') < 0: + cmd = "%s %s" % (PIZZA_MONTAGE,switch) + for j in range(nsets): cmd += " %s" % fileargs[j] + commands.getoutput(cmd) + return + + nfiles = len(glob.glob(fileargs[0])) + filesets = [] + for i in range(nsets-1): + filesets.append(glob.glob(fileargs[i])) + if len(filesets[-1]) != nfiles: + raise StandardError,"each montage arg must represent equal # of files" + + index = fileargs[0].index('*') + pre1 = fileargs[0][:index] + post1 = fileargs[0][index+1:] + index = fileargs[-1].index('*') + preN = fileargs[-1][:index] + postN = fileargs[-1][index+1:] + expr = "%s(.*)%s" % (pre1,post1) + + for i in range(nfiles): + cmd = "%s %s" % (PIZZA_MONTAGE,switch) + for j in range(nsets-1): cmd += " %s" % filesets[j][i] + middle = re.search(expr,filesets[0][i]).group(1) + fileN = "%s%s%s" % (preN,middle,postN) + cmd += " %s" % fileN + commands.getoutput(cmd) + print middle, + sys.stdout.flush() + print + # -------------------------------------------------------------------- # thumbnail class --- /home/sjplimp/oldpizza/src/DEFAULTS.py 2005-09-07 10:13:09.000000000 -0600 +++ /home/sjplimp/pizza/src/DEFAULTS.py 2005-09-09 17:46:22.000000000 -0600 @@ -39,11 +39,17 @@ # -------------- +# ImageMagick programs to manipulate image files # DISPLAY = program to view GIF, PNG, SVG files # tools that use it: rasmol, raster, svg +# CONVERT = program to convert one image format to another +# MONTAGE = program to stitch 2 images together +# tools that use it: image # default = display #PIZZA_DISPLAY = "/usr/bin/display" +#PIZZA_CONVERT = "/usr/bin/convert" +#PIZZA_MONTAGE = "/usr/bin/montage" # -------------- --- /home/sjplimp/oldpizza/examples/test_image.py 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/examples/test_image.py 2005-09-12 18:00:04.000000000 -0600 @@ -2,6 +2,8 @@ # requires files/bucky*.png i = image("files/bucky*.png") -i.view("files/bucky*.png") +i.convert("files/bucky*.png","tmp*.gif") +i.montage("","files/bucky*.png","tmp*.gif","tmpnew*.png") +i.view("") print "all done ... type CTRL-D to exit Pizza.py" --- /home/sjplimp/oldpizza/examples/test_gnu.py 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/examples/test_gnu.py 2005-09-12 15:46:22.000000000 -0600 @@ -11,6 +11,7 @@ g.plot(a) g.plot(a,b) g.plot(a,b,b,a) +g.mplot(0,10,2,"tmp",a,b) g.export("tmp.gnu",a,b) --- /home/sjplimp/oldpizza/examples/test_matlab.py 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/examples/test_matlab.py 2005-09-12 15:46:15.000000000 -0600 @@ -9,6 +9,7 @@ m.plot(a) m.plot(a,b) m.plot(a,b,b,a) +m.mplot(0,10,2,"tmp",a,b) m("3*400 - 50") --- /home/sjplimp/oldpizza/doc/image.txt 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/doc/image.txt 2005-09-12 17:24:55.000000000 -0600 @@ -14,19 +14,39 @@ [Description:] -The image tool displays a palette of thumbnail-size images for a set -of files. Each thumbnail can be clicked on to view the full-size -image. Clicking on the full-size image removes it. - -The image constructor creates the GUI for a set of files. The view() -method does the same thing for a new set of files. +The image tool can be used to display image files or convert them to +other formats via the ImageMagick tools (or alternate tools if +specified in the DEFAULTS.py file). + +The image constructor creates a GUI to view a set of image files as a +palette of thumbnail-size images. Each thumbnail can be clicked on to +view the full-size image. Clicking on the full-size image removes it. +The view() method does the same operation for a new set of files. + +The convert() method invokes the ImageMagick "convert" command to +convert an image file to a different format. If both arguments have a +wildcard character, one conversion is done for each file in the 1st +argument to create a file in the 2nd argument, e.g. "convert +image0012.svg new0012.png". If either argument has no wildcard, one +"convert" command is issued using both arguments. This form can be +used to create a movie file, e.g. "convert *.png ligand.mpg". + +The montage() method invokes the ImageMagick "montage" command to +combine 2 image files to create a 3rd. If all 3 arguments have a +wildcard character, one montage is created for each file in the 1st +argument, paired with one file in the 2nd argument, e.g. "montage +image0012.svg plot0012.eps combine0012.png". For this to work, the +1st arguments must each expand to the same number of files. If any of +the 3 arguments does not have a wildcard, one "montage" command is +issued using all 3 arguements. Image files can be in any format (PNG, GIF, JPG, etc) recognized by -the Python Image Library (PIL) installed in your Python. Various -Pizza.py visualization tools (raster, deja, rasmol, etc) create such -image files. If a particular image format fails to load, your PIL -installation was linked without support for that format. Rebuild PIL, -and follow the install instructions included in its top directory. +the Python Image Library (PIL) installed in your Python or by +ImageMagick. Various Pizza.py visualization tools (raster, deja, +rasmol, etc) create such image files. If a particular image format +fails to load, your PIL installation was linked without support for +that format. Rebuild PIL, and follow the install instructions +included in its top directory. [Usage:] @@ -43,10 +63,24 @@ view arg is same as constructor arg :pre +i.convert("image*.svg","new*.png") each SVG file to PNG +i.convert("image*.svg","new*.jpg","-quality 50") 3rd arg is switch +i.convert("image*.png","movie.mpg") all PNGs to MPG movie +i.convert("image*.png","movie.mpg","-resize 128x128") 3rd arg is switch +i.montage("","image*.png","plot*.png","two*.png") image + plot = two +i.montage("-geometry 512x512","i*.png","new.png") 1st arg is switch :pre + + convert with 2 wildcard args loops over 1st set of files to make 2nd set + convert with not all wildcard args will issue single convert command + montage with all wildcard args loops over 1st set of files, + combines with one file from other sets, to make last set of files + montage with not all wildcard args will issue single montage command :pre + [Related tools:] "raster"_raster.html, "rasmol"_rasmol.html, "animate"_animate.html [Prerequisites:] -Python Tkinter, Pmw, and PIL packages. +Python Tkinter, Pmw, and PIL packages. ImageMagick convert and +montage commands or equivalent. --- /home/sjplimp/oldpizza/doc/image.html 2005-09-07 10:13:10.000000000 -0600 +++ /home/sjplimp/pizza/doc/image.html 2005-09-13 09:17:16.000000000 -0600 @@ -17,19 +17,39 @@
Description:
-The image tool displays a palette of thumbnail-size images for a set -of files. Each thumbnail can be clicked on to view the full-size -image. Clicking on the full-size image removes it. -
-The image constructor creates the GUI for a set of files. The view() -method does the same thing for a new set of files. +
The image tool can be used to display image files or convert them to +other formats via the ImageMagick tools (or alternate tools if +specified in the DEFAULTS.py file). +
+The image constructor creates a GUI to view a set of image files as a +palette of thumbnail-size images. Each thumbnail can be clicked on to +view the full-size image. Clicking on the full-size image removes it. +The view() method does the same operation for a new set of files. +
+The convert() method invokes the ImageMagick "convert" command to +convert an image file to a different format. If both arguments have a +wildcard character, one conversion is done for each file in the 1st +argument to create a file in the 2nd argument, e.g. "convert +image0012.svg new0012.png". If either argument has no wildcard, one +"convert" command is issued using both arguments. This form can be +used to create a movie file, e.g. "convert *.png ligand.mpg". +
+The montage() method invokes the ImageMagick "montage" command to +combine 2 image files to create a 3rd. If all 3 arguments have a +wildcard character, one montage is created for each file in the 1st +argument, paired with one file in the 2nd argument, e.g. "montage +image0012.svg plot0012.eps combine0012.png". For this to work, the +1st arguments must each expand to the same number of files. If any of +the 3 arguments does not have a wildcard, one "montage" command is +issued using all 3 arguements.
Image files can be in any format (PNG, GIF, JPG, etc) recognized by -the Python Image Library (PIL) installed in your Python. Various -Pizza.py visualization tools (raster, deja, rasmol, etc) create such -image files. If a particular image format fails to load, your PIL -installation was linked without support for that format. Rebuild PIL, -and follow the install instructions included in its top directory. +the Python Image Library (PIL) installed in your Python or by +ImageMagick. Various Pizza.py visualization tools (raster, deja, +rasmol, etc) create such image files. If a particular image format +fails to load, your PIL installation was linked without support for +that format. Rebuild PIL, and follow the install instructions +included in its top directory.
Usage:
@@ -46,12 +66,26 @@view arg is same as constructor arg+
i.convert("image*.svg","new*.png") each SVG file to PNG
+i.convert("image*.svg","new*.jpg","-quality 50") 3rd arg is switch
+i.convert("image*.png","movie.mpg") all PNGs to MPG movie
+i.convert("image*.png","movie.mpg","-resize 128x128") 3rd arg is switch
+i.montage("","image*.png","plot*.png","two*.png") image + plot = two
+i.montage("-geometry 512x512","i*.png","new.png") 1st arg is switch
+
+convert with 2 wildcard args loops over 1st set of files to make 2nd set + convert with not all wildcard args will issue single convert command + montage with all wildcard args loops over 1st set of files, + combines with one file from other sets, to make last set of files + montage with not all wildcard args will issue single montage command +
Related tools:
Prerequisites:
-Python Tkinter, Pmw, and PIL packages. +
Python Tkinter, Pmw, and PIL packages. ImageMagick convert and +montage commands or equivalent.