Skip to content

Commit

Permalink
fix #5 create Generic Grid for curvilinear grid (#119)
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

* remove import pdb from test
  • Loading branch information
dnadeau4 authored and doutriaux1 committed Apr 26, 2017
1 parent d41c270 commit 604df9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,12 +1465,12 @@ def genGenericBounds(self, width=1.0):
bnds = numpy.array([self[0]-delta,self[0]+delta])

# Transform to (n,2) array
retbnds = numpy.zeros((len(ar),2),numpy.float64)
retbnds[:,0] = bnds[:-1]
retbnds[:,1] = bnds[1:]
retbnds = numpy.zeros((ar.shape+(2,)),numpy.float64)
retbnds[...,0] = bnds[:-1]
retbnds[...,1] = bnds[1:]
# To avoid floating point error on bound limits

if( self.isLongitude() and hasattr(self, 'units') and (self.units.find('degree') != -1)):
if(self.isLongitude() and hasattr(self, 'units') and (self.units.find('degree') != -1) and len(retbnds.shape)==2):
# Make sure we have close to 360 degree interval
if( abs(abs(retbnds[-1,1] - retbnds[0,0]) -360) < (numpy.minimum(0.01, abs(retbnds[0,1] - retbnds[0,0])*0.1))):
# Now check wether either bound is near an interger value;
Expand All @@ -1493,8 +1493,8 @@ def genGenericBounds(self, width=1.0):

if( (self.isLatitude() and getAutoBounds()) or
(self.isLatitude() and hasattr(self, 'units') and (self.units.find('degree') != -1))):
retbnds[0,:] = numpy.maximum(-90.0, numpy.minimum(90.0,retbnds[0,:]))
retbnds[-1,:] = numpy.maximum(-90.0, numpy.minimum(90.0,retbnds[-1,:]))
retbnds[0,...] = numpy.maximum(-90.0, numpy.minimum(90.0,retbnds[0,...]))
retbnds[-1,...] = numpy.maximum(-90.0, numpy.minimum(90.0,retbnds[-1,...]))

return retbnds

Expand Down
14 changes: 14 additions & 0 deletions tests/test_gen_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@


class TestGenericGrids(basetest.CDMSBaseTest):
def testGenGrids2(self):
latb = [ 62.47686472, 69.70600048]
lonb = [ 102.87075526, 105.51598035]
fn = self.getDataFile('sampleCurveGrid4.nc')
s=fn("sample")
g=s.getGrid()
lat=g.getLatitude()
lon=g.getLongitude()
g2=cdms2.createGenericGrid(lat, lon)
datalat = g2.getLatitude().getBounds()[22,25]
datalon = g2.getLongitude().getBounds()[22,25]
self.assertTrue(numpy.ma.allclose(datalat, latb))
self.assertTrue(numpy.ma.allclose(datalon, lonb))

def testGenGrids(self):

datb = numpy.array([ 693., 694.,])
Expand Down

0 comments on commit 604df9a

Please sign in to comment.