コード例 #1
0
ファイル: regrid2dtests.py プロジェクト: PBrockmann/PyFerret
    def test08RegridCurvToRectPatch(self):
        '''
        Tests the CurvRectRegridder.regridCurvToRect method using patch regridding
        '''
        regridder = CurvRectRegridder()

        # Test with only center data, and flags only on rectilinear centers,
        # using patch regridding
        regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats)
        regridder.assignCurvField(self.curv_data)
        regridder.createRectGrid(self.rect_center_lons, self.rect_center_lats,
                                 self.rect_center_ignr)
        regridder.assignRectField()
        regrid_data = regridder.regridCurvToRect(self.undef_val,
                                                 ESMP.ESMP_REGRIDMETHOD_PATCH)
        expect_data = numpy.array(self.rect_data, dtype=numpy.float64)
        undef_flags = numpy.array(self.rect_center_ignr, dtype=numpy.bool)
        expect_data[undef_flags] = self.undef_val
        # one point falls outside the curvilinear centerpoints grid?
        expect_data[5, 0] = self.undef_val
        mismatch_found = False
        for i in xrange(expect_data.shape[0]):
            for j in xrange(expect_data.shape[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 = %5.1f, " \
                          "lat = %5.1f" % (expect_data[i, j], regrid_data[i, j],
                           self.rect_center_lons[i], self.rect_center_lats[j])
        if mismatch_found:
            self.fail("data mismatch found")
コード例 #2
0
ファイル: regrid2dtests.py プロジェクト: PBrockmann/PyFerret
    def test06RegridCurvToRectConserve(self):
        '''
        Tests the CurvRectRegridder.regridCurvToRect 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(self.curv_data)
        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()
        regrid_data = regridder.regridCurvToRect(self.undef_val, 
                                                 ESMP.ESMP_REGRIDMETHOD_CONSERVE)
        expect_data = numpy.array(self.rect_data, dtype=numpy.float64)
        undef_flags = numpy.array(self.rect_center_ignr, dtype=numpy.bool)
        expect_data[undef_flags] = self.undef_val
        mismatch_found = False
        # Couple "good" points next to ignored data area are a bit wonky
        expect_data[2, 0] = self.undef_val
        regrid_data[2, 0] = self.undef_val
        expect_data[2, 1] = self.undef_val
        regrid_data[2, 1] = self.undef_val
        for i in xrange(expect_data.shape[0]):
            for j in xrange(expect_data.shape[1]):
                if numpy.abs(expect_data[i, j] - regrid_data[i, j]) > 0.0007:
                    mismatch_found = True
                    print "expect = %#6.4f, found = %#6.4f for lon = %5.1f, " \
                          "lat = %5.1f" % (expect_data[i, j], regrid_data[i, j],
                           self.rect_center_lons[i], self.rect_center_lats[j])
        if mismatch_found:
            self.fail("data mismatch found")
コード例 #3
0
ファイル: regrid2dtests.py プロジェクト: PBrockmann/PyFerret
    def test07RegridCurvToRectBilinear(self):
        '''
        Tests the CurvRectRegridder.regridCurvToRect 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(self.curv_data)
        regridder.createRectGrid(self.rect_center_lons, self.rect_center_lats)
        regridder.assignRectField()
        regrid_data = regridder.regridCurvToRect(self.undef_val,
                                                 ESMP.ESMP_REGRIDMETHOD_BILINEAR)
        expect_data = numpy.array(self.rect_data, dtype=numpy.float64)
        mismatch_found = False
        # one point falls outside the curvilinear centerpoints grid?
        expect_data[5, 0] = self.undef_val
        for i in xrange(expect_data.shape[0]):
            for j in xrange(expect_data.shape[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 = %5.1f, " \
                          "lat = %5.1f" % (expect_data[i, j], regrid_data[i, j],
                           self.rect_center_lons[i], self.rect_center_lats[j])
        if mismatch_found:
            self.fail("data mismatch found")
コード例 #4
0
                             rect_corner_lons, rect_corner_lats, None)
#                             rect_corner_lons, rect_corner_lats, rect_corner_ignore)

    # Create the curvilinear source field
    regridder.assignCurvField(curv_data)

    # Create the rectilinear destination field
    regridder.assignRectField(None)

    # Generate the 2D rectilinear longitudes and latitudes arrays only to 
    # simplify printing differences; not used for regridding
    rect_2d_center_lats, rect_2d_center_lons = \
        numpy.meshgrid(rect_center_lats, rect_center_lons)

    # Regrid from curvilinear to rectilinear using the bilinear method
    rect_regrid_data = regridder.regridCurvToRect(undef_val, ESMP.ESMP_REGRIDMETHOD_BILINEAR)
    # Print the differences between the expected and regrid data
    print ""
    print "analytic (expect) versus bilinear regridded (found) differences"
    printDiffs(rect_2d_center_lons, rect_2d_center_lats, undef_val, max_negl,
               rect_expect_data, rect_regrid_data)

    # Regrid from curvilinear to rectilinear using the patch method
    rect_regrid_data = regridder.regridCurvToRect(undef_val, ESMP.ESMP_REGRIDMETHOD_PATCH)
    # Print the differences between the expected and regrid data
    print ""
    print "analytic (expect) versus patch regridded (found) differences"
    printDiffs(rect_2d_center_lons, rect_2d_center_lats, undef_val, max_negl,
               rect_expect_data, rect_regrid_data)

    # Regrid from curvilinear to rectilinear using the conserve method