Skip to content

Commit dc725e1

Browse files
dnadeau4doutriaux1
authored andcommitted
Issue#158 1 (#160)
* Fix CF-1 Conventions for GPCP * Fix GPCP and break other tests * Check dimension of coords and pep8 dataset.py * Add GPCP test * Delete fvariable default missing_value * change test for DRS * temporarly disable tests * create rectangular grid for axis of length 1 * fix GPCP grid * fix fill_value comparison to N/A * fix array comparison issue * remove space * add BaseException to try statement * limit axis and varname to 127 characters * limit axis and varname to 127 characters * limit axis and varname to 127 characters * get rid of pdb * pep8 dataset.py * pep8 crossSection.py from regrid2
1 parent 081d2ce commit dc725e1

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

Lib/dataset.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from tvariable import asVariable
2727
from cdmsNode import CdDatatypes
2828
import convention
29+
import warnings
2930

3031
# Default is serial mode until setNetcdfUseParallelFlag(1) is called
3132
rk = 0
@@ -1243,7 +1244,8 @@ def __init__(self, path, mode, hostObj=None, mpiBarrier=False):
12431244
lat, lon, gridname, parent=self, maskvar=maskvar)
12441245
except BaseException:
12451246
if(lat.rank() == 1 and lon.rank() == 1):
1246-
grid = FileRectGrid(self, gridname, lat, lon, gridkey[2], gridtype)
1247+
grid = FileRectGrid(
1248+
self, gridname, lat, lon, gridkey[2], gridtype)
12471249

12481250
self.grids[grid.id] = grid
12491251
self._gridmap_[gridkey] = grid
@@ -1432,6 +1434,11 @@ def copyAxis(self, axis, newname=None, unlimited=0,
14321434
if newname is None:
14331435
newname = axis.id
14341436

1437+
if len(newname) > 127:
1438+
msg = "axis name has more than 127 characters, name will be truncate"
1439+
warnings.warn(msg, UserWarning)
1440+
newname = newname[:127] if len(newname) > 127 else newname
1441+
14351442
# If the axis already exists and has the same values, return existing
14361443
if newname in self.axes:
14371444
newaxis = self.axes[newname]
@@ -1979,6 +1986,12 @@ def write(self, var, attributes=None, axes=None, extbounds=None, id=None,
19791986
varid = var.id
19801987
else:
19811988
varid = id
1989+
1990+
if len(varid) > 127:
1991+
msg = "varid name has more than 127 characters, name will be truncate"
1992+
warnings.warn(msg, UserWarning)
1993+
varid = varid[:127] if len(varid) > 127 else varid
1994+
19821995
if varid in self.variables:
19831996
if pack:
19841997
raise CDMSError(

regrid2/Lib/crossSection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __call__(self, ar, missing=None, order=None, method="log"):
232232

233233
# Reconstruct the same class as on input
234234
# Mask fill_value and return results
235-
print "INPUT IS VAR:",inputIsVariable
235+
print "INPUT IS VAR:", inputIsVariable
236236
if inputIsVariable == 1:
237237
result = numpy.ma.masked_values(outar, missing)
238238
result = cdms2.createVariable(result, fill_value=missing,
@@ -594,18 +594,18 @@ def generic_wts_bnds(lat):
594594
newLat = lat.clone()
595595
newLat.setBounds(None)
596596
bnds = lat.getBounds()
597-
except: # just an array....
597+
except BaseException:
598598
newLat = cdms2.createAxis(lat)
599599
newLat.setBounds(None)
600600
bnds = newLat.getBounds()
601-
outBnds = bnds[:,0].tolist()
601+
outBnds = bnds[:, 0].tolist()
602602
outBnds.append(bnds[-1][-1])
603603
outBnds = numpy.array(outBnds)
604-
wts = [ outBnds[i+1] - outBnds[i] for i in range(len(lat))]
604+
wts = [outBnds[i + 1] - outBnds[i] for i in range(len(lat))]
605605
wts = numpy.array(wts) / numpy.sum(wts)
606606
return wts, outBnds
607607

608-
608+
609609
def get_latitude_wts_bnds(checklatpass):
610610
""" #-------------------------------------------------------------------
611611
#

tests/test_gen_grid.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import sys
1010
import basetest
11-
import pdb
1211

1312

1413
class TestGenericGrids(basetest.CDMSBaseTest):

tests/test_longname.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import cdms2
2+
import os
3+
import numpy
4+
import cdat_info
5+
import basetest
6+
import MV2
7+
8+
9+
class TestFormats(basetest.CDMSBaseTest):
10+
11+
def testAxisID(self):
12+
a = MV2.ones((12,12))
13+
ax = cdms2.createAxis(MV2.arange(12))
14+
ax.id = "1234567890"*26
15+
a.setAxis(0,ax)
16+
with cdms2.open("bad.nc","w") as f:
17+
f.write(a)
18+
f=cdms2.open("bad.nc")
19+
listdim = f.listdimension()
20+
self.assertEqual(listdim[1], ax.id[0:127])
21+
f.close()
22+
23+
def testVarID(self):
24+
NLAT=16
25+
NLON=32
26+
latarr = numpy.ma.arange(NLAT) * (180. / (NLAT - 1)) - 90.
27+
lonarr = numpy.ma.arange(NLON) * (360.0 / NLON)
28+
timearr = numpy.ma.array([0.0, 366.0, 731.0])
29+
u = self.test_arr[0]
30+
tobj = cdms2.createAxis(id='time', data=timearr)
31+
tobj.units = 'days since 2000-1-1'
32+
latobj = cdms2.createAxis(id='latitude', data=latarr)
33+
latobj.units = 'degrees_north'
34+
lonobj = cdms2.createAxis(id='longitude', data=lonarr)
35+
lonobj.units = 'degrees_east'
36+
varid = "1234567890"*26
37+
var = cdms2.createVariable(u,id=varid, typecode=numpy.float, axes=(tobj, latobj, lonobj))
38+
var.units = 'm/s'
39+
with cdms2.open("bad.nc","w") as f:
40+
f.write(var)
41+
f.close()
42+
f=cdms2.open("bad.nc")
43+
listvar = f.listvariables()
44+
self.assertEqual(listvar[2], varid[:127])
45+
f.close()
46+
47+
def tearDown(self):
48+
os.unlink("bad.nc")
49+
50+
51+
52+
if __name__ == "__main__":
53+
basetest.run()

0 commit comments

Comments
 (0)