|
From: <ah...@us...> - 2011-11-18 15:01:16
|
Revision: 703
http://pyphant.svn.sourceforge.net/pyphant/?rev=703&view=rev
Author: aheld84
Date: 2011-11-18 15:01:02 +0000 (Fri, 18 Nov 2011)
Log Message:
-----------
Merge branch 'master' into svn-trunk
* master:
Fix: Removed direct usage of PyTablesPersister
Modified Paths:
--------------
trunk/src/pyphant/pyphant/cli/createExecutionOrder.py
trunk/src/pyphant/pyphant/cli/simpleCLI.py
trunk/src/pyphant/pyphant/core/H5FileHandler.py
trunk/src/pyphant/pyphant/core/PyTablesPersister.py
trunk/src/pyphant/pyphant/tests/TestH5FileHandler.py
trunk/src/pyphant/pyphant/tests/TestPyTablesPersister.py
trunk/src/pyphant/pyphant/wxgui2/wxPyphantApplication.py
Modified: trunk/src/pyphant/pyphant/cli/createExecutionOrder.py
===================================================================
--- trunk/src/pyphant/pyphant/cli/createExecutionOrder.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/cli/createExecutionOrder.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -1,6 +1,7 @@
import pkg_resources
pkg_resources.require('pyphant')
from pyphant.core import PyTablesPersister
+from pyphant.core.H5FileHandler import H5FileHandler
import optparse
import sys
@@ -105,7 +106,8 @@
orderLists.append(orders[i:])
for i, orderList in enumerate(orderLists):
filename = os.path.basename(sourcefile)[:-3]+'_%i.h5'%i
- PyTablesPersister.saveRecipeToHDF5File(recipe, filename)
+ with H5FileHandler(filename, 'w') as handler:
+ handler.saveRecipe(recipe)
h5 = tables.openFile(filename, 'r+')
for o in orderList:
PyTablesPersister.saveExecutionOrder(h5, o)
Modified: trunk/src/pyphant/pyphant/cli/simpleCLI.py
===================================================================
--- trunk/src/pyphant/pyphant/cli/simpleCLI.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/cli/simpleCLI.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -34,11 +34,12 @@
__author__ = "$Author: liehr $"
__version__ = "$Revision: 29 $"
-import pyphant.core.PyTablesPersister
+from pyphant.core.H5FileHandler import H5FileHandler
from pyphant.visualizers.ImageVisualizer import ImageVisualizer
#Load recipe from hdf file
-recipe = pyphant.core.PyTablesPersister.loadRecipeFromHDF5File('demo.h5')
+with H5FileHandler('demo.h5', 'r') as handler:
+ recipe = handler.loadRecipe()
#Configure ImageLoaderWorker
inputWorker = recipe.getWorkers('Image Loader')[0]
@@ -52,7 +53,3 @@
#Visualise result
visualizer = ImageVisualizer(result)
visualizer.figure.savefig('result-'+imageName)
-
-
-
-
Modified: trunk/src/pyphant/pyphant/core/H5FileHandler.py
===================================================================
--- trunk/src/pyphant/pyphant/core/H5FileHandler.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/core/H5FileHandler.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -39,10 +39,8 @@
# $Source$:
import tables
from pyphant.core import DataContainer
-from tables import StringCol
from pyphant.quantities import Quantity
PhysicalQuantity = Quantity
-import scipy
import logging
import os
from pyphant.core import PyTablesPersister
@@ -261,7 +259,7 @@
in the file.
result -- SampleContainer instance to be saved
"""
- PyTablesPersister.saveSample(self.handle, resultGroup, result)
+ return PyTablesPersister.saveSample(self.handle, resultGroup, result)
def saveField(self, resultGroup, result):
"""
@@ -271,4 +269,13 @@
in the file.
result -- FieldContainer instance to be saved
"""
- PyTablesPersister.saveField(self.handle, resultGroup, result)
+ return PyTablesPersister.saveField(self.handle, resultGroup, result)
+
+ def saveRecipe(self, recipe, saveResults=True):
+ """
+ Saves a recipe
+
+ recipe -- CompositeWorker to be saved
+ saveResults -- Whether to save results of the workers
+ """
+ return PyTablesPersister.saveRecipe(self.handle, recipe, saveResults)
Modified: trunk/src/pyphant/pyphant/core/PyTablesPersister.py
===================================================================
--- trunk/src/pyphant/pyphant/core/PyTablesPersister.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/core/PyTablesPersister.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -106,15 +106,12 @@
input.flush()
orderGroup._v_attrs.resultPlug = order[1]
-def saveRecipeToHDF5File(recipe, filename, saveResults=True):
- _logger.info( "Saving to %s" % filename )
- h5 = tables.openFile(filename, 'w')
+def saveRecipe(h5, recipe, saveResults=True):
recipeGroup = h5.createGroup("/", "recipe")
- resultsGroup = h5.createGroup("/", "results")
- workers=recipe.getWorkers()
+ h5.createGroup("/", "results")
+ workers = recipe.getWorkers()
for worker in workers:
saveWorker(h5, recipeGroup, worker, saveResults)
- h5.close()
def saveWorker(h5, recipeGroup, worker, saveResults=True):
workerGroup = h5.createGroup(recipeGroup, "worker_"+str(hash(worker)))
@@ -258,12 +255,6 @@
except KeyError:
_logger.warning(u'Could not restore "%s" to parameter: "%s"'%(param,paramName))
-def loadRecipeFromHDF5File( filename ):
- h5 = tables.openFile(filename, 'r')
- recipe = loadRecipe(h5)
- h5.close()
- return recipe
-
def loadRecipe(h5):
recipeGroup = h5.root.recipe
recipe = CompositeWorker.CompositeWorker()
Modified: trunk/src/pyphant/pyphant/tests/TestH5FileHandler.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestH5FileHandler.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/tests/TestH5FileHandler.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -45,8 +45,7 @@
import pkg_resources
pkg_resources.require("pyphant")
from pyphant.quantities import Quantity as PQ
-from pyphant.core.DataContainer import FieldContainer, SampleContainer,\
- assertEqual
+from pyphant.core.DataContainer import FieldContainer, SampleContainer
from pyphant.core.H5FileHandler import H5FileHandler as H5FH
from numpy import array as NPArray
import os
@@ -56,7 +55,7 @@
class BasicTestCase(unittest.TestCase):
def testReadOnlyFileNotFound(self):
try:
- handler = H5FH('', 'r')
+ H5FH('', 'r')
assert False
except IOError:
pass
@@ -78,8 +77,8 @@
class FCSaveLoadTestCase(FieldContainerTestCase):
def setUp(self):
FieldContainerTestCase.setUp(self)
- osHandle, self.fcFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.fcFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
def tearDown(self):
@@ -96,8 +95,8 @@
class FCReadOnlyTestCase(FieldContainerTestCase):
def setUp(self):
FieldContainerTestCase.setUp(self)
- osHandle, self.rofcFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.rofcFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
handler = H5FH(self.rofcFilename, 'w')
with handler:
@@ -137,11 +136,10 @@
class SCSaveLoadTestCase(SampleContainerTestCase):
def setUp(self):
SampleContainerTestCase.setUp(self)
- osHandle, self.scFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.scFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
-
def tearDown(self):
os.remove(self.scFilename)
@@ -156,8 +154,8 @@
class SCReadOnlyTestCase(SampleContainerTestCase):
def setUp(self):
SampleContainerTestCase.setUp(self)
- osHandle, self.roscFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.roscFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
handler = H5FH(self.roscFilename, 'w')
with handler:
@@ -176,8 +174,8 @@
class MixedAppendTestCase(SampleContainerTestCase):
def setUp(self):
SampleContainerTestCase.setUp(self)
- osHandle, self.appscFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.appscFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
handler = H5FH(self.appscFilename, 'w')
with handler:
@@ -199,8 +197,8 @@
class SummaryTestCase(SampleContainerTestCase):
def setUp(self):
SampleContainerTestCase.setUp(self)
- osHandle, self.summFilename = mkstemp(suffix = '.h5',
- prefix = 'pyphantH5FileHandlerTest')
+ osHandle, self.summFilename = mkstemp(
+ suffix = '.h5', prefix = 'pyphantH5FileHandlerTest')
os.close(osHandle)
handler = H5FH(self.summFilename, 'w')
with handler:
@@ -233,6 +231,38 @@
self.assertEqual(fcsummary['dimensions'], [im_id])
+class RecipeTestCase(unittest.TestCase):
+ def setUp(self):
+ osHandle, self.path = mkstemp(
+ suffix='.h5', prefix='pyphantH5RecipeTest')
+ os.close(osHandle)
+
+ def tearDown(self):
+ os.remove(self.path)
+
+ def testSaveLoadRecipe(self):
+ from pyphant.core.CompositeWorker import CompositeWorker
+ from pyphant.core.WorkerRegistry import WorkerRegistry
+ from itertools import chain
+ recipe = CompositeWorker()
+ wreg = WorkerRegistry.getInstance()
+ workerInfos = [t.workerInfos for t in wreg.getToolBoxInfoList()]
+ for wInfo in chain(*workerInfos):
+ worker = wInfo.createWorker()
+ recipe.addWorker(worker)
+ with H5FH(self.path, 'w') as handler:
+ handler.saveRecipe(recipe)
+ with H5FH(self.path, 'r') as handler:
+ loadedRecipe = handler.loadRecipe()
+ loadedWorkers = loadedRecipe.getWorkers()
+ workers = recipe.getWorkers()
+ self.assertEqual(len(loadedWorkers), len(workers))
+ workerNames = [w.name for w in workers]
+ loadedWorkerNames = [w.name for w in loadedWorkers]
+ for name in loadedWorkerNames:
+ self.assertTrue(name in workerNames)
+
+
if __name__ == "__main__":
import sys
if len(sys.argv) == 1:
Modified: trunk/src/pyphant/pyphant/tests/TestPyTablesPersister.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestPyTablesPersister.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/tests/TestPyTablesPersister.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -46,11 +46,10 @@
import scipy
import copy, datetime
from pyphant.quantities import Quantity
-from pyphant.core.DataContainer import FieldContainer, SampleContainer, assertEqual
+from pyphant.core.DataContainer import FieldContainer, SampleContainer
from pyphant.core.PyTablesPersister import (saveField, loadField, saveSample,
loadSample, saveExecutionOrder,
loadExecutionOrders)
-import numpy.testing as nt
import numpy
import tables
Modified: trunk/src/pyphant/pyphant/wxgui2/wxPyphantApplication.py
===================================================================
--- trunk/src/pyphant/pyphant/wxgui2/wxPyphantApplication.py 2011-11-17 11:10:52 UTC (rev 702)
+++ trunk/src/pyphant/pyphant/wxgui2/wxPyphantApplication.py 2011-11-18 15:01:02 UTC (rev 703)
@@ -61,8 +61,7 @@
import wx.aui
import sogl
import pyphant.wxgui2.paramvisualization.ParamVisReg as ParamVisReg
-from pyphant.core.PyTablesPersister import (loadRecipeFromHDF5File,
- saveRecipeToHDF5File)
+from pyphant.core.H5FileHandler import H5FileHandler
import WorkerRepository
import ConfigureFrame
import platform
@@ -226,8 +225,9 @@
if self._wxPyphantApp.pathToRecipe[-3:] == '.h5':
if os.path.exists(self._wxPyphantApp.pathToRecipe):
try:
- recipe = loadRecipeFromHDF5File(
- self._wxPyphantApp.pathToRecipe)
+ with H5FileHandler(self._wxPyphantApp.pathToRecipe, 'r') \
+ as handler:
+ recipe = handler.loadRecipe()
self._remainingSpace = PyphantCanvas.PyphantCanvas(
self, recipe)
except:
@@ -259,9 +259,9 @@
self.recipeState = 'dirty'
def onSaveCompositeWorker(self, event=None):
- saveRecipeToHDF5File(self._remainingSpace.diagram.recipe,
- self._wxPyphantApp.pathToRecipe,
- self._fileMenu.IsChecked(wx.ID_FILE4))
+ with H5FileHandler(self._wxPyphantApp.pathToRecipe, 'w') as handler:
+ handler.saveRecipe(self._remainingSpace.diagram.recipe,
+ self._fileMenu.IsChecked(wx.ID_FILE4))
self.recipeState = 'clean'
def onSaveAsCompositeWorker(self, event=None):
@@ -273,9 +273,10 @@
filename = dlg.GetPath()
if not filename.endswith(".h5"):
filename += ".h5"
- saveRecipeToHDF5File(
- self._remainingSpace.diagram.recipe,
- filename, self._fileMenu.IsChecked(wx.ID_FILE4))
+ with H5FileHandler(filename, 'w') as handler:
+ handler.saveRecipe(
+ self._remainingSpace.diagram.recipe,
+ self._fileMenu.IsChecked(wx.ID_FILE4))
self._wxPyphantApp.pathToRecipe = filename
self.recipeState = 'clean'
from pyphant.core.WebInterface import shorten
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|