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, longname=field.dimensions[-1].longname, shortname=field.dimensions[-1].shortname) y = numpy.extract(numpy.logical_not(numpy.isnan(field.data)),field.data) yCon = DataContainer.FieldContainer(y,longname=field.longname, shortname=field.shortname, unit=field.unit) xOff, xStep, xInd = OA.grid2Index(x, self.paramExtentX.value) yOff, yStep, yInd = OA.grid2Index(y, self.paramExtentY.value) xMax = xInd.maxV yMax = yInd.maxV xDim = DataContainer.FieldContainer( numpy.linspace(xInd.minV,xInd.maxV,xInd.stepCount), xCon.unit, longname = xCon.longname, shortname = xCon.shortname ) yDim = DataContainer.FieldContainer( numpy.linspace(yInd.minV,yInd.maxV,yInd.stepCount), yCon.unit, longname = yCon.longname, shortname = yCon.shortname ) functional = numpy.ones((xInd.stepCount, yInd.stepCount), dtype='float') distances = numpy.zeros(x.shape,'f') ni = functional.shape[0] nj = functional.shape[1] increment = 50.0/(ni*nj) for i in xrange(ni): for j in xrange(nj): for k in xrange(len(x)): distances[k] = numpy.sqrt((x[k]-xDim.data[i])**2+ (y[k]-yDim.data[j])**2) functional[i,j]=distances.min() percentage += increment subscriber %= percentage result = DataContainer.FieldContainer(functional.transpose(), dimensions=[yDim, xDim], longname = 'functional of %s'%field.longname, shortname= 'F_{%s}'%field.shortname ) return result
def testSignificantNoise(self): """Tests the conservation of abscissae data in case of significant deviation.""" worker = OA.OscAbsorptionCalculator() worker.paramClipping.value = 0 self.sampleC['I'].dimensions[-1].data += numpy.random.randn(self.n) self.sampleC.seal() result = worker.calcAbsorption(self.sampleC) expectedDim = copy.deepcopy(self.sampleC['I'].dimensions) expectedResult = DC.FieldContainer(numpy.ones( (self.m, self.n), 'float') - self.I.data, dimensions=expectedDim, longname=u'absorption', shortname=ur'\tilde{A}') self.assertEqual(result, expectedResult)
def testCalculation(self): """Tests the correct calculation of absorption without clipping. It is assumed, that the dark reference intensity is equal to zero, while white reference intensity is equal to one.""" worker = OA.OscAbsorptionCalculator() worker.paramClipping.value = 0 self.sampleC.seal() result = worker.calcAbsorption(self.sampleC) expectedDim = [ DC.generateIndex(1, self.m), DC.FieldContainer(self.x, longname='position', shortname='x', unit='1m') ] expectedResult = DC.FieldContainer(numpy.ones( (self.m, self.n), 'float') - self.I.data, dimensions=expectedDim, longname=u'absorption', shortname=ur'\tilde{A}') self.assertEqual(result, expectedResult)
def testNegligibleNoise(self): """Tests the merging of abscissae data in case of negliglible deviation.""" worker = OA.OscAbsorptionCalculator() worker.paramClipping.value = 0 self.sampleC['I'].dimensions[-1].data += 1e-8 * numpy.random.randn( self.n) self.sampleC.seal() result = worker.calcAbsorption(self.sampleC) expectedDim = [ DC.generateIndex(1, self.m), DC.FieldContainer(self.x, longname='position', shortname='x', unit='1m') ] expectedResult = DC.FieldContainer(numpy.ones( (self.m, self.n), 'float') - self.I.data, dimensions=expectedDim, longname=u'absorption', shortname=ur'\tilde{A}') self.assertEqual(result, expectedResult)