diff --git a/Lib/axis.py b/Lib/axis.py index cddee3da..5fd35bb7 100644 --- a/Lib/axis.py +++ b/Lib/axis.py @@ -656,10 +656,11 @@ def designateLatitude(self, persistent=0): # Return true iff the axis is a latitude axis def isLatitude(self): id = self.id.strip().lower() - if (hasattr(self,'axis') and self.axis=='Y'): return 1 + if (hasattr(self,'axis') and self.axis=='Y'): return True units = getattr(self,"units","").strip().lower() - if units in ["degrees_north","degree_north","degree_n","degrees_n","degreen","degreesn"]: - return 1 + if units in ["degrees_north","degree_north","degree_n","degrees_n","degreen","degreesn"] and \ + not (self.isLongitude() or self.isLevel() or self.isTime()): + return True return (id[0:3] == 'lat') or (id in latitude_aliases) # Designate axis as a vertical level axis @@ -674,16 +675,16 @@ def designateLevel(self, persistent=0): # Return true iff the axis is a level axis def isLevel(self): id = self.id.strip().lower() - if (hasattr(self,'axis') and self.axis=='Z'): return 1 + if (hasattr(self,'axis') and self.axis=='Z'): return True if getattr(self,"positive","").strip().lower() in ["up","down"]: - return 1 + return True try: #Ok let's see if this thing as pressure units import genutil p=genutil.udunits(1,"Pa") units=getattr(self,'units',"").strip() p2=p.to(units) - return 1 + return True except Exception,err: pass return ((id[0:3] == 'lev') or (id[0:5] == 'depth') or (id in level_aliases)) @@ -714,10 +715,11 @@ def designateLongitude(self, persistent=0, modulo=360.0): # Return true iff the axis is a longitude axis def isLongitude(self): id = self.id.strip().lower() - if (hasattr(self,'axis') and self.axis=='X'): return 1 + if (hasattr(self,'axis') and self.axis=='X'): return True units = getattr(self,"units","").strip().lower() - if units in ["degrees_east","degree_east","degree_e","degrees_e","degreee","degreese"]: - return 1 + if units in ["degrees_east","degree_east","degree_e","degrees_e","degreee","degreese"] and \ + not (self.isLatitude() or self.isLevel() or self.isTime()): + return True return (id[0:3] == 'lon') or (id in longitude_aliases) # Designate axis as a time axis, and optionally set the calendar @@ -743,14 +745,14 @@ def designateTime(self, persistent=0, calendar=None): def isTime(self): id = self.id.strip().lower() if hasattr(self,'axis'): - if self.axis=='T': return 1 - elif self.axis is not None: return 0 + if self.axis=='T': return True + elif self.axis is not None: return False # Have we saved the id-to-axis type information already? if id in self.idtaxis: if self.idtaxis[id]=='T': - return 1 + return True else: - return 0 + return False ## Try to figure it out from units try: import genutil @@ -761,26 +763,26 @@ def isTime(self): s = sp[0].strip() if s in t.available_units() and t.known_units()[s]=="TIME": self.idtaxis[id] = 'T' - return 1 + return True #try the plural version since udunits only as singular (day noy days) s=s+"s" if s in t.available_units() and t.known_units()[s]=="TIME": self.idtaxis[id] = 'T' - return 1 + return True except: pass #return (id[0:4] == 'time') or (id in time_aliases) if (id[0:4] == 'time') or (id in time_aliases): self.idtaxis[id]='T' - return 1 + return True else: self.idtaxis[id] = 'O' - return 0 + return False # Return true iff the axis is a forecast axis def isForecast(self): id = self.id.strip().lower() - if (hasattr(self,'axis') and self.axis=='F'): return 1 + if (hasattr(self,'axis') and self.axis=='F'): return True return (id[0:6] == 'fctau0') or (id in forecast_aliases) def isForecastTime(self): return self.isForecast() @@ -917,10 +919,10 @@ def isCircularAxis(self): def isCircular(self): if hasattr(self,'realtopology'): - if self.realtopology=='circular': return 1 - elif self.realtopology=='linear': return 0 + if self.realtopology=='circular': return True + elif self.realtopology=='linear': return False if(len(self) < 2): - return 0 + return False try: # non float types will fail this baxis = self[0] @@ -1530,7 +1532,7 @@ def info(self, flag=None, device=None): def isVirtual(self): "Return true iff coordinate values are implicitly defined." - return 0 + return False shape = property(_getshape,None) dtype = _getdtype @@ -1762,7 +1764,7 @@ def setBounds(self, bounds, persistent=0, validate=0, index=None, boundsid=None, self._bounds_ = None def isLinear(self): - return 0 + return False def typecode(self): return self._data_.dtype.char @@ -1794,11 +1796,11 @@ def getData(self): return numpy.arange(float(self._virtualLength)) def isCircular(self): - return 0 # Circularity doesn't apply to index space. + return False # Circularity doesn't apply to index space. def isVirtual(self): "Return true iff coordinate values are implicitly defined." - return 1 + return True def setBounds(self, bounds, isGeneric=False): "No boundaries on virtual axes" @@ -2005,7 +2007,7 @@ def __len__(self): return length def isLinear(self): - return 0 # All file axes are vector representation + return False # All file axes are vector representation # Return the bounds array, or generate a default if autobounds mode is set # If isGeneric is a list with one element, we set its element to True if the @@ -2103,7 +2105,7 @@ def isVirtual(self): # No virtual axes in GrADS files if self.parent is not None and hasattr(self.parent, 'format') and self.parent.format=='GRADS': - return 0 + return False return (self._obj_ is None) def isUnlimited(self): @@ -2138,7 +2140,7 @@ def getData(self): def isVirtual(self): "Return true iff coordinate values are implicitly defined." - return 1 + return True ## PropertiedClasses.initialize_property_class (FileVirtualAxis) @@ -2320,7 +2322,7 @@ def axisMatches(axis, specification): raise CDMSError, 'Malformed axis spec, ' + specification s = s[1:-1].strip() if string.lower(axis.id) == s: - return 1 + return True elif (s == 'time') or (s in time_aliases): return axis.isTime() elif (s == 'fctau0') or (s in forecast_aliases): @@ -2332,14 +2334,14 @@ def axisMatches(axis, specification): elif (s[0:3] == 'lev') or (s in level_aliases): return axis.isLevel() else: - return 0 + return False elif isinstance(specification, types.FunctionType): r = specification(axis) if r: - return 1 + return True else: - return 0 + return False elif isinstance(specification, AbstractAxis): return (specification is axis) diff --git a/Lib/convention.py b/Lib/convention.py index 4e8c9053..83f207dd 100644 --- a/Lib/convention.py +++ b/Lib/convention.py @@ -190,21 +190,21 @@ def getVarLonId(self, var, vardict): def axisIsLatitude(self, axis): if (hasattr(axis,'axis') and axis.axis=='Y'): - return 1 - elif (hasattr(axis, 'units') and string.lower(axis.units) in ['degrees_north', 'degree_north', 'degree_n', 'degrees_n', 'degreen', 'degreesn']): - return 1 + return True + elif (hasattr(axis, 'units') and string.lower(axis.units) in ['degrees_north', 'degree_north', 'degree_n', 'degrees_n', 'degreen', 'degreesn'] and not (axis.isLongitude() or axis.isLevel() or axis.isTime())): + return True elif (hasattr(axis, 'standard_name') and string.lower(axis.standard_name)=='latitude'): - return 1 + return True else: return AbstractConvention.axisIsLatitude(self, axis) def axisIsLongitude(self, axis): if (hasattr(axis,'axis') and axis.axis=='X'): - return 1 - elif (hasattr(axis, 'units') and string.lower(axis.units) in ['degrees_east', 'degree_east', 'degree_e', 'degrees_e', 'degreee', 'degreese']): - return 1 + return True + elif (hasattr(axis, 'units') and string.lower(axis.units) in ['degrees_east', 'degree_east', 'degree_e', 'degrees_e', 'degreee', 'degreese'] and not (axis.isLatitude() or axis.isLevel() or axis.isTime())): + return True elif (hasattr(axis, 'standard_name') and string.lower(axis.standard_name)=='longitude'): - return 1 + return True else: return AbstractConvention.axisIsLongitude(self, axis) diff --git a/Test/test_allMIPs.py b/Test/test_allMIPs.py new file mode 100644 index 00000000..94aa3bf4 --- /dev/null +++ b/Test/test_allMIPs.py @@ -0,0 +1,26 @@ +import pdb +import urllib +import cdms2 +import os +import sys +import cdat_info +import basetest + + +class TestMIPS(basetest.CDMSBaseTest): + def setUp(self): + myurl = "http://uvcdat.llnl.gov/cdat/sample_data/161122_RobertPincus_multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-20161122_none.nc" + super(TestMIPS, self).setUp() + urllib.urlretrieve(myurl, "161122_RobertPincus_multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-20161122_none.nc") + + def tearDown(self): + super(TestMIPS, self).tearDown() + os.remove("161122_RobertPincus_multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-20161122_none.nc") + + def testinput4MIPs(self): + f=cdms2.open("161122_RobertPincus_multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-20161122_none.nc") + self.assertEqual(f['water_vapor'].getLatitude()[0:4].tolist(), [-28.5, 28.5, 31.5, 87.]) + self.assertEqual(f['water_vapor'].getLongitude()[0:4].tolist(), [27., 24., 162., 126.]) + +if __name__ == "__main__": + basetest.run() diff --git a/Test/test_cdmsfile_io.py b/Test/test_cdmsfile_io.py index fb8240ab..f8792ced 100755 --- a/Test/test_cdmsfile_io.py +++ b/Test/test_cdmsfile_io.py @@ -79,4 +79,4 @@ def testClosedOperations(self): u[0:1]=-99.9 if __name__ == '__main__': - basetest.run() \ No newline at end of file + basetest.run() diff --git a/Test/test_ncSTRING.py b/Test/test_ncSTRING.py deleted file mode 100644 index d6e539ed..00000000 --- a/Test/test_ncSTRING.py +++ /dev/null @@ -1,81 +0,0 @@ -# Automatically adapted for numpy.oldnumeric Aug 01, 2007 by ^F^F^F^F^F - -import urllib -import cdms2 -import MV2 -import os -import basetest -import numpy - - -class TestNCString(basetest.CDMSBaseTest): - def setUp(self): - myurl = "http://uvcdat.llnl.gov/cdat/sample_data/prcp_1951.nc" - super(TestNCString, self).setUp() - urllib.urlretrieve(myurl, "prcp_1951.nc") - - def tearDown(self): - super(TestNCString, self).tearDown() - os.remove("prcp_1951.nc") - - - - def testNCStringWrite(self): - cdms2.setNetcdf4Flag(1) - cdms2.setNetcdfClassicFlag(0) - cdms2.setNetcdfShuffleFlag(0) - cdms2.setNetcdfDeflateFlag(0) - cdms2.setNetcdfDeflateLevelFlag(0) - NYR = 6 - NMO = 12 - NLAT = 16 - NLON = 32 - timear = MV2.arange(NYR*NMO, dtype=MV2.float) - time = cdms2.createAxis(timear, id='time') - time.units = "months since 2000-1" - g = cdms2.createUniformGrid(-90.0, NLAT, - 180./(NLAT-1), 0., NLON, 360./NLON) - - uar = numpy.arange(NYR*NMO*NLAT*NLON) - uar.shape = (NYR*NMO, NLAT, NLON) - u = cdms2.createVariable(uar, - id='u', - axes=(time, g.getLatitude(), - g.getLongitude())) - u.units = 'm/s' - - f = self.getTempFile("junk.nc", "w") - f.myNCSTRING=["1","2","3","4"] - u.long_name=["aaa","bbbb","cccc","dddd"] - f.write(u) - f.close() - # assert values - f = self.getTempFile("junk.nc", "r") - self.assertEqual(f.listglobal(),['myNCSTRING','Conventions']) - self.assertEqual(f.listattribute('u'), - ['units', - '_FillValue', - 'missing_value', - 'long_name']) - self.assertEqual(f['u'].long_name, ["aaa", "bbbb", "cccc", "dddd"]) - f.close() - - - def testNCStringArray(self): - f = cdms2.open("prcp_1951.nc", "r") - # Verify if all attributes are presents. - self.assertEqual(f.listglobal(), - ['history', - 'Conventions', - 'references', - 'institution', - 'title']) - self.assertEqual(f.listattribute('prcp'), - ['_FillValue', 'grid_mapping', - 'valid_min', 'long_name', 'standard_name', - 'units', 'missing_value', 'valid_max']) - self.assertEqual(f['prcp'].long_name, - ['Daily precipitation', 'Sasha', 'Charles', 'Denis']) - -if __name__ == "__main__": - basetest.run()