Skip to content

Commit

Permalink
Issue32 (#86)
Browse files Browse the repository at this point in the history
* Fix #32 for input4MIPs

* Fix #32: change Return 1 and return 0 -- to return True and return False

* add test for inpu4MIPs
  • Loading branch information
dnadeau4 authored and doutriaux1 committed Feb 13, 2017
1 parent 5b6b0d6 commit 068bb93
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 122 deletions.
66 changes: 34 additions & 32 deletions Lib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions Lib/convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions Test/test_allMIPs.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion Test/test_cdmsfile_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ def testClosedOperations(self):
u[0:1]=-99.9

if __name__ == '__main__':
basetest.run()
basetest.run()
81 changes: 0 additions & 81 deletions Test/test_ncSTRING.py

This file was deleted.

0 comments on commit 068bb93

Please sign in to comment.