|
From: <zk...@us...> - 2010-06-17 16:17:53
|
Revision: 685
http://pyphant.svn.sourceforge.net/pyphant/?rev=685&view=rev
Author: zklaus
Date: 2010-06-17 16:17:44 +0000 (Thu, 17 Jun 2010)
Log Message:
-----------
Merge branch 'master' into svn-trunk
* master:
Enh: rich comparison for Quantity
Enh: Added ZStack Visualizer
Enh: Refactored ZStack and AutoFocus
Enh: Emd5Src
Fix: SQLiteWrapper, SliceSelector
Fix: Removed unused workers
Enh: Feedback during update
Fix: WebInterface order_by
Cosm: gitignore
Fix: Handle broken toolboxes
Fix: Typo
Enh: NDImage Worker
Enh: Improved ZStack
Modified Paths:
--------------
trunk/.gitignore
trunk/src/pyphant/pyphant/cli/pyphant_exec.py
trunk/src/pyphant/pyphant/core/Connectors.py
trunk/src/pyphant/pyphant/core/EventDispatcher.py
trunk/src/pyphant/pyphant/core/Param.py
trunk/src/pyphant/pyphant/core/PyTablesPersister.py
trunk/src/pyphant/pyphant/core/SQLiteWrapper.py
trunk/src/pyphant/pyphant/core/WebInterface.py
trunk/src/pyphant/pyphant/core/ZStackManager.py
trunk/src/pyphant/pyphant/quantities/__init__.py
trunk/src/pyphant/pyphant/tests/TestQuantities.py
trunk/src/pyphant/pyphant/tests/TestZStacks.py
trunk/src/pyphant/pyphant/visualizers/__init__.py
trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ListSelect.py
trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ParamVisReg.py
trunk/src/pyphant/pyphant/wxgui2/wxPyphantApplication.py
trunk/src/workers/ImageProcessing/ImageProcessing/AutoFocus.py
trunk/src/workers/ImageProcessing/ImageProcessing/NDImageWorker.py
trunk/src/workers/ImageProcessing/ImageProcessing/SliceSelector.py
trunk/src/workers/ImageProcessing/ImageProcessing/__init__.py
trunk/src/workers/tools/tools/Emd5Src.py
trunk/src/workers/tools/tools/__init__.py
trunk/src/workers/tools/tools/tests/TestEmd5Source.py
Added Paths:
-----------
trunk/src/pyphant/pyphant/visualizers/ZStackVisualizer.py
trunk/src/workers/ImageProcessing/ImageProcessing/MarkAF.py
trunk/src/workers/tools/tools/FCSource.py
trunk/src/workers/tools/tools/SCSource.py
Removed Paths:
-------------
trunk/src/pyphant/pyphant/core/RecipeAlg.py
trunk/src/pyphant/pyphant/tests/TestAutoFocus.py
trunk/src/pyphant/pyphant/tests/resources/recipes/AutoFocus.h5
trunk/src/pyphant/pyphant/tests/resources/recipes/MeasureFocus.h5
trunk/src/pyphant/pyphant/tests/resources/recipes/pre-MF-no-median.h5
trunk/src/workers/ImageProcessing/ImageProcessing/MeasureFocus.py
trunk/src/workers/ImageProcessing/ImageProcessing/ZStacks.py
trunk/src/workers/tools/tools/BatchExtractor.py
trunk/src/workers/tools/tools/BatchHead.py
trunk/src/workers/tools/tools/BatchTail.py
trunk/src/workers/tools/tools/ParameterRun.py
Modified: trunk/.gitignore
===================================================================
--- trunk/.gitignore 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/.gitignore 2010-06-17 16:17:44 UTC (rev 685)
@@ -17,3 +17,4 @@
*.out
*.bst
*.bbl
+.ropeproject/
Modified: trunk/src/pyphant/pyphant/cli/pyphant_exec.py
===================================================================
--- trunk/src/pyphant/pyphant/cli/pyphant_exec.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/cli/pyphant_exec.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -59,10 +59,10 @@
w = recipe.getWorker(sSpec[0])
s = getattr(w, sSpec[-1])
src = Emd5Src.Emd5Src(recipe)
- src.paramDc.value=emd5
+ src.paramEmd5.value=emd5
if s.isFull():
s.pullPlug()
- s.insert(src.plugLoad)
+ s.insert(src.plugGetDataContainer)
pSpec = order[1][0].split('.')
d = recipe.getWorker(pSpec[0])
plug = getattr(d, pSpec[1])
Modified: trunk/src/pyphant/pyphant/core/Connectors.py
===================================================================
--- trunk/src/pyphant/pyphant/core/Connectors.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/Connectors.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -48,6 +48,7 @@
TYPE_INT = type(2)
TYPE_STRING = type("")
SUBTYPE_FILE = "filename"
+SUBTYPE_INSTANT = "instant"
TYPE_INACTIVE = type(None)
TYPE_BOOL = type(True)
DEFAULT_DATA_TYPE = TYPE_ARRAY
Modified: trunk/src/pyphant/pyphant/core/EventDispatcher.py
===================================================================
--- trunk/src/pyphant/pyphant/core/EventDispatcher.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/EventDispatcher.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -47,6 +47,14 @@
except KeyError:
self._listeners[eventType] = [listener]
+ # The following method is a quick workaround for the shortcoming
+ # of this EventDispatcher which offers no control, in which
+ # order listeners for the same event are called and the
+ # event interface is not specified at all, so there is no
+ # functionality like event.skip()
+ def registerExclusiveListener(self, listener, eventType):
+ self._listeners[eventType] = [listener]
+
def unregisterListener(self, listener, eventType=None):
if eventType:
self._listeners[eventType].remove( listener )
Modified: trunk/src/pyphant/pyphant/core/Param.py
===================================================================
--- trunk/src/pyphant/pyphant/core/Param.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/Param.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -47,18 +47,40 @@
return Param(worker, paramName, displayName, values, subtype)
+class ParamChangeExpected(object):
+ def __init__(self, param, expectedValue):
+ self.param = param
+ self.expectedValue = expectedValue
+
+
+class PossibleValuesChangeExpected(object):
+ def __init__(self, param, expectedPVs, update=False):
+ self.param = param
+ self.expectedPVs = expectedPVs
+ self.update = update
+
+
class ParamChangeRequested(object):
def __init__(self, param, oldValue, newValue):
self.param = param
self.oldValue = oldValue
self.newValue = newValue
+
class ParamChanged(object):
def __init__(self, param, oldValue, newValue):
self.param = param
self.oldValue = oldValue
self.newValue = newValue
+
+class ParamOverridden(object):
+ def __init__(self, param, oldValue, newValue):
+ self.param = param
+ self.oldValue = oldValue
+ self.newValue = newValue
+
+
class VetoParamChange(ValueError):
def __init__(self, paramChangeEvent):
ValueError.__init__(self, "Veto: change %s from %s to %s." %
@@ -67,6 +89,7 @@
paramChangeEvent.newValue))
self.paramChangeEvent = paramChangeEvent
+
class Param(Connectors.Socket):
def __getValue(self):
if self.isFull():
@@ -75,7 +98,10 @@
return self._value
def overrideValue(self, value):
+ oldValue = self._value
self._value = value
+ self._eventDispatcher.dispatchEvent(
+ ParamOverridden(self, oldValue, value))
def __setValue(self, value):
oldValue = self.value
Modified: trunk/src/pyphant/pyphant/core/PyTablesPersister.py
===================================================================
--- trunk/src/pyphant/pyphant/core/PyTablesPersister.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/PyTablesPersister.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -68,7 +68,6 @@
from tables import StringCol, Col
from pyphant.quantities import Quantity
from pyphant.quantities import Quantity as PhysicalQuantity
-from ImageProcessing.AutoFocus import FocusSlice # For loading FCs...
import scipy
import logging
_logger = logging.getLogger("pyphant")
Deleted: trunk/src/pyphant/pyphant/core/RecipeAlg.py
===================================================================
--- trunk/src/pyphant/pyphant/core/RecipeAlg.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/RecipeAlg.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -1,148 +0,0 @@
-#!/usr/bin/env python2.5
-# -*- coding: utf-8 -*-
-
-# Copyright (c) 2006-2009, Rectorate of the University of Freiburg
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# * Neither the name of the Freiburg Materials Research Center,
-# University of Freiburg nor the names of its contributors may be used to
-# endorse or promote products derived from this software without specific
-# prior written permission.
-#
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-u"""Provides ZStackManager
-"""
-
-__id__ = "$Id$".replace('$','')
-__author__ = "$Author$".replace('$','')
-__version__ = "$Revision$".replace('$','')
-# $Source$
-
-from pyphant.core.KnowledgeManager import KnowledgeManager
-from pyphant.core.PyTablesPersister import loadRecipeFromHDF5File
-from tools import Emd5Src
-import os
-kmanager = KnowledgeManager.getInstance()
-
-
-class RecipeAlg(object):
- def __init__(self, recipe_fname, result_worker,
- result_plug, params={}):
- self.recipe_fname = recipe_fname
- self.recipe = loadRecipeFromHDF5File(recipe_fname)
- self.params = params
- self.rwn = result_worker
- self.rpn = result_plug
- self.result_plug = self.recipe.getWorker(
- result_worker).getPlug(result_plug)
-
- def get_result(self, input_ids, id_only=False, temporary=False):
- from pyphant.core.Helpers import utf82uc
- search_dict = {'attributes':{
- 'recipe':utf82uc(self.recipe_fname),
- 'result_worker':utf82uc(self.rwn),
- 'result_plug':utf82uc(self.rpn),
- 'applied_to':utf82uc(input_ids.__repr__()),
- 'params':utf82uc(self.params.__repr__())}}
- result_ids = kmanager.search(['id'], search_dict)
- if len(result_ids) > 0 and not temporary:
- if id_only:
- return result_ids[0][0]
- else:
- return kmanager.getDataContainer(result_ids[0][0])
- else:
- # Fill open sockets:
- for wname, sockets in input_ids.iteritems():
- worker = self.recipe.getWorker(wname)
- for sname, emd5 in sockets.iteritems():
- socket = worker.getSocket(sname)
- dummy = Emd5Src.Emd5Src()
- dummy.paramSelectby.value = u"enter emd5"
- dummy.paramEnteremd5.value = emd5
- socket.insert(dummy.getPlugs()[0])
- # Set parameters:
- for wname, wparams in self.params.iteritems():
- for pname, pvalue in wparams.iteritems():
- self.recipe.getWorker(wname).getParam(pname).value = pvalue
- # Get Result
- result_dc = self.result_plug.getResult()
- # Pull plugs
- for wname, sockets in input_ids.iteritems():
- worker = self.recipe.getWorker(wname)
- for sname, emd5 in sockets.iteritems():
- worker.getSocket(sname).pullPlug()
- result_dc.attributes['recipe'] = utf82uc(self.recipe_fname)
- result_dc.attributes['applied_to'] = utf82uc(input_ids.__repr__())
- result_dc.attributes['params'] = utf82uc(self.params.__repr__())
- result_dc.attributes['result_plug'] = utf82uc(self.rpn)
- result_dc.attributes['result_worker'] = utf82uc(self.rwn)
- kmanager.registerDataContainer(result_dc, temporary=temporary)
- if id_only:
- return result_dc.id
- else:
- return result_dc
-
- def get_batch_result_id(self, input_ids, column='emd5', update_attrs={},
- subscriber=0, start=1, end=100, temporary=False):
- subscriber %= start
- from pyphant.core.Helpers import utf82uc
- search_dict = {'attributes':{
- 'batch_recipe':utf82uc(self.recipe_fname),
- 'result_worker':utf82uc(self.rwn),
- 'result_plug':utf82uc(self.rpn),
- 'applied_to':utf82uc(input_ids.__repr__()),
- 'params':utf82uc(self.params.__repr__())}}
- result_ids = kmanager.search(['id'], search_dict)
- if len(result_ids) > 0:
- subscriber %= end
- return result_ids[0][0]
- import copy
- input_scs = dict([(wname, dict([(sname, kmanager.getDataContainer(emd5)) \
- for sname, emd5 in sockets.iteritems()])) \
- for wname, sockets in input_ids.iteritems()])
- out_column = []
- ref_sc = input_scs.values()[0].values()[0]
- output_sc = copy.deepcopy(ref_sc)
- import numpy
- sharpruns = len(ref_sc[column].data)
- import math
- for index in xrange(sharpruns):
- subscriber %= 1 + math.floor(start + float((end - start) * index) \
- / sharpruns)
- ids = dict([(wname, dict([(sname, unicode(isc[column].data[index])) \
- for sname, isc in sockets.iteritems()])) \
- for wname, sockets in input_scs.iteritems()])
- out_column.append(self.get_result(ids, id_only=True))
- output_sc[column].data = numpy.array(out_column)
- output_sc.longname = "%s_%s" % (os.path.basename(self.recipe_fname),
- ref_sc.longname)
- output_sc.attributes['batch_recipe'] = utf82uc(self.recipe_fname)
- output_sc.attributes['applied_to'] = utf82uc(input_ids.__repr__())
- output_sc.attributes['result_plug'] = utf82uc(self.rpn)
- output_sc.attributes['result_worker'] = utf82uc(self.rwn)
- output_sc.attributes['params'] = utf82uc(self.params.__repr__())
- output_sc.attributes.update(update_attrs)
- output_sc.seal()
- kmanager.registerDataContainer(output_sc, temporary=temporary)
- subscriber %= end
- return output_sc.id
Modified: trunk/src/pyphant/pyphant/core/SQLiteWrapper.py
===================================================================
--- trunk/src/pyphant/pyphant/core/SQLiteWrapper.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/SQLiteWrapper.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -189,9 +189,10 @@
one_to_one_result_keys = one_to_one_search_keys + ['date', 'id', 'type']
common_search_keys = one_to_one_search_keys + ['id', 'attributes',
'date_from', 'date_to']
- fc_search_keys = common_search_keys + ['unit', 'dimensions', 'dim_of', 'col_of']
+ fc_search_keys = common_search_keys + ['unit', 'dimensions',
+ 'dim_of', 'col_of']
sc_search_keys = common_search_keys + ['columns']
- sortable_keys = common_keys + ['id', 'storage', 'type']
+ sortable_keys = common_keys + ['storage', 'type']
any_value = AnyValue()
def __init__(self, database, timeout=60.0):
Modified: trunk/src/pyphant/pyphant/core/WebInterface.py
===================================================================
--- trunk/src/pyphant/pyphant/core/WebInterface.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/WebInterface.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -593,6 +593,8 @@
+ [key for key in common_keys \
if qry[key] == self.anystr] \
+ ['id']
+ if not order_by in missing_keys:
+ order_by = 'date'
search_result = self.kn.km.search(
missing_keys, search_dict, order_by=order_by,
order_asc=order_asc, limit=limit, offset=offset)
Modified: trunk/src/pyphant/pyphant/core/ZStackManager.py
===================================================================
--- trunk/src/pyphant/pyphant/core/ZStackManager.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/core/ZStackManager.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -45,7 +45,6 @@
import scipy
import Image
from pyphant.core.KnowledgeManager import KnowledgeManager
-from pyphant.core.RecipeAlg import RecipeAlg
import os
kmanager = KnowledgeManager.getInstance()
@@ -53,8 +52,8 @@
class ZStack(object):
def __init__(self, sc_id=None, name=None, xml_file=None, temporary=False):
"""Initializes a ZStack from an existing id or a local source"""
- self.temporary = temporary
assert (sc_id is None) is not (xml_file is None)
+ self.temporary = temporary
self._recipe_path = None
if sc_id is not None:
self.repr_sc = kmanager.getDataContainer(sc_id)
@@ -137,11 +136,13 @@
'zvi_filename':img_meta['zvi_filename'],
'zvalue':zvalue,
'timestamp':img_meta['timestamp'],
- 'zid':img_meta['zid']}
+ 'zid':img_meta['zid'],
+ 'ZStackType':'RawImage',
+ 'vmin':0, 'vmax':255}
img_fc = FieldContainer(data=data,
longname=os.path.basename(
img_meta['img_filename']),
- shortname="img",
+ shortname="i",
dimensions=dimensions, attributes=fcattr)
img_fc.seal()
kmanager.registerDataContainer(img_fc, temporary=temporary)
@@ -153,7 +154,8 @@
shortname='z', unit=Quantity(1.0, 'mum'))
filefc = FieldContainer(scipy.array(files), longname='filename',
shortname='f')
- emd5fc = FieldContainer(scipy.array(emd5s), longname='emd5', shortname='i')
+ emd5fc = FieldContainer(scipy.array(emd5s), longname='emd5',
+ shortname='i')
if pdial is not None:
pdial.Destroy()
return zfc, filefc, emd5fc
@@ -175,55 +177,16 @@
return None
attributes = {}
attributes['ztol'] = ZStack._estimate_ztol(zfc)
- attributes['isZStack'] = 'yes'
+ attributes['ZStackType'] = 'RawSC'
ssc = SampleContainer([zfc, filefc, emd5fc],
name,
- "z-stack",
+ "z",
attributes)
ssc.seal()
kmanager.registerDataContainer(ssc, temporary=self.temporary)
return ssc
- def _set_recipe_path(self, rpath):
- self._recipe_path = os.path.realpath(rpath)
- def _get_recipe_path(self):
- return self._recipe_path
- recipe_path = property(_get_recipe_path, _set_recipe_path)
-
- def _get_mf_id(self, gradient_alg, label_alg, human, subscriber=0):
- assert self._recipe_path is not None
- uattr = {'isZStack':'no'}
- in_ids = {'grey_invert':{'image':self.repr_sc.id}}
- gradient_id = gradient_alg.get_batch_result_id(
- in_ids, update_attrs=uattr, subscriber=subscriber,
- start=1, end=30, temporary=self.temporary)
- in_ids = {'threshold':{'image':gradient_id}}
- label_id = label_alg.get_batch_result_id(
- in_ids, update_attrs=uattr, subscriber=subscriber,
- start=31, end=66, temporary=self.temporary)
- mf_alg = RecipeAlg(os.path.join(self.recipe_path, 'MeasureFocus.h5'),
- 'MeasureFocus', 'measure_focus',
- {'MeasureFocus':{'humanOutput':human}})
- in_ids = {'MeasureFocus':{'image':gradient_id,
- 'labels':label_id}}
- return mf_alg.get_batch_result_id(
- in_ids, update_attrs=uattr, subscriber=subscriber,
- start=67, end=100, temporary=self.temporary)
-
- def get_statistics(self, gradient_alg, label_alg, subscriber=0):
- mf_id = self._get_mf_id(gradient_alg, label_alg, False, subscriber)
- af_alg = RecipeAlg(os.path.join(self.recipe_path, 'AutoFocus.h5'),
- 'AutoFocus', 'AutoFocusWorker')
- in_ids = {'AutoFocus':{'focusSC':mf_id}}
- af_sc = af_alg.get_result(in_ids, temporary=self.temporary)
- return af_sc
-
- def get_human_imgs(self, gradient_alg, label_alg, subscriber=0):
- mf_id = self._get_mf_id(gradient_alg, label_alg, True, subscriber)
- return kmanager.getDataContainer(mf_id)
-
-
class ZStackManager(object):
def addZStack(self, zstack):
"""Adds a given zstack to the pool"""
@@ -231,8 +194,17 @@
def getZStacks(self):
"""Returns a list of all ZStacks in the pool"""
- search_dict = {'type':'sample', 'attributes':{'isZStack':'yes'}}
+ search_dict = {'type':'sample', 'attributes':{'ZStackType':'RawSC'}}
search_result = kmanager.search(['id'], search_dict)
if len(search_result) == 0:
return []
return [ZStack(zs_id[0]) for zs_id in search_result]
+
+ def getZStackByName(self, name):
+ search_dict = {'type':'sample', 'attributes':{'ZStackType':'RawSC'},
+ 'longname':name}
+ sresult = kmanager.search(['id'], search_dict)
+ if sresult == []:
+ raise ValueError("There is no ZStack called %s!" \
+ % name)
+ return ZStack(sc_id=sresult[0][0])
Modified: trunk/src/pyphant/pyphant/quantities/__init__.py
===================================================================
--- trunk/src/pyphant/pyphant/quantities/__init__.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/quantities/__init__.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -241,6 +241,46 @@
def __rsub__(self, other):
return self._sum(other, -1, 1)
+ def __eq__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) == 0
+ else:
+ return False
+
+ def __ne__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) != 0
+ else:
+ return True
+
+ def __le__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) <= 0
+ else:
+ return False
+
+ def __ge__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) >= 0
+ elif other is None:
+ return True
+ else:
+ return False
+
+ def __lt__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) < 0
+ else:
+ return False
+
+ def __gt__(self, other):
+ if isQuantity(other) and self.isCompatible(other.unit):
+ return self.__cmp__(other) > 0
+ elif other is None:
+ return True
+ else:
+ return False
+
def __cmp__(self, other):
normed = self.inBaseUnits() # Minimizing numerical errors
diff = normed._sum(other, 1, -1)
Deleted: trunk/src/pyphant/pyphant/tests/TestAutoFocus.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestAutoFocus.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/tests/TestAutoFocus.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -1,229 +0,0 @@
-#!/usr/bin/env python2.5
-# -*- coding: utf-8 -*-
-
-# Copyright (c) 2006-2010, Rectorate of the University of Freiburg
-# Copyright (c) 2009-2010, Andreas W. Liehr (li...@us...)
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# * Neither the name of the Freiburg Materials Research Center,
-# University of Freiburg nor the names of its contributors may be used to
-# endorse or promote products derived from this software without specific
-# prior written permission.
-#
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-u"""Provides unittest classes for AutoFocus worker.
-"""
-
-__id__ = "$Id$".replace('$','')
-__author__ = "$Author$".replace('$','')
-__version__ = "$Revision$".replace('$','')
-# $Source$
-
-import unittest
-import pkg_resources
-pkg_resources.require("pyphant")
-from pyphant.quantities import Quantity
-from pyphant.core.DataContainer import FieldContainer, SampleContainer
-from ImageProcessing import AutoFocus as AF
-import numpy
-from pyphant.core.KnowledgeManager import KnowledgeManager
-
-
-class CubeTestCase(unittest.TestCase):
- def setUp(self):
- self.cube1 = AF.Cube([slice(0, 10),
- slice(0, 10),
- slice(0, 10)])
- self.cube2 = AF.Cube([slice(3, 5),
- slice(4, 6),
- slice(-5, 7)])
- def tearDown(self):
- pass
-
- def testEq(self):
- cube1c = AF.Cube(self.cube1.slices)
- assert self.cube1 == cube1c
- assert not self.cube1.__eq__(self.cube2)
-
- def testAnd(self):
- expected = AF.Cube([slice(3, 5), slice(4, 6), slice(0, 7)])
- assert self.cube1 & self.cube2 == expected
-
- def testOr(self):
- expected = AF.Cube([slice(0, 10), slice(0, 10), slice(-5, 10)])
- assert self.cube1 | self.cube2 == expected
-
- def testVolume(self):
- assert self.cube1.getVolume() == 1000
- assert self.cube2.getVolume() == 48
- assert AF.Cube([slice(0, 0),
- slice(0, 1000),
- slice(0, 1000)]).getVolume() == 0
-
- def testSubCube(self):
- expected = AF.Cube([slice(3,5 ), slice(-5, 7)])
- assert self.cube2.getSubCube([0, 2]) == expected
-
- def testGetEdgeLength(self):
- assert self.cube2.getEdgeLength(0) == 2
- assert self.cube2.getEdgeLength(1) == 2
- assert self.cube2.getEdgeLength(2) == 12
-
- def testSub(self):
- expected = AF.Cube([slice(-3, 7),
- slice(-4, 6),
- slice(5, 15)])
- assert self.cube1 - self.cube2 == expected
-
- def testCenter(self):
- expected = (5.0, 5.0, 5.0)
- assert self.cube1.getCenter() == expected
-
-
-class ZTubeTestCase(unittest.TestCase):
- def setUp(self):
- slices = [slice(0, 10), slice(0, 10)]
- mask = numpy.ones((20, 20), dtype=bool)
- mask_fc = FieldContainer(mask)
- mask_fc.seal()
- km = KnowledgeManager.getInstance()
- km.registerDataContainer(mask_fc, temporary=True)
- mask_parent = mask_fc.id
- fslice = AF.FocusSlice(slices, 10.0, mask_parent, slices, 1, 1)
- self.ztube = AF.ZTube(fslice, 0, 1, 0.5, 0.5)
- testslices1 = [slice(3, 12), slice(2, 9)]
- mask1 = numpy.ones((9, 7), dtype=bool)
- self.testfslice1 = AF.FocusSlice(testslices1, 12.0, mask_parent,
- testslices1, 1, 1)
- testslices2 = [slice(7, 17), slice(8, 16)]
- mask2 = numpy.ones((10, 8), dtype=bool)
- self.testfslice2 = AF.FocusSlice(testslices2, 8.0, mask_parent,
- testslices2, 1, 1)
-
- def tearDown(self):
- pass
-
- def testMatching(self):
- assert self.ztube.match(self.testfslice1, 1)
- assert not self.ztube.match(self.testfslice2, 1.01)
- expectedyx = AF.Cube([slice(0, 12),
- slice(0, 10)])
- expectedz = AF.Cube([slice(-1, 2)])
- assert self.ztube.yxCube == expectedyx
- assert self.ztube.zCube == expectedz
- assert self.ztube.focusedFSlice == self.testfslice1
- assert self.ztube.focusedZ == 1
-
-
-class AutoFocusTestCase(unittest.TestCase):
- def setUp(self):
- from pyphant.core.KnowledgeManager import KnowledgeManager
- km = KnowledgeManager.getInstance()
- sl1 = [slice(Quantity('1.0mm'),
- Quantity('2.0mm')),
- slice(Quantity('1.5mm'),
- Quantity('3.5mm'))]
- sl2 = [slice(Quantity('0.8mm'),
- Quantity('1.9mm')),
- slice(Quantity('1.7mm'),
- Quantity('3.4mm'))]
- mask = numpy.ones((11, 20), dtype=bool)
- mask_fc = FieldContainer(mask)
- mask_fc.seal()
- mask_parent = mask_fc.id
- km = KnowledgeManager.getInstance()
- km.registerDataContainer(mask_fc, temporary=True)
- fsl1 = AF.FocusSlice(sl1, Quantity('10.0mm**-3'), mask_parent,
- [slice(0, 10), slice(0, 20)],
- Quantity('1.0mm'),
- Quantity('1.0mm'))
- self.fsl2 = AF.FocusSlice(sl2, Quantity('12.0mm**-3'),
- mask_parent, [slice(0, 11), slice(0, 17)],
- Quantity('0.1mm'), Quantity('0.1mm'))
- fc1 = FieldContainer(numpy.array([fsl1]))
- fc2 = FieldContainer(numpy.array([self.fsl2]))
- fc1.seal()
- fc2.seal()
- km.registerDataContainer(fc1, temporary=True)
- km.registerDataContainer(fc2, temporary=True)
- columns = [FieldContainer(numpy.array([.5, 1.0]),
- unit=Quantity('1.0mm'),
- longname='z-value'),
- FieldContainer(numpy.array([fc1.id, fc2.id]),
- longname="emd5")]
- attributes = {u'ztol': Quantity('0.5mm')}
- self.inputSC = SampleContainer(columns, attributes=attributes)
- self.inputSC.seal()
-
- def tearDown(self):
- pass
-
- def testAutofocus(self):
- columns = AF.autofocus(self.inputSC, 0.5, 0.75)
- inclusionSC = SampleContainer(columns,
- "AutoFocus")
- for fc in inclusionSC.columns:
- assert fc.data.shape == (1, )
- zfc, yfc, xfc, dfc, ffc = inclusionSC.columns
- assert zfc.data[0] * zfc.unit == Quantity('1.0mm')
- assert (yfc.data[0] * yfc.unit,
- xfc.data[0] * xfc.unit) == self.fsl2.getCenter()
- assert ffc.data[0] * ffc.unit == Quantity('12.0mm**-3')
-
-
-class FocusSliceTestCase(unittest.TestCase):
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
- def testSaveLoadFocusSlice(self):
- km = KnowledgeManager.getInstance()
- mask = numpy.ones((100, 150), dtype=bool)
- mask_fc = FieldContainer(mask)
- mask_fc.seal()
- mask_parent = mask_fc.id
- km.registerDataContainer(mask_fc, temporary=True)
- slices = [slice(Quantity('100mm'),
- Quantity('200mm')),
- slice(Quantity('150mm'),
- Quantity('350mm'))]
- fslice = AF.FocusSlice(slices, Quantity('10mm**-3'),
- mask_parent, [slice(0, 100), slice(0, 150)],
- Quantity('1mm'), Quantity('1mm'))
- fc = FieldContainer(numpy.array([fslice for xr in xrange(1000)]))
- fc.seal()
- km.registerDataContainer(fc, temporary=True)
- returnfc = km.getDataContainer(fc.id, use_cache=False)
- assert returnfc.data[0].slices[0].start == fc.data[0].slices[0].start
-
-
-if __name__ == "__main__":
- import sys
- if len(sys.argv) == 1:
- unittest.main()
- else:
- suite = unittest.TestLoader().loadTestsFromTestCase(
- eval(sys.argv[1:][0]))
- unittest.TextTestRunner().run(suite)
Modified: trunk/src/pyphant/pyphant/tests/TestQuantities.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestQuantities.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/tests/TestQuantities.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -45,6 +45,15 @@
(Quantity(731814.5,'d'), None)
"""
class TestQuantity(unittest.TestCase):
+ def setUp(self):
+ self.quants = []
+ self.quants.append(Quantity("1000 m"))
+ self.quants.append(Quantity("1 km"))
+ self.quants.append(Quantity("1000.1 m"))
+ self.quants.append(0)
+ self.quants.append(None)
+ self.quants.append(Quantity("1000 s"))
+
def testTextualQuantitySpecification(self):
self.assertEqual(Quantity('1V'),
Quantity(1.0,'V')
@@ -58,6 +67,90 @@
Quantity(1.0,'V')
)
+ def compare(self, quant0, cop, quant1, result):
+ if cop == '==':
+ expression = quant0 == quant1
+ elif cop == '!=':
+ expression = quant0 != quant1
+ elif cop == '<=':
+ expression = quant0 <= quant1
+ elif cop == '>=':
+ expression = quant0 >= quant1
+ elif cop == '<':
+ expression = quant0 < quant1
+ elif cop == '>':
+ expression = quant0 > quant1
+ if expression != result:
+ print "%s %s %s = %s, should be %s" % (quant0, cop, quant1,
+ expression, result)
+ self.assertEqual(expression, result)
+
+ def matrixTest(self, matrix, cop):
+ for index0, quant0 in enumerate(self.quants):
+ for index1, quant1 in enumerate(self.quants):
+ self.compare(quant0, cop, quant1, matrix[index0][index1])
+
+ def testComparisonOperationEqual(self):
+ matrix = [[1, 1, 0, 0, 0, 0],
+ [1, 1, 0, 0, 0, 0],
+ [0, 0, 1, 0, 0, 0],
+ [0, 0, 0, 1, 0, 0],
+ [0, 0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 0, 1]]
+ self.matrixTest(matrix, '==')
+
+ def testComparisonOperationNotEqual(self):
+ matrix = [[0, 0, 1, 1, 1, 1],
+ [0, 0, 1, 1, 1, 1],
+ [1, 1, 0, 1, 1, 1],
+ [1, 1, 1, 0, 1, 1],
+ [1, 1, 1, 1, 0, 1],
+ [1, 1, 1, 1, 1, 0]]
+ self.matrixTest(matrix, '!=')
+
+ def testComparisonOperationLessOrEqual(self):
+ matrix = [[1, 1, 1, 0, 0, 0],
+ [1, 1, 1, 0, 0, 0],
+ [0, 0, 1, 0, 0, 0],
+ [0, 0, 0, 1, 0, 0],
+ [1, 1, 1, 1, 1, 1],
+ [0, 0, 0, 0, 0, 1]]
+ self.matrixTest(matrix, '<=')
+
+ def testComparisonOperationGreaterOrEqual(self):
+ matrix = [[1, 1, 0, 0, 1, 0],
+ [1, 1, 0, 0, 1, 0],
+ [1, 1, 1, 0, 1, 0],
+ [0, 0, 0, 1, 1, 0],
+ [0, 0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 1, 1]]
+ self.matrixTest(matrix, '>=')
+
+ def testComparisonOperationLess(self):
+ matrix = [[0, 0, 1, 0, 0, 0],
+ [0, 0, 1, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0],
+ [1, 1, 1, 1, 0, 1],
+ [0, 0, 0, 0, 0, 0]]
+ self.matrixTest(matrix, '<')
+
+ def testComparisonOperationGreater(self):
+ matrix = [[0, 0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 1, 0],
+ [1, 1, 0, 0, 1, 0],
+ [0, 0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 1, 0]]
+ self.matrixTest(matrix, '>')
+
+ def testList(self):
+ self.assertEqual(self.quants[1] in self.quants, True)
+ self.assertEqual(self.quants[0] in self.quants[1:], True)
+ self.assertEqual(self.quants[2] in self.quants[3:], False)
+ self.assertEqual(self.quants[1] in [], False)
+
+
if __name__ == "__main__":
import sys
if len(sys.argv) == 1:
Modified: trunk/src/pyphant/pyphant/tests/TestZStacks.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestZStacks.py 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/tests/TestZStacks.py 2010-06-17 16:17:44 UTC (rev 685)
@@ -51,19 +51,6 @@
def tearDown(self):
pass
- def get_rp_ga_la(self, ppath):
- import os
- from pyphant.core.RecipeAlg import RecipeAlg
- gradient_recipe = "pre-MF-no-median.h5"
- label_recipe = "pre-MF-no-median.h5"
- rpath = os.path.join(ppath, "tests", "resources", "recipes")
- gradient_alg = RecipeAlg(os.path.join(rpath, gradient_recipe),
- 'gradient', 'gradientWorker',
- {'median':{'size':5}})
- label_alg = RecipeAlg(os.path.join(rpath, label_recipe),
- 'label', 'ndimage')
- return (rpath, gradient_alg, label_alg)
-
def check(self, rng, value):
assert value >= rng[0] - rng[1] and value <= rng[0] + rng[1], \
"Value %f not in range (%f, %f)" % (value, rng[0] - rng[1],
@@ -81,22 +68,21 @@
temporary=True)
print "Done."
print "Calculating ZStack-statistics..."
- rpath, gradient_alg, label_alg = self.get_rp_ga_la(ppath[0])
- zstack.recipe_path = rpath
- statistics = zstack.get_statistics(gradient_alg, label_alg)
+ from ImageProcessing.AutoFocus import AutoFocus
+ afw = AutoFocus()
+ statistics = afw.get_statistics_sc(zstack.repr_sc)
print "Done."
assert len(statistics['diameter'].data) == 2
imax = statistics['diameter'].data.argmax()
imin = statistics['diameter'].data.argmin()
- self.check((200.0, 1.0), statistics['x-value'].data[imax])
- self.check((200.0, 1.0), statistics['y-value'].data[imax])
- self.check((300.0, 0.0), statistics['z-value'].data[imax])
- self.check((20.5, 1.0), statistics['diameter'].data[imax])
- self.check((53.0, 1.0), statistics['x-value'].data[imin])
- self.check((53.0, 1.0), statistics['y-value'].data[imin])
- self.check((300.0, 0.0), statistics['z-value'].data[imin])
- self.check((6.5, 1.0), statistics['diameter'].data[imin])
- print statistics['diameter'].data
+ self.check((200.0, 1.0), statistics['x-pos'].data[imax])
+ self.check((200.0, 1.0), statistics['y-pos'].data[imax])
+ self.check((300.0, 0.0), statistics['z-pos'].data[imax])
+ self.check((20.7, 1.0), statistics['diameter'].data[imax])
+ self.check((53.0, 1.0), statistics['x-pos'].data[imin])
+ self.check((53.0, 1.0), statistics['y-pos'].data[imin])
+ self.check((300.0, 0.0), statistics['z-pos'].data[imin])
+ self.check((7.0, 1.0), statistics['diameter'].data[imin])
if __name__ == "__main__":
Deleted: trunk/src/pyphant/pyphant/tests/resources/recipes/AutoFocus.h5
===================================================================
--- trunk/src/pyphant/pyphant/tests/resources/recipes/AutoFocus.h5 2010-05-26 20:45:06 UTC (rev 684)
+++ trunk/src/pyphant/pyphant/tests/resources/recipes/AutoFocus.h5 2010-06-17 16:17:44 UTC (rev 685)
@@ -1,18 +0,0 @@
-\x89HDF
-
- |