[scitools] 2 new revisions pushed by h...@simula.no on 2013-11-03 08:29 GMT

0 views
Skip to first unread message

scit...@googlecode.com

unread,
Nov 3, 2013, 3:29:22 AM11/3/13
to scitoo...@googlegroups.com
2 new revisions:

Revision: 90be2df56742
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Wed Oct 16 23:18:33 2013 UTC
Log: Fix of StringFunction.__str__ shortcoming.
http://code.google.com/p/scitools/source/detail?r=90be2df56742

Revision: 5ccc87cbe0cb
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Sun Nov 3 08:28:57 2013 UTC
Log: Fixed bug in bar plot. Arose after we added automated markers in
color...
http://code.google.com/p/scitools/source/detail?r=5ccc87cbe0cb

==============================================================================
Revision: 90be2df56742
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Wed Oct 16 23:18:33 2013 UTC
Log: Fix of StringFunction.__str__ shortcoming.
http://code.google.com/p/scitools/source/detail?r=90be2df56742

Modified:
/lib/scitools/StringFunction.py
/lib/scitools/easyviz/movie.py

=======================================
--- /lib/scitools/StringFunction.py Wed Oct 2 05:16:18 2013 UTC
+++ /lib/scitools/StringFunction.py Wed Oct 16 23:18:33 2013 UTC
@@ -352,12 +352,12 @@

# Substitute parameter names by their numerical values.
# Start with the most complicated parameter names
- # (this algorithm may fail).
+ # Improvement by Eigil Skjaelveland
<eig...@student.matnat.uio.no>.
prm_names = list(self._prms.keys())
- prm_names.sort(lambda a, b: cmp(len(a), len(b)))
- prm_names.reverse()
+ prm_names.sort(key=len, reverse=1)
for name in prm_names:
- s = s.replace(name, str(self._prms[name]))
+ s = re.sub(r'([^a-z_])' + name + '([^a-z_])',
+ r'\1{0}\2', s).format(str(self._prms[name]))
return s

def __repr__(self):
@@ -633,8 +633,8 @@
def __str__(self):
s = self._f
# Substitute parameter names by their numerical values.
- # Start with the most complicated parameter names
- # (this algorithm may fail).
+ # Start with the most complicated parameter names.
+ # Improvements by Eigil Skjaelveland.

# first remove indep. variables possibly inserted in self._prms
# by the self.__call__ method:
@@ -643,10 +643,10 @@
except:
pass
prm_names = list(self._prms.keys())
- prm_names.sort(lambda a, b: cmp(len(a), len(b)))
- prm_names.reverse()
+ prm_names.sort(key=len, reverse=1)
for name in prm_names:
- s = s.replace(name, str(self._prms[name]))
+ s = re.sub(r'([^a-z_])' + name + '([^a-z_])',
+ r'\1{0}\2', s).format(str(self._prms[name]))
return s

def __repr__(self):
=======================================
--- /lib/scitools/easyviz/movie.py Mon Jun 24 03:58:21 2013 UTC
+++ /lib/scitools/easyviz/movie.py Wed Oct 16 23:18:33 2013 UTC
@@ -738,9 +738,150 @@
size = None
return size

