Example #1
0
    def test_270degRotation3D(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((4, 2))
        highResCellGrid[3, :] = 0
        highResCellGrid[1, 1] = 0
        xs = np.array(range(2)) + xoff
        ys = np.array(range(4)) + yoff
        highResCellGrid = np.dstack(
            (highResCellGrid, highResCellGrid, highResCellGrid))
        freqs = np.array([.1, .2, .3])
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid, freqs=freqs)

        lowresDx = 1.3
        lowresDy = 3.3
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        direction = 290. / 180. * np.pi

        trfrm = abFirstOctantTransformation(hiResAlphaMtx, cellPoly)
        rtheta, rmtx, rcell = trfrm.transform(direction)

        if plotResults:
            plot('original', hiResAlphaMtx, direction)
            plot('transformed', rmtx, rtheta)
            plt.show()

        expdir = 20. / 180. * np.pi
        self.assertAlmostEqual(expdir, rtheta)

        crds = list(cellPoly.boundary.coords)
        expcoord = [(-c[1], c[0]) for c in crds]
        rcellcoord = list(rcell.boundary.coords)
        for ec, rc in zip(expcoord, rcellcoord):
            self.assertAlmostEqual(ec, rc)

        expalpha = highResCellGrid.transpose((1, 0, 2))
        exprtmtx = alphaMtx(-ys, xs, expalpha, freqs=freqs)
        exprtmtx.polygon = rcell
        self.assertTrue(np.allclose(exprtmtx.alphas, rmtx.alphas))
        self.assertIs(exprtmtx.polygon, rmtx.polygon)
        self.assertTrue(np.allclose(exprtmtx.xs, rmtx.xs))
        self.assertTrue(np.allclose(exprtmtx.ys, rmtx.ys))
        self.assertEqual(exprtmtx.hasFreqs, rmtx.hasFreqs)
        self.assertIs(freqs, rmtx.freqs)
