| 
     
      
      
      From: <zk...@us...> - 2010-07-12 21:47:59
      
     
   | 
Revision: 696
          http://pyphant.svn.sourceforge.net/pyphant/?rev=696&view=rev
Author:   zklaus
Date:     2010-07-12 21:47:51 +0000 (Mon, 12 Jul 2010)
Log Message:
-----------
Merge branch 'master' into svn-trunk
* master:
  Enh: Add EstimateParameterFromValues.py
  Enh: Add removal of second lamp peak to Absorbtion calculation.
  Fix: Improve progress handling in Compute Functional.
  Enh: PlotFrame now takes the mask of the value column into account.
  Fix: MRA can now deal with curves without extrema.
Modified Paths:
--------------
    trunk/src/pyphant/pyphant/visualizers/ConfigurablePlot.py
    trunk/src/workers/OSC/OSC/ComputeFunctional.py
    trunk/src/workers/OSC/OSC/MRA.py
    trunk/src/workers/OSC/OSC/OscAbsorption.py
    trunk/src/workers/OSC/OSC/__init__.py
Added Paths:
-----------
    trunk/src/workers/OSC/OSC/EstimateParameterFromValues.py
Modified: trunk/src/pyphant/pyphant/visualizers/ConfigurablePlot.py
===================================================================
--- trunk/src/pyphant/pyphant/visualizers/ConfigurablePlot.py	2010-07-12 20:43:11 UTC (rev 695)
+++ trunk/src/pyphant/pyphant/visualizers/ConfigurablePlot.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -122,9 +122,13 @@
         if not isinstance(aspect, Quantity):
             self.ax.set_aspect(aspect)
         try:
