Skip to content

Commit

Permalink
Regrid2#15 (#120)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dnadeau4 authored May 1, 2017
1 parent aae8ee6 commit 60891b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Lib/tvariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/test_gen_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import cdms2, numpy, os, sys
import basetest
import pdb


class TestGenericGrids(basetest.CDMSBaseTest):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_regrid2.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -59,15 +59,15 @@ 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)

# Dataset
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:
Expand All @@ -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)
Expand All @@ -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__":
Expand Down

0 comments on commit 60891b0

Please sign in to comment.