Example #1
0
    def test10RegridRectToCurvBilinear(self):
        '''
        Tests the CurvRectRegridder.regridRectToCurv method using bilinear regridding
        '''
        regridder = CurvRectRegridder()

        # Test with only center data and no flags, using bilinear regridding
        regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats)
        regridder.assignCurvField()
        regridder.createRectGrid(self.rect_center_lons, self.rect_center_lats)
        regridder.assignRectField(self.rect_data)
        regrid_data = regridder.regridRectToCurv(self.undef_val,
                                                 ESMP.ESMP_REGRIDMETHOD_BILINEAR)
        expect_data = numpy.array(self.curv_data, dtype=numpy.float64)
        mismatch_found = False
        # Ignore outermost edges of curvilinear grid since
        # they aren't really well covered by the rectilinear grid
        # Also ignore the second east-most edge and second south-most edge;
        # also not covered
        for i in xrange(1, expect_data.shape[0] - 2):
            for j in xrange(2, expect_data.shape[1] - 1):
                if numpy.abs(expect_data[i, j] - regrid_data[i, j]) > 0.0003:
                    mismatch_found = True
                    print "expect = %#6.4f, found = %#6.4f for lon = %7.3f, " \
                          "lat = %7.3f" % (expect_data[i, j], regrid_data[i, j],
                          self.curv_center_lons[i][j], self.curv_center_lats[i][j])
        if mismatch_found:
            self.fail("data mismatch found")
Example #2
0
    def test11RegridRectToCurvPatch(self):
        '''
        Tests the CurvRectRegridder.regridRectToCurv method using patch regridding
        '''
        # Mark as the last test so ESMPControl().stopESMP will be called
        self.last_test = True

        regridder = CurvRectRegridder()

        # Test with only center data, and flags only on curvilinear centers,
        # using patch regridding
        regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats,
                                 self.curv_center_ignr)
        regridder.assignCurvField()
        regridder.createRectGrid(self.rect_center_lons, self.rect_center_lats)
        regridder.assignRectField(self.rect_data)
        regrid_data = regridder.regridRectToCurv(self.undef_val,
                                                 ESMP.ESMP_REGRIDMETHOD_PATCH)
        expect_data = numpy.array(self.curv_data, dtype=numpy.float64)
        undef_flags = numpy.array(self.curv_center_ignr, dtype=numpy.bool)
        expect_data[undef_flags] = self.undef_val
        mismatch_found = False
        # Ignore outermost edges of curvilinear grid since
        # they aren't really well covered by the rectilinear grid
        # Also ignore the second east-most edge and second south-most edge;
        # also not covered
        for i in xrange(1, expect_data.shape[0] - 2):
            for j in xrange(2, expect_data.shape[1] - 1):
                if numpy.abs(expect_data[i, j] - regrid_data[i, j]) > 0.0011:
                    mismatch_found = True
                    print "expect = %#6.4f, found = %#6.4f for lon = %7.3f, " \
                          "lat = %7.3f" % (expect_data[i, j], regrid_data[i, j],
                          self.curv_center_lons[i][j], self.curv_center_lats[i][j])
        if mismatch_found:
            self.fail("data mismatch found")
Example #3
0
    def test09RegridRectToCurvConserve(self):
        '''
        Tests the CurvRectRegridder.regridRectToCurv method using conservative regridding
        '''
        regridder = CurvRectRegridder()

        # Test with all corner and center data, using conservative regridding
        regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats,
                                 self.curv_center_ignr, self.curv_corner_lons,
                                 self.curv_corner_lats, self.curv_corner_ignr)
        regridder.assignCurvField()
        regridder.createRectGrid(self.rect_center_lons, self.rect_center_lats,
                                 self.rect_center_ignr, self.rect_corner_lons,
                                 self.rect_corner_lats, self.rect_corner_ignr)
        regridder.assignRectField(self.rect_data)
        regrid_data = regridder.regridRectToCurv(self.undef_val,
                                                 ESMP.ESMP_REGRIDMETHOD_CONSERVE)
        expect_data = numpy.array(self.curv_data, dtype=numpy.float64)
        undef_flags = numpy.array(self.curv_center_ignr, dtype=numpy.bool)
        expect_data[undef_flags] = self.undef_val
        # Couple "good" points next to ignored area are a bit wonky
        expect_data[1, 3] = self.undef_val
        regrid_data[1, 3] = self.undef_val
        expect_data[2, 3] = self.undef_val
        regrid_data[2, 3] = self.undef_val
        mismatch_found = False
        # Ignore outermost edges of curvilinear grid since
        # they aren't really well covered by the rectilinear grid
        # Also ignore the second east-most edge;
        # also not well covered and errors are larger 
        for i in xrange(1, expect_data.shape[0] - 2):
            for j in xrange(1, expect_data.shape[1] - 1):
                if numpy.abs(expect_data[i, j] - regrid_data[i, j]) > 0.0004:
                    mismatch_found = True
                    print "expect = %#6.4f, found = %#6.4f for lon = %7.3f, " \
                          "lat = %7.3f" % (expect_data[i, j], regrid_data[i, j], 
                          self.curv_center_lons[i][j], self.curv_center_lats[i][j])
        if mismatch_found:
            self.fail("data mismatch found")