Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5 create Generic Grid for curvilinear grid #119

Merged
merged 4 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's neat! I never realized you could do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still learning Eh?

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
15 changes: 15 additions & 0 deletions tests/test_gen_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@

import cdms2, numpy, os, sys
import basetest
import pdb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done



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