diff --git a/Lib/axis.py b/Lib/axis.py index 70625b77..ce4c3c9a 100644 --- a/Lib/axis.py +++ b/Lib/axis.py @@ -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; @@ -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 diff --git a/tests/test_gen_grid.py b/tests/test_gen_grid.py index 0808a47d..13fdf441 100644 --- a/tests/test_gen_grid.py +++ b/tests/test_gen_grid.py @@ -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.,])