Exemplo n.º 1
0
 def testParabelArray(self):
     x = numpy.array([-2,-1,0,1,2],'float')
     field = numpy.array([(x-0.2)**2-0.5,(x+0.1)**2])
     inputField = DC.FieldContainer(field,
                                    error=numpy.resize(numpy.repeat(0.1,len(field)),field.shape),
                                    dimensions=[DC.FieldContainer(numpy.array([1,2]),
                                                                  longname='type',shortname=r'\theta'),
                                                DC.FieldContainer(x,longname='position',shortname='x')],
                                    longname='parabel',
                                    shortname='f')
     def error(y):
         error  = inputField.error[0,0] / (y[1]-2*y[2]+y[3])**2
         error *= numpy.abs(y[2]-y[3]) + numpy.abs(y[1]-y[3]) + numpy.abs(y[1]-y[2])
         return error
     expectedResult = DC.FieldContainer(numpy.array([[0.2,-0.1]]),
                                        longname = 'position of the local minima of parabel',
                                        shortname = 'x_0',
                                        error = numpy.array([[error(field[0]),error(field[1])]]))
     expectedResult.dimensions[-1] = DC.FieldContainer(numpy.array([1,2]),
                                                       longname='type',
                                                       shortname=r'\theta')
     w = EF.ExtremumFinder(None)
     w.paramExtremum.value=u'minima'
     #Retrieve result from worker
     result = w.locate(inputField)
     DC.assertEqual(result,expectedResult)
Exemplo n.º 2
0
 def testDistanceMappingInvertedStringDyDx(self):
     """
     Consider two features, which are divided by a vertical line.
     The respective distances increase by dx for each column counted
     from the centre line.
     """
     self.dydx = 0.01
     self.yDim = DataContainer.FieldContainer(numpy.linspace(
         -self.dydx, self.dydx, self.dim),
                                              unit='1m',
                                              longname='height',
                                              shortname='h')
     referenceField = DataContainer.FieldContainer(
         numpy.logical_not(stringFeature(self.dim, distanceToBorder=0)),
         dimensions=[self.xDim, self.yDim],
         unit='1',
         longname='Inverted String Feature',
         shortname='S')
     referenceField.seal()
     result = self.worker.calculateDistanceMap(referenceField)
     #Compute result afoot
     afoot = numpy.zeros(referenceField.data.shape, 'f')
     dx = numpy.diff(referenceField.dimensions[0].data)[0]
     for i in xrange(referenceField.data.shape[1]):
         afoot[:, i] = dx * abs(5 - i)
     afootC = DataContainer.FieldContainer(afoot,
                                           unit=self.xDim.unit,
                                           dimensions=map(
                                               copy.deepcopy,
                                               referenceField.dimensions))
     DataContainer.assertEqual(afootC, result)
Exemplo n.º 3
0
 def testDistanceMappingInvertedStringDyDx(self):
     """
     Consider two features, which are divided by a vertical line.
     The respective distances increase by dx for each column counted
     from the centre line.
     """
     self.dydx = 0.01
     self.yDim = DataContainer.FieldContainer(
         numpy.linspace(-self.dydx,self.dydx,self.dim),
         unit = '1m',
         longname= 'height',
         shortname='h')
     referenceField = DataContainer.FieldContainer(
         numpy.logical_not(stringFeature(self.dim,distanceToBorder=0)),
         dimensions = [self.xDim, self.yDim],
         unit = '1',
         longname='Inverted String Feature',
         shortname='S')
     referenceField.seal()
     result = self.worker.calculateDistanceMap(referenceField)
     #Compute result afoot
     afoot = numpy.zeros(referenceField.data.shape,'f')
     dx = numpy.diff(referenceField.dimensions[0].data)[0]
     for i in xrange(referenceField.data.shape[1]):
         afoot[:,i]= dx * abs(5-i)
     afootC=DataContainer.FieldContainer(afoot, unit=self.xDim.unit,
                                        dimensions = map(copy.deepcopy,referenceField.dimensions))
     DataContainer.assertEqual(afootC, result)
Exemplo n.º 4
0
 def testParabel(self):
     x = numpy.array([-2, -1, 0, 1, 2], 'float') + 0.1
     y = x**2
     inputField = DC.FieldContainer(y,
                                    error=numpy.repeat(0.1, len(y)),
                                    dimensions=[
                                        DC.FieldContainer(
                                            x,
                                            longname='abscissae',
                                            shortname='x')
                                    ],
                                    longname='parabel',
                                    shortname='f')
     error = inputField.error[slice(0, 1)] / (y[1] - 2 * y[2] + y[3])**2
     error *= numpy.abs(y[2] - y[3]) + numpy.abs(y[1] -
                                                 y[3]) + numpy.abs(y[1] -
                                                                   y[2])
     expectedResult = DC.FieldContainer(
         numpy.array([0.0]),
         longname='position of the local minimum of parabel',
         shortname='x_0',
         error=error)
     w = EF.ExtremumFinder(None)
     w.paramExtremum.value = u'minima'
     #Retrieve result from worker
     result = w.locate(inputField)
     DC.assertEqual(result, expectedResult)
Exemplo n.º 5
0
 def testMinima(self):
     """Test the correct computation of all local minima for a bistable potential."""
     #Predict result
     x0,curv,mask = fixedPoints(numpy.array([self.LAMBDA]),kappa1=self.kappa1)
     expectedResult = DC.FieldContainer(numpy.extract(curv[0]>0,x0[0]),
                                        unit = self.xField.unit,
                                        longname = 'position of the local minima of electric potential',
                                        shortname = 'x_0')
     #Retrieve result from worker
     w = EF.ExtremumFinder(None)
     w.paramExtremum.value=u'minima'
     result = w.locate(self.V)
     #Testing
     DC.assertEqual(result,expectedResult)
Exemplo n.º 6
0
 def testParabel(self):
     x = numpy.array([-2,-1,0,1,2],'float')+0.1
     y = x**2
     inputField = DC.FieldContainer(y,
                                    error=numpy.repeat(0.1,len(y)),
                                    dimensions=[DC.FieldContainer(x,longname='abscissae',shortname='x')],
                                    longname='parabel',
                                    shortname='f')
     error  = inputField.error[slice(0,1)] / (y[1]-2*y[2]+y[3])**2
     error *= numpy.abs(y[2]-y[3]) + numpy.abs(y[1]-y[3]) + numpy.abs(y[1]-y[2])
     expectedResult = DC.FieldContainer(numpy.array([0.0]),
                                        longname = 'position of the local minimum of parabel',
                                        shortname = 'x_0',
                                        error = error)
     w = EF.ExtremumFinder(None)
     w.paramExtremum.value=u'minima'
     #Retrieve result from worker
     result = w.locate(inputField)
     DC.assertEqual(result,expectedResult)
Exemplo n.º 7
0
 def testParabelSymmetricallyBoxedMinimum(self):
     x = numpy.array([-2,-1,0,1,2],'float')-0.5
     y = x**2
     inputField = DC.FieldContainer(y,
                                    error=numpy.repeat(0.1,len(y)),
                                    dimensions=[DC.FieldContainer(x,longname='abscissae',shortname='x')],
                                    longname='parabel',
                                    shortname='f'
                                    )
     expectedResult = DC.FieldContainer(numpy.array([0.0]),
                                        longname = 'position of the local minimum of parabel',
                                        shortname = 'x_0',
                                        error = numpy.array([0.1])
                                        )
     w = EF.ExtremumFinder(None)
     w.paramExtremum.value=u'minima'
     #Retrieve result from worker
     result = w.locate(inputField)
     DC.assertEqual(result,expectedResult)