From 60891b0580f7944c0db3f979dfafd3b11e48b561 Mon Sep 17 00:00:00 2001 From: Denis Nadeau Date: Mon, 1 May 2017 09:45:41 -0700 Subject: [PATCH] Regrid2#15 (#120) * fix #5 create Generic Grid for curvilinear grid * delete print * add bounds testing using assertTrue * fix#15 regrid2 with wrong default fill_value * fix test changing Regridder to Horizontal --- Lib/tvariable.py | 4 ++++ tests/test_gen_grid.py | 1 + tests/test_regrid2.py | 12 ++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Lib/tvariable.py b/Lib/tvariable.py index 2eb5c8ba..71328d19 100644 --- a/Lib/tvariable.py +++ b/Lib/tvariable.py @@ -278,12 +278,16 @@ def __new__(cls, data, typecode=None, copy=0, savespace=0, data = numpy.ma.masked.data mask = numpy.ma.masked.mask + if dtype is None and data is not None: + dtype = numpy.array(data).dtype + if fill_value in ["N/A"]: fill_value = None if fill_value is not None: fill_value = numpy.array(fill_value).astype(dtype) else: fill_value = numpy.ma.MaskedArray(1).astype(dtype).item() + fill_value = numpy.ma.default_fill_value(fill_value) self = numpy.ma.MaskedArray.__new__(cls, data, dtype=dtype, copy=ncopy, diff --git a/tests/test_gen_grid.py b/tests/test_gen_grid.py index 13fdf441..690a147e 100644 --- a/tests/test_gen_grid.py +++ b/tests/test_gen_grid.py @@ -6,6 +6,7 @@ import cdms2, numpy, os, sys import basetest +import pdb class TestGenericGrids(basetest.CDMSBaseTest): diff --git a/tests/test_regrid2.py b/tests/test_regrid2.py index 99327541..7754dc1d 100755 --- a/tests/test_regrid2.py +++ b/tests/test_regrid2.py @@ -1,6 +1,6 @@ import cdms2, numpy.ma, regrid2 as regrid, os, sys -from regrid2 import Regridder +from regrid2 import Horizontal import numpy import basetest @@ -17,7 +17,7 @@ def testRegrid2(self): sh = ingrid.shape - regridf = Regridder(ingrid, outgrid) + regridf = Horizontal(ingrid, outgrid) newu = regridf(u) self.assertLess(abs(newu[0,0,-1]-488.4763488), 1.e-3) @@ -59,7 +59,7 @@ def testRegrid2(self): # Set the input grid mask ingrid.setMask(mask) - regridf2 = Regridder(ingrid, outgrid) + regridf2 = Horizontal(ingrid, outgrid) newar = regridf2(numar) self.assertLess(abs(newar[0][-1]-488.4763488), 1.e-3) @@ -67,7 +67,7 @@ def testRegrid2(self): g = self.getDataFile('test.xml') u = g.variables['u'] outgrid = cdms2.createGaussianGrid(24) - regridf3 = Regridder(u.getGrid(), outgrid) + regridf3 = Horizontal(u.getGrid(), outgrid) try: unew = regridf3(u) except: @@ -94,7 +94,7 @@ def testRegrid2(self): var = cdms2.createVariable(dat, axes=(lev,g), attributes={'units':'N/A'}, id='test') result = var.pressureRegrid(levout) - #self.assertLess(abs(result[0,0,0]-3.26185), 1.e-4) + self.assertLess(abs(result[0,0,0]-3.26185), 1.e-4) # Test cross-section regridder -------------------------------- latin = cdms2.createGaussianAxis(16) latout = cdms2.createGaussianAxis(24) @@ -108,7 +108,7 @@ def testRegrid2(self): dat[2] = 6.0 var = cdms2.createVariable(dat, axes=(lev,latin), attributes={'units':'N/A'}, id='test') dat2 = var.crossSectionRegrid(levout, latout) - #self.assertLess(abs(dat2[0,0]-3.26185), 1.e-4) + self.assertLess(abs(dat2[0,0]-3.26185), 1.e-4) if __name__ == "__main__":