+
+
def html_movie(plotfiles, interval_ms=300, width=800, height=600,
casename='movie'):
"""
+ Takes a list plotfiles which should be for example of the form::
+
+ ['frame00.png', 'frame01.png', ... ]
+
+ where each string should be the name of an image file and they should
be
+ in the proper order for viewing as an animation.
+
+ The result is html text strings that incorporate javascript to
+ loop through the plots one after another. The html text also features
+ buttons for controlling the movie.
+ The parameter iterval_ms is the time interval between loading
+ successive images and is in milliseconds.
+
+ The width and height parameters do not seem to have any effect
+ for reasons not understood.
+
+ The following strings are returned: header, javascript code, form
+ with movie and buttons, and footer. Concatenating these strings
+ and dumping to an html file yields a kind of movie file to be
+ viewed in a browser. The images variable in the javascript code
+ is unique for each movie, because it is annotated by the casename
+ string, so several such javascript sections can be used in the
+ same html file. If casename is just 'movie', the name of the plot
+ files is used as casename.
+
+ This function is based on code written by R. J. LeVeque, based on
+ a template from Alan McIntyre.
+ """
+ # Alternative method:
+ #
http://stackoverflow.com/questions/9486961/animated-image-with-javascript
+ import os
+ if not isinstance(plotfiles, (tuple,list)):
+ raise TypeError('html_movie: plotfiles=%s of wrong type %s' %
+ (str(plotfiles), type(plotfiles)))
+ # Check that the plot files really exist
+ missing_files = [fname for fname in plotfiles if not
os.path.isfile(fname)]
+ if missing_files:
+ raise ValueError('Missing plot files: %s' %
str(missing_files)[1:-1])
+
+ filestem, ext = os.path.splitext(plotfiles[0])
+ if ext == '.png' or ext == '.jpg' or ext == '.jpeg' or ext == 'gif':
+ pass
+ else:
+ raise ValueError('Plotfiles (%s, ...) must be PNG, JPEG, or GIF
files with '\
+ 'extension .png, .jpg/.jpeg, or .gif' %
plotfiles[0])
+ if casename == 'movie' : # default
+ # Make a valid variable name for Javascript out of filestem
+ filestem = re.sub(r'_?\d+\.', '', filestem)
+ filestem = filestem.replace('/', '_')
+ for c in """ ,.[]{}\\"'^&%$#@!=|?""":
+ filestem = filestem.replace(c, '')
+ casename = filestem
+
+ header = """\
+<html>
+<head>
+</head>
+<body>
+"""
+ no_images = len(plotfiles)
+ jscode = """
+<script language="Javascript">
+<!---
+var num_images_%(casename)s = %(no_images)d;
+var img_width_%(casename)s = %(width)d;
+var img_height_%(casename)s = %(height)d;
+var interval_%(casename)s = %(interval_ms)d;
+var images_%(casename)s = new Array();
+
+function preload_images_%(casename)s()
+{
+ t = document.getElementById("progress");
+""" % vars()
+
+ i = 0
+ for fname in plotfiles:
+ jscode += """
+ t.innerHTML = "Preloading image ";
+ images_%(casename)s[%(i)s] = new Image(img_width_%(casename)s,
img_height_%(casename)s);
+ images_%(casename)s[%(i)s].src = "%(fname)s";
+ """ % vars()
+ i = i+1
+ jscode += """
+ t.innerHTML = "";
+}
+
+function tick_%(casename)s()
+{
+ if (frame_%(casename)s > num_images_%(casename)s - 1)
+ frame_%(casename)s = 0;
+
+ document.name_%(casename)s.src =
images_%(casename)s[frame_%(casename)s].src;
+ frame_%(casename)s += 1;
+ tt = setTimeout("tick_%(casename)s()", interval_%(casename)s);
+}
+
+function startup_%(casename)s()
+{
+ preload_images_%(casename)s();
+ frame_%(casename)s = 0;
+ setTimeout("tick_%(casename)s()", interval_%(casename)s);
+}
+
+function stopit_%(casename)s()
+{ clearTimeout(tt); }
+
+function restart_%(casename)s()
+{ tt = setTimeout("tick_%(casename)s()", interval_%(casename)s); }
+
+function slower_%(casename)s()
+{ interval_%(casename)s = interval_%(casename)s/0.7; }
+
+function faster_%(casename)s()
+{ interval_%(casename)s = interval_%(casename)s*0.7; }
+
+// --->
+</script>
+""" % vars()
+ plotfile0 = plotfiles[0]
+ form = """
+<form>
+&nbsp;
+<input type="button" value="Start movie" onClick="startup_%(casename)s()">
+<input type="button" value="Pause movie" onClick="stopit_%(casename)s()">
+<input type="button" value="Restart movie"
onClick="restart_%(casename)s()">
+&nbsp;
+<input type="button" value="Slower" onClick="slower_%(casename)s()">
+<input type="button" value="Faster" onClick="faster_%(casename)s()">
+</form>
+
+<p><div ID="progress"></div></p>
+<img src="%(plotfile0)s" name="name_%(casename)s" border=2/>
+""" % vars()
+ footer = '\n</body>\n</html>\n'
+ return header, jscode, form, footer
+
+def old_html_movie(plotfiles, interval_ms=300, width=800, height=600,
+ casename='movie'):
+ """
Takes a list plotfiles which should be for example of the form:
['frame00.png', 'frame01.png', ... ]
where each string should be the name of an image file and they should
be
@@ -866,7 +1007,6 @@
footer = '\n</body>\n</html>\n'
return header, jscode, form, footer

-
def movie(input_files, **kwargs):
"""
Make a movie from a series of image files.

==============================================================================
Revision: 5ccc87cbe0cb
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Sun Nov 3 08:28:57 2013 UTC
Log: Fixed bug in bar plot. Arose after we added automated markers in
color plots.
http://code.google.com/p/scitools/source/detail?r=5ccc87cbe0cb

Modified:
/lib/scitools/Heaviside.py
/lib/scitools/easyviz/common.py
/lib/scitools/easyviz/gnuplot_.py
/setup.py

=======================================
--- /lib/scitools/Heaviside.py Wed Oct 2 05:16:18 2013 UTC
+++ /lib/scitools/Heaviside.py Sun Nov 3 08:28:57 2013 UTC
@@ -45,7 +45,7 @@
"""

def __init__(self, eps=0):
- """`eps` is the smoothing parameter (0: exact Heaviside
function."""
+ """`eps` is the smoothing parameter (0: exact Heaviside
function)."""
self.eps = eps

def __call__(self, x):
=======================================
--- /lib/scitools/easyviz/common.py Wed Oct 2 05:16:18 2013 UTC
+++ /lib/scitools/easyviz/common.py Sun Nov 3 08:28:57 2013 UTC
@@ -271,8 +271,9 @@
try:
return self._prop[prm_name]
except:
- raise KeyError('%s.getp: no parameter with name "%s"' % \
- (self.__class__.__name__, prm_name))
+ #raise KeyError('%s.getp: no parameter with name "%s"' % \
+ # (self.__class__.__name__, prm_name))
+ return None

def setformat(self, format):
"""
=======================================
--- /lib/scitools/easyviz/gnuplot_.py Mon Jul 15 09:20:22 2013 UTC
+++ /lib/scitools/easyviz/gnuplot_.py Sun Nov 3 08:28:57 2013 UTC
@@ -658,8 +658,12 @@
# Add marker (if not too many points) so that curves in
# png/eps can be distinguised in black-and-white
#if len(item.getp('xdata')) <= 61: # fixed in _add_line
- marker = self._markers[PlotProperties._colors2markers[
- item.getp('linecolor')]]
+
+ if item.getp('linecolor'):
+ marker = self._markers[PlotProperties._colors2markers[
+ item.getp('linecolor')]]
+ else:
+ marker = None
style = 'lines'
width = 1 # only PNG needs thicker lines and that is set in
hardcopy (savefig)

=======================================
--- /setup.py Wed Jun 13 10:33:57 2012 UTC
+++ /setup.py Sun Nov 3 08:28:57 2013 UTC
@@ -25,7 +25,6 @@
scripts.extend(batch_files)

# NOTE: now we force matplotlib as default backend if it is installed:
-# (previously gnuplot was always default)
try:
import matplotlib
default_easyviz_backend = 'matplotlib'
Reply all
Reply to author
Forward
0 new messages