Example #2
0
    def test3(self):
        xoff = 30.
        yoff = 40.

        highResCellGrid = np.ones((5, 4))
        highResCellGrid[0, 0] = 0
        highResCellGrid[1, 1] = 0
        highResCellGrid[2, 2] = 0
        highResCellGrid[4, 3] = 0
        xs = np.array(range(4)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 4
        lowresDy = 5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        betaEst = be(cellPoly, hiResAlphaMtx, maxSubSections=100000)

        dr = np.arctan(.5)
        beta = betaEst.computeBeta(dr, .1)

        expbeta = rotatingTestBeta
        self.assertAlmostEqual(expbeta, beta, delta=.0001)
Example #3
0
    def test2(self):
        xoff = 30.
        yoff = 40.

        highResCellGrid = np.ones((5, 4))
        highResCellGrid[0, 0] = 0
        highResCellGrid[1, 1] = 0
        highResCellGrid[2, 2] = 0
        highResCellGrid[4, 3] = 0
        xs = np.array(range(4)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 4
        lowresDy = 5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        betaEst = be(cellPoly, hiResAlphaMtx)

        dr = np.pi / 4.
        beta = betaEst.computeBeta(dr, .1)

        expbeta = 0.72105087014725577
        self.assertAlmostEqual(expbeta, beta, delta=.0001)
Example #4
0
    def test_concavePolygon(self):
        xoff = 30.
        yoff = 40.

        highResCellGrid = np.ones((5, 4))
        highResCellGrid[2, 1] = 0
        xs = np.array(range(4)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 4
        lowresDy = 5
        vrtxxs = np.array([1., 3., 3., 1., 1., 2., 2., 1., 1.]) + xoff
        vrtxys = np.array([1., 1., 4., 4., 2.75, 2.75, 2.25, 2.25, 1.]) + yoff
        cellPolyVrtxs = [[c[0], c[1]] for c in zip(vrtxxs, vrtxys)]

        cellPoly = g.Polygon(cellPolyVrtxs)
        hiResAlphaMtx.polygon = cellPoly

        betaEst = be(cellPoly, hiResAlphaMtx)

        dr = np.arctan(.5)
        beta = betaEst.computeBeta(dr, .1)

        expbeta = 0.67258992805755391
        self.assertAlmostEqual(expbeta, beta, delta=.0001)
Example #5
0
    def test1(self):
        xoff = 30.
        yoff = 40.

        highResCellGrid = np.ones((5, 4))
        highResCellGrid[0, 0] = 0
        highResCellGrid[1, 1] = 0
        highResCellGrid[2, 2] = 0
        highResCellGrid[4, 3] = 0
        xs = np.array(range(4)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 4
        lowresDy = 5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        betaEst = be(cellPoly, hiResAlphaMtx)

        dr = 0
        beta = betaEst.computeBeta(dr, .1)

        alpha1 = .8
        alpha2 = .6
        alpha3 = .4
        alpha4 = .2
        expbeta = (alpha1 + alpha2 + alpha3 + alpha4) / 4
        self.assertAlmostEqual(expbeta, beta, delta=.0001)
Example #6
0
    def test_forthQuarter(self):
        xoff = 30.
        yoff = 40.

        highResCellGrid = np.ones((5, 4))
        highResCellGrid[0, 0] = 0
        highResCellGrid[1, 1] = 0
        highResCellGrid[2, 2] = 0
        highResCellGrid[4, 3] = 0
        highResCellGrid = highResCellGrid.transpose()
        highResCellGrid = highResCellGrid[:, ::-1]
        xs = np.array(range(5)) + xoff
        ys = np.array(range(4)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 5
        lowresDy = 4
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        betaEst = be(cellPoly, hiResAlphaMtx)

        dr = np.arctan(-2.) + np.pi
        beta = betaEst.computeBeta(dr, .1)

        expbeta = rotatingTestBeta
        self.assertAlmostEqual(expbeta, beta, delta=.0001)
    def test2(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((4, 2))
        highResCellGrid[0, :] = 0
        highResCellGrid[2, 1] = 0
        xs = np.array(range(2)) + xoff
        ys = np.array(range(4)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 1.3
        lowresDy = 3.3
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = -20. / 180. * np.pi
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)
        obstrE = (2. + .3 * abs(np.tan(direction))) * abs(np.cos(direction))
        obstrN = 1.3 * abs(np.sin(direction))
        expalpha = 1 - (obstrE + obstrN) / (1.3 * abs(np.sin(direction)) +
                                            3.3 * abs(np.cos(direction)))
        self.assertAlmostEqual(expalpha, alpha, delta=.001)
    def testConcavePolygonDoubleIntersectionHiResCell(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 2] = 0

        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        xvtxs = [21., 22.25, 22.25, 22.75, 22.75, 24., 24., 21., 21.]
        yvtxs = [11., 11., 12., 12., 11., 11., 13., 13., 11.]
        xyvtxs = [xy for xy in zip(xvtxs, yvtxs)]
        cellPoly = g.Polygon(xyvtxs)
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = np.pi / 2
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        expalpha = 2.5 / 3.
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def testConcavePolygon1(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 1] = 0
        highResCellGrid[1, 3] = 0

        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        xvtxs = [21., 22., 22., 23., 23., 24., 24., 21., 21.]
        yvtxs = [11., 11., 12., 12., 11., 11., 13., 13., 11.]
        xyvtxs = [xy for xy in zip(xvtxs, yvtxs)]
        cellPoly = g.Polygon(xyvtxs)
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = np.arctan(2)
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        trndir = np.arctan(.5)
        obstrE = 2. * np.cos(trndir)
        obstrN = 2. * np.sin(trndir)
        expalpha = 1 - (obstrE + obstrN) / (2. * abs(np.sin(trndir)) +
                                            3. * abs(np.cos(trndir)))
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def testPentagonalCell1(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 3] = 0
        highResCellGrid[2, 1] = 0
        highResCellGrid[3, 2] = 0

        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        xvtxs = [21.5, 22., 23.5, 23., 22.5]
        yvtxs = [12.5, 12., 11.5, 13., 13.5]
        xyvtxs = [xy for xy in zip(xvtxs, yvtxs)]
        cellPoly = g.Polygon(xyvtxs)
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = np.arctan(.5)
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        #total cross section of the cell with respect to direction:
        ltot = (5.)**.5
        #transparent section of the cell:
        ltrs = (1. / 5.)**.5
        expalpha = ltrs / ltot
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def testPentagonalCell(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 3] = 0
        highResCellGrid[2, 1] = 0
        highResCellGrid[3, 2] = 0

        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        xvtxs = [21.5, 22., 23.5, 23., 22.5]
        yvtxs = [12.5, 12., 11.5, 13., 13.5]
        xyvtxs = [xy for xy in zip(xvtxs, yvtxs)]
        cellPoly = g.Polygon(xyvtxs)
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = np.pi / 4.
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        expalpha = 1. / 3.
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def testTriangularCell(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 3] = 0
        highResCellGrid[2, 1] = 0
        highResCellGrid[3, 2] = 0

        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        xvtxs = [23.5, 24., 22.]
        yvtxs = [11., 13., 14]
        xyvtxs = [xy for xy in zip(xvtxs, yvtxs)]
        cellPoly = g.Polygon(xyvtxs)
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = np.pi / 4.
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        obstrE = 1.5 * np.cos(direction)
        obstrN = 2. * np.sin(direction)
        expalpha = 1 - (obstrE + obstrN) / (2.5 * abs(np.sin(direction)) +
                                            2. * abs(np.cos(direction)))
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def testDifferentHighResDxDy_quadrant4(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((4, 2))
        highResCellGrid[0, :] = 0
        highResCellGrid[2, 1] = 0
        highResCellGrid = highResCellGrid.transpose()[::-1, ::-1]
        xs = np.array(range(4)) * .5 + xoff
        ys = np.array(range(2)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDy = 1.3
        lowresDx = 3.3 * .5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = 20. / 180. * np.pi + np.pi * 3. / 2.
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)

        turneddir = 20. / 180. * np.pi
        obstrE = (.65 + 2.3 * np.tan(turneddir)) * np.cos(turneddir)
        obstrN = 0.
        expalpha = 1 - (obstrE + obstrN) / (1.3 * abs(np.sin(turneddir)) +
                                            3.3 * .5 * abs(np.cos(turneddir)))
        self.assertAlmostEqual(expalpha, alpha, delta=0.001)
    def test0radiants(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 3] = 0.
        highResCellGrid[2, 1] = 0.
        highResCellGrid[3, 2] = 0.
        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 5
        lowresDy = 5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = 0.
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)
        expalpha = 2. / 5.
        self.assertEqual(expalpha, alpha, .001)
    def testMultipleOverlaps(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((5, 5))
        highResCellGrid[1, 1] = 0
        highResCellGrid[1, 3] = 0
        highResCellGrid[2, 1] = 0
        highResCellGrid[2, 2] = 0
        highResCellGrid[3, 2] = 0
        highResCellGrid[3, 3] = 0
        xs = np.array(range(5)) + xoff
        ys = np.array(range(5)) + yoff
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid)

        lowresDx = 5
        lowresDy = 5
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        alphaEst = ae(cellPoly, hiResAlphaMtx)

        direction = math.atan(.5)
        alpha = alphaEst.computeAlpha(direction, .1)
        self.assertTrue(alpha > 0)
        obstrE = 3.5 * np.cos(direction)
        obstrN = 1. * np.sin(direction)
        expalpha = 1 - (obstrE + obstrN) / 5 / (abs(np.sin(direction)) +
                                                abs(np.cos(direction)))
        self.assertAlmostEqual(expalpha, alpha, delta=.001)
Example #16
0
    def test_noTransform2D(self):
        xoff = 20.
        yoff = 10.

        highResCellGrid = np.ones((4, 2))
        highResCellGrid[3, :] = 0
        highResCellGrid[1, 1] = 0
        xs = np.array(range(2)) + xoff
        ys = np.array(range(4)) + yoff
        freqs = None
        hiResAlphaMtx = alphaMtx(xs, ys, highResCellGrid, freqs=freqs)

        lowresDx = 1.3
        lowresDy = 3.3
        cellPoly = g.Polygon(\
                    [[xoff, yoff], [xoff + lowresDx, yoff],\
                    [xoff + lowresDx, yoff + lowresDy], [xoff, yoff + lowresDy]])
        hiResAlphaMtx.polygon = cellPoly

        direction = 20. / 180. * np.pi

        trfrm = abFirstOctantTransformation(hiResAlphaMtx, cellPoly)
        rtheta, rmtx, rcell = trfrm.transform(direction)

        expdir = direction
        self.assertAlmostEqual(expdir, rtheta)

        expcoord = list(cellPoly.boundary.coords)
        rcellcoord = list(rcell.boundary.coords)
        for ec, rc in zip(expcoord, rcellcoord):
            self.assertAlmostEqual(ec, rc)

        exprtmtx = hiResAlphaMtx
        self.assertTrue(np.allclose(exprtmtx.alphas, rmtx.alphas))
        self.assertIs(exprtmtx.polygon, rmtx.polygon)
        self.assertTrue(np.allclose(exprtmtx.xs, rmtx.xs))
        self.assertTrue(np.allclose(exprtmtx.ys, rmtx.ys))
        self.assertEqual(exprtmtx.hasFreqs, rmtx.hasFreqs)
        self.assertIs(freqs, rmtx.freqs)
        self.assertTrue(rmtx.xs[0] < rmtx.xs[-1])
        self.assertTrue(rmtx.ys[0] < rmtx.ys[-1])