-            self.scat = self.ax.scatter(self.x.data, self.y.data,
+            mask = numpy.logical_not(self.c.mask)
+            x = self.x.data[mask]
+            y = self.y.data[mask]
+            c = self.c.data[mask]
+            self.scat = self.ax.scatter(x,y,
                                         s=numpy.pi*(self.radius/self.x.unit)**2,
-                                        c=self.c.data,
+                                        c=c,
                                         vmin=self.vmin, vmax=self.vmax)
             self.colorbar = self.figure.colorbar(self.scat, format=F(self.c),
                                                  ax=self.ax)
@@ -223,9 +227,9 @@
         if self.plot_panel.c_key != colorVariable:
             self.plot_panel.c_key = colorVariable
             field = self.dataContainer[colorVariable]
-            vmin = field.data.min().round()*field.unit
+            vmin = numpy.nanmin(field.data).round()*field.unit
             self.vmin_text.Value=str(vmin)
-            vmax = field.data.max().round()*field.unit
+            vmax = numpy.nanmax(field.data).round()*field.unit
             self.vmax_text.Value=str(vmax)
         self.plot_panel.vmin = Quantity(self.vmin_text.Value)
         self.plot_panel.vmax = Quantity(self.vmax_text.Value)
Modified: trunk/src/workers/OSC/OSC/ComputeFunctional.py
===================================================================
--- trunk/src/workers/OSC/OSC/ComputeFunctional.py	2010-07-12 20:43:11 UTC (rev 695)
+++ trunk/src/workers/OSC/OSC/ComputeFunctional.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -57,7 +57,7 @@
     _params = [("extentX", u"Extension of x-axis [%%]", 10, None),
                ("extentY", u"Extension of y-axis [%%]", 10, None)]
 
-    def computeDistances(self, field, subscriber=1):
+    def computeDistances(self, field, subscriber=1, percentage=0):
         xGrid,yGrid = numpy.meshgrid(field.dimensions[-1].data,field.dimensions[-2].data)
         x    = numpy.extract(numpy.logical_not(numpy.isnan(field.data)),xGrid)
         xCon = DataContainer.FieldContainer(x,unit=field.dimensions[-1].unit,
@@ -80,8 +80,7 @@
         distances = numpy.zeros(x.shape,'f')
         ni = functional.shape[0]
         nj = functional.shape[1]
-        increment = 100.0/(ni*nj)
-        percentage = 0
+        increment = 50.0/(ni*nj)
         for i in xrange(ni):
             for j in xrange(nj):
                 for k in xrange(len(x)):
@@ -99,7 +98,8 @@
 
     @Worker.plug(Connectors.TYPE_ARRAY)
     def compute(self, field, subscriber=1):
-        functionals = DataContainer.SampleContainer([self.computeDistances(column, subscriber) for column in field],
+        percentage = 0
+        functionals = DataContainer.SampleContainer([self.computeDistances(column, subscriber, percentage) for column in field],
                                                     longname='Functionals of %s'%field.longname,
                                                     shortname='F_{%s}'%field.shortname)
         functionals.seal()
Added: trunk/src/workers/OSC/OSC/EstimateParameterFromValues.py
===================================================================
--- trunk/src/workers/OSC/OSC/EstimateParameterFromValues.py	                        (rev 0)
+++ trunk/src/workers/OSC/OSC/EstimateParameterFromValues.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -0,0 +1,140 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2008-2009, Rectorate of the University of Freiburg
+# Copyright (c) 2009, 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"""
+"""
+
+__id__ = "$Id$"
+__author__ = "$Author$"
+__version__ = "$Revision$"
+# $Source$
+
+import numpy
+from pyphant.core import (Worker, Connectors,
+                          Param, DataContainer)
+import scipy.interpolate
+from pyphant import quantities
+import copy
+
+class EstimateParameterFromValues(Worker.Worker):
+    API = 2
+    VERSION = 1
+    REVISION = "$Revision$"[11:-1]
+    name = "Estimate Parameter"
+
+    _sockets = [("model", Connectors.TYPE_ARRAY),
+                ("experimental", Connectors.TYPE_ARRAY)]
+    _params = [("minima_model", u"Minima in the model", [u"Minima"], None),
+               ("maxima_model", u"Maxima in the model", [u"Maxima"], None),
+               ("minima_experimental", u"Minima in the experiment", [u"Minima"], None),
+               ("maxima_experimental", u"Maxima in the experiment", [u"Maxima"], None),
+               ("extentX", u"Extension of x-axis [%%]", 10, None),
+               ("extentY", u"Extension of y-axis [%%]", 10, None)]
+
+    def refreshParams(self, subscriber=None):
+        if self.socketModel.isFull():
+            templ = self.socketModel.getResult( subscriber )
+            self.paramMinima_model.possibleValues = templ.longnames.keys()
+            self.paramMaxima_model.possibleValues = templ.longnames.keys()
+        if self.socketExperimental.isFull():
+            templ = self.socketExperimental.getResult( subscriber )
+            self.paramMinima_experimental.possibleValues = templ.longnames.keys()
+            self.paramMaxima_experimental.possibleValues = templ.longnames.keys()
+
+    @Worker.plug(Connectors.TYPE_IMAGE)
+    def compute(self, model, experimental, subscriber=1):
+        minima_model = model[self.paramMinima_model.value]
+        maxima_model = model[self.paramMaxima_model.value]
+        minima_experimental = experimental[self.paramMinima_experimental.value]
+        minima_experimantal = minima_experimental.inUnitsOf(minima_model)
+        minima = minima_experimental.data.transpose()
+        if minima_experimental.error != None:
+            minima_error = iter(minima_experimental.error.transpose())
+        else:
+            minima_error = None
+        maxima_experimental = experimental[self.paramMaxima_experimental.value]
+        maxima_experimantal = maxima_experimental.inUnitsOf(maxima_model)
+        maxima = maxima_experimental.data.transpose()
+        if maxima_experimental.error != None:
+            maxima_error = iter(maxima_experimental.error.transpose())
+        else:
+            maxima_error = None
+        parameter = []
+        inc = 100.0/float(len(minima))
+        acc = inc
+        subscriber %= acc
+        mask = []
+        for row_minima, row_maxima in zip(minima, maxima):
+            if minima_error:
+                filtered_minima_error = filter(
+                    lambda c: not numpy.isnan(c), minima_error.next())
+            else:
+                filtered_minima_error = None
+            if maxima_error:
+                filtered_maxima_error = filter(
+                    lambda c: not numpy.isnan(c), maxima_error.next())
+            else:
+                filtered_maxima_error = None
+            row_minima = numpy.array(filter(lambda c: not numpy.isnan(c), row_minima))
+            row_maxima = numpy.array(filter(lambda c: not numpy.isnan(c), row_minima))
+            grades = []
+            for rm_minima, rm_maxima in zip(minima_model.data.transpose(), maxima_model.data.transpose()):
+                rm_minima = filter(lambda c: not numpy.isnan(c), rm_minima)
+                rm_maxima = filter(lambda c: not numpy.isnan(c), rm_maxima)
+                grade = 0
+                if len(rm_minima) == len(row_minima):
+                    grade = sum(numpy.abs(numpy.array(rm_minima)-row_minima))
+                if len(rm_maxima) == len(row_maxima):
+                    grade += sum(numpy.abs(numpy.array(rm_maxima)-row_maxima))
+                if grade == 0:
+                    grades.append(numpy.nan)
+                    continue
+                grades.append(grade)
+                print grades[-1]
+            grades = numpy.array(grades)
+            i = numpy.nanargmin(grades)
+            if numpy.isnan(i):
+                mask.append(True)
+                parameter.append(numpy.nan)
+            else:
+                mask.append(False)
+                parameter.append(minima_model.dimensions[1].data[i])
+            acc += inc
+            subscriber %= acc
+        result = DataContainer.FieldContainer(
+            numpy.array(parameter),
+            mask = numpy.array(mask),
+            longname = minima_model.dimensions[-1].longname,
+            shortname = minima_model.dimensions[-1].shortname,
+            unit = minima_model.dimensions[-1].unit)
+        result.seal()
+        return result
Modified: trunk/src/workers/OSC/OSC/MRA.py
===================================================================
--- trunk/src/workers/OSC/OSC/MRA.py	2010-07-12 20:43:11 UTC (rev 695)
+++ trunk/src/workers/OSC/OSC/MRA.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -116,10 +116,18 @@
         convolvedField = convolveMRA(field, sigma)
         lastMinima = findMinima(convolvedField, numb_edge, lastMinima)
         lastMaxima = findMaxima(convolvedField, numb_edge, lastMaxima)
-    pos_minima = dim.data[numpy.array(lastMinima)+1]
-    error_minima = numpy.abs(pos_minima - dim.data[numpy.array(firstMinima)+1])
-    pos_maxima = dim.data[numpy.array(lastMaxima)+1]
-    error_maxima = numpy.abs(pos_maxima - dim.data[numpy.array(firstMaxima)+1])
+    if len(lastMinima)>0 and len(firstMinima)>0:
+        pos_minima = dim.data[numpy.array(lastMinima)+1]
+        error_minima = numpy.abs(pos_minima - dim.data[numpy.array(firstMinima)+1])
+    else:
+        pos_minima = numpy.array([],dtype=dim.data.dtype)
+        error_minima = numpy.array([],dtype=dim.data.dtype)
+    if len(lastMaxima)>0 and len(firstMaxima)>0:
+        pos_maxima = dim.data[numpy.array(lastMaxima)+1]
+        error_maxima = numpy.abs(pos_maxima - dim.data[numpy.array(firstMaxima)+1])
+    else:
+        pos_maxima = numpy.array([],dtype=dim.data.dtype)
+        error_maxima = numpy.array([],dtype=dim.data.dtype)
     return ((pos_minima, error_minima), (pos_maxima, error_maxima))
 
 def pos_error_to_data_container(p_e):
Modified: trunk/src/workers/OSC/OSC/OscAbsorption.py
===================================================================
--- trunk/src/workers/OSC/OSC/OscAbsorption.py	2010-07-12 20:43:11 UTC (rev 695)
+++ trunk/src/workers/OSC/OSC/OscAbsorption.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -73,6 +73,22 @@
         indexDict = IndexDict(offset,fmax,fstep)
     return (offset, fstep, indexDict)
 
+def removePeak(Abso, lower, upper):
+    dim = Abso.dimensions[-1]
+    minVal = lower/dim.unit
+    maxVal = upper/dim.unit
+    high_part = numpy.argwhere(minVal<dim.data).flatten()
+    low_part = numpy.argwhere(dim.data<maxVal).flatten()
+    lamp_interval = numpy.intersect1d(high_part, low_part)
+    min_index = lamp_interval[0]
+    max_index = lamp_interval[-1]
+    steps = max_index-min_index
+    for row in Abso.data:
+        min_value = row[min_index]
+        max_value = row[max_index]
+        step_size = (max_value-min_value)/steps
+        row[lamp_interval] = min_value + (lamp_interval-min_index)*step_size
+
 class OscAbsorptionCalculator(Worker.Worker):
     API = 2
     VERSION = 1
@@ -100,20 +116,12 @@
                                             shortname=ur'\tilde{A}')
         Abso.dimensions[-1] = I.dimensions[-1]
         if self.paramMask_lamp.value==1:
-            dim = Abso.dimensions[-1]
-            minVal = quantities.Quantity('654nm')/dim.unit
-            maxVal = quantities.Quantity('660nm')/dim.unit
-            high_part = numpy.argwhere(minVal<dim.data).flatten()
-            low_part = numpy.argwhere(dim.data<maxVal).flatten()
-            lamp_interval = numpy.intersect1d(high_part, low_part)
-            min_index = lamp_interval[0]
-            max_index = lamp_interval[-1]
-            steps = max_index-min_index
-            for row in Abso.data:
-                min_value = row[min_index]
-                max_value = row[max_index]
-                step_size = (max_value-min_value)/steps
-                row[lamp_interval] = min_value + (lamp_interval-min_index)*step_size
+            removePeak(Abso,
+                       quantities.Quantity('654nm'),
+                       quantities.Quantity('660nm'))
+            removePeak(Abso,
+                       quantities.Quantity('920nm'),
+                       quantities.Quantity('980nm'))
         Abso.seal()
         return Abso
 
Modified: trunk/src/workers/OSC/OSC/__init__.py
===================================================================
--- trunk/src/workers/OSC/OSC/__init__.py	2010-07-12 20:43:11 UTC (rev 695)
+++ trunk/src/workers/OSC/OSC/__init__.py	2010-07-12 21:47:51 UTC (rev 696)
@@ -45,6 +45,7 @@
     "ComputeFunctional",
     "ErrorEstimator",
     "EstimateParameter",
+    "EstimateParameterFromValues",
     "ExtremumFinder",
     "MRA",
     "OscAbsorption",
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |