[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah/experiment metahtest.py
From: |
Jean-Philippe Aumasson |
Subject: |
[oMetah-devel] ometah/experiment metahtest.py |
Date: |
Tue, 07 Jun 2005 06:09:40 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Jean-Philippe Aumasson <address@hidden> 05/06/07 10:09:39
Modified files:
experiment : metahtest.py
Log message:
* code cleaned, orientedobjectisation...
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/metahtest.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: ometah/experiment/metahtest.py
diff -u ometah/experiment/metahtest.py:1.5 ometah/experiment/metahtest.py:1.6
--- ometah/experiment/metahtest.py:1.5 Tue Jun 7 08:33:49 2005
+++ ometah/experiment/metahtest.py Tue Jun 7 10:09:39 2005
@@ -30,26 +30,32 @@
--------------------------------------------------------
TODO
-
+------
histogramme 3D ?? transfo Xdim en 1 ou 2 dim...
fonctions 'plotAutrechosequedistribution (listOfPoints)'
Exceptions ! Errors in log !
+Nommer fichiers en fx du problème...
+
+Organisation fichiers (arborescencec ? noms fichiers ? clé/ID unique ? ..?)
+
+/----
NOTES
fonction math :
import math
import Numeric
-
pour XML parsing :
http://pyxml.sourceforge.net/
http://communaute.openesub.org/softs/externe/cvs/chora/co.php/enki/openNewRapport.py?r=1.7
sortie parsing : liste d'instances de Point
+executer commandes R : r('cmd...')
+
"""
import os
@@ -60,33 +66,32 @@
import datetime
+
+
def setPostscriptOutput(filename):
""" set a postscript output file """
r.postscript(filename, paper='letter')
def setBitmapOutput(filename):
""" set a bitmap (png) output file """
- r.bitmap(filename, res=100)
+ r.bitmap(filename, res=150)
def datedFileName(name, extension):
""" return a string of today's date + given string """
s = datetime.date.today().isoformat()
return name + s + extension
-def log(filename, string):
- """ will write log of current job in a *.log file with date,
- pb name, output files... """
- fd = open(filename, 'a')
- fd.write(string)
- fd.close()
-
class Interface:
""" the main interface with ometah output """
-
+
+ # if true, log events in *.log file
+ LOG_ON = 0
+
def __init__(self, args):
""" constructor, from command line arguments """
- self.__argv = [''] + args[1:]
+ self.__argv = [''] + args[1:]
+ self.__logfile = datedFileName("", ".log")
def execOmetah(self, path):
""" execute ometah with given arguments,
@@ -105,13 +110,18 @@
for x in plist:
vlist.append(float(x.value))
r.hist(vlist, breaks, col='green', main='Distribution', xlab='Values')
+ r.lines(r.density(vlist, bw=0.3), col='red')
- def plotValues(self, plist):
+ def plotValues(self, plist, dimension):
""" plot values """
- vlist = []
- for x in plist:
- vlist.append(float(x.value))
- r.plot(vlist, type='o', col='red', main='Values evolution',
xlab='Points', ylab='Value')
+ if dimension == 1 :
+ vlist = []
+ for x in plist:
+ vlist.append(float(x.value))
+ r.plot(vlist, type='o', col='red', main='Values evolution',
xlab='Points', ylab='Value')
+ else :
+ if dimension == 2 :
+ self.log('ERROR : dimension 2')
def getProblemName():
@@ -126,6 +136,18 @@
def getIterations():
return self.__iterations
+ def log(self, string):
+ """ will write log of current job in a *.log file with date,
+ pb name, output files... """
+ if self.LOG_ON:
+ fd = open(self.__logfile, 'a')
+ fd.write(string)
+ fd.close()
+
+
+ def setLog(self, boolean):
+ self.LOG_ON = boolean
+
class XMLParser:
@@ -134,9 +156,10 @@
__currentNode__ = None
__pointsList__ = None
- def __init__(self, xmlFile):
+ def __init__(self, xmlFile, interf):
""" constructor, xmlFile is the file object of the XML output """
self.__xmlFile = xmlFile
+ self.__interface = interf
def readXml(self):
from xml.dom.minidom import parse
@@ -172,7 +195,7 @@
p.value =
self.getText(point.getElementsByTagName('values')[0])
p.coords =
self.getList(point.getElementsByTagName('solution')) #returns a list
except:
- log(__LOG_NAME, 'ERROR : XML element missing')
+ self.__interface.log('ERROR : XML element
missing')
self.__pointsList__.append(p)
return self.__pointsList__
@@ -201,6 +224,7 @@
def main():
""" main() """
+
# path to ometah binary
__OMETAH_PATH = "../ometah"
@@ -210,37 +234,35 @@
# nb of breaks in the distribution histogram
__HIST_BREAKS = 20
- # name of the log file
- __LOG_NAME = datedFileName("", ".log")
-
+ interface = Interface(sys.argv)
+ interface.setLog(1)
slog = "\n\n[ Starting at " + time.ctime() + " ] \n"
- log(__LOG_NAME, slog)
- main = Interface(sys.argv)
+ interface.log(slog)
# fd ~ XML output
- fd = main.execOmetah(__OMETAH_PATH)
- log(__LOG_NAME, 'ometah execution ... OK\n')
+ fd = interface.execOmetah(__OMETAH_PATH)
+ interface.log('ometah execution ... OK\n')
# skip first line to avoid bug in parsing
fd.readline()
- parser = XMLParser(fd)
+ parser = XMLParser(fd, interface)
parser.readXml()
- log(__LOG_NAME, 'parsing XML : readXML() ... OK\n')
+ interface.log('parsing XML : readXML() ... OK\n')
- pointsList = parser.getPoints()
- log(__LOG_NAME, 'getting points list : getPoints() ... OK\n')
+ pointsList = parser.getPoints()
+ interface.log('getting points list : getPoints() ... OK\n')
# set_postscript_output(R_OUT)
setBitmapOutput(datedFileName(__R_OUT, '.png'))
- main.plotDistribution(pointsList, __HIST_BREAKS)
+ interface.plotDistribution(pointsList, __HIST_BREAKS)
r.dev_off()
- log(__LOG_NAME, 'outputing results : plotDistribution(...) ... OK\n')
+ interface.log('outputing results : plotDistribution(...) ... OK\n')
setBitmapOutput(datedFileName('values', '.png'))
- main.plotValues(pointsList)
+ interface.plotValues(pointsList, 1)
r.dev_off()
- log(__LOG_NAME, 'outputing results : plotValues(...) ... OK\n')
+ interface.log('outputing results : plotValues(...) ... OK\n')
if __name__ == '__main__':
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/06
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/07
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/07
- [oMetah-devel] ometah/experiment metahtest.py,
Jean-Philippe Aumasson <=
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/07
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/07
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/09
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/09
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/10
- [oMetah-devel] ometah/experiment metahtest.py, Jean-Philippe Aumasson, 2005/06/13