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")
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")
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")
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")
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")
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")
def test03AssignCurvField(self): ''' Tests the CurvRectRegridder.assignCurvGrid method. Since nothing is returned from this method, just checks for unexpected/expected Errors being raised. ''' regridder = CurvRectRegridder() # Test with all corner and center data 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.assignCurvField(self.curv_data) # Test without flags regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats, None, self.curv_corner_lons, self.curv_corner_lats) regridder.assignCurvField(self.curv_data) regridder.assignCurvField() # Test without corners regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats, self.curv_center_ignr) regridder.assignCurvField(self.curv_data) regridder.assignCurvField() # Test without corners or flags regridder.createCurvGrid(self.curv_center_lons, self.curv_center_lats) regridder.assignCurvField() regridder.assignCurvField(self.curv_data) # TODO: Test invalid cases # Done with this regridder regridder.finalize()
# expected results at the rectilinear centers for checking rect_expect_data = numpy.array(data[2:-2:2, 2:-2:2]) rect_expect_data[ ignore[2:-2:2, 2:-2:2] ] = undef_val # Create the curvilinear grid with corner and center points regridder.createCurvGrid(curv_center_lons, curv_center_lats, curv_center_ignore, curv_corner_lons, curv_corner_lats, None) # curv_corner_lons, curv_corner_lats, curv_corner_ignore) # Create the rectilinear grid with corner and center points regridder.createRectGrid(rect_center_lons, rect_center_lats, rect_center_ignore, 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,