Skip to content

Commit 212f877

Browse files
committed
Merge pull request #1752 from UV-CDAT/climofast
several tweaks, mainly saving method results for re-use, to improve
2 parents ce70b1b + c6ddc71 commit 212f877

File tree

4 files changed

+223
-166
lines changed

4 files changed

+223
-166
lines changed

Packages/cdms2/Lib/axis.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,22 @@ def designateTime(self, persistent=0, calendar=None):
735735
if calendar is not None:
736736
self.setCalendar(calendar, persistent)
737737

738+
# For isTime(), keep track of whether each id is for a time axis or not, for better performance.
739+
# This dictionary is a class variable (not a member of any particular instance).
740+
idtaxis = {} # id:type where type is 'T' for time, 'O' for other
741+
738742
# Return true iff the axis is a time axis
739743
def isTime(self):
740744
id = self.id.strip().lower()
741-
if (hasattr(self,'axis') and self.axis=='T'): return 1
745+
if hasattr(self,'axis'):
746+
if self.axis=='T': return 1
747+
elif self.axis is not None: return 0
748+
# Have we saved the id-to-axis type information already?
749+
if id in self.idtaxis:
750+
if self.idtaxis[id]=='T':
751+
return 1
752+
else:
753+
return 0
742754
## Try to figure it out from units
743755
try:
744756
import genutil
@@ -747,15 +759,23 @@ def isTime(self):
747759
if len(sp)>1:
748760
t=genutil.udunits(1,"day")
749761
s = sp[0].strip()
750-
if s in t.available_units() and t.know_units()[s]=="TIME":
762+
if s in t.available_units() and t.known_units()[s]=="TIME":
763+
self.idtaxis[id] = 'T'
751764
return 1
752765
#try the plural version since udunits only as singular (day noy days)
753766
s=s+"s"
754-
if s in t.available_units() and t.know_units()[s]=="TIME":
767+
if s in t.available_units() and t.known_units()[s]=="TIME":
768+
self.idtaxis[id] = 'T'
755769
return 1
756770
except:
757771
pass
758-
return (id[0:4] == 'time') or (id in time_aliases)
772+
#return (id[0:4] == 'time') or (id in time_aliases)
773+
if (id[0:4] == 'time') or (id in time_aliases):
774+
self.idtaxis[id]='T'
775+
return 1
776+
else:
777+
self.idtaxis[id] = 'O'
778+
return 0
759779

760780
# Return true iff the axis is a forecast axis
761781
def isForecast(self):
@@ -896,6 +916,9 @@ def isCircularAxis(self):
896916
# (2) self.topology is undefined, and the axis is a longitude
897917
def isCircular(self):
898918

919+
if hasattr(self,'realtopology'):
920+
if self.realtopology=='circular': return 1
921+
elif self.realtopology=='linear': return 0
899922
if(len(self) < 2):
900923
return 0
901924

@@ -918,6 +941,9 @@ def isCircular(self):
918941
else:
919942
iscircle = 0
920943

944+
# save realtopology attribute in __dict__, don't write it to the file
945+
if iscircle==1: self.__dict__['realtopology'] = 'circular'
946+
elif iscircle==0: self.__dict__['realtopology'] = 'linear'
921947
return iscircle
922948

923949
def designateCircular(self, modulo, persistent=0):
@@ -1947,6 +1973,7 @@ def getExplicitBounds(self):
19471973
try:
19481974
boundsVar = self.parent[boundsName]
19491975
boundsArray = numpy.ma.filled(boundsVar)
1976+
self._boundsArray_ = boundsArray # for climatology performance
19501977
except KeyError,err:
19511978
print err
19521979
boundsArray = None

Packages/cdms2/Lib/dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None):
307307
if hasattr(file1, libcf.CF_FILETYPE):
308308
if getattr(file1, libcf.CF_FILETYPE) == libcf.CF_GLATT_FILETYPE_HOST:
309309
file = gsHost.open(path, mode)
310+
elif mode=='r' and hostObj is None:
311+
# helps performance on machines where file open (in CdmsFile) is costly
312+
file = file1
310313
else:
311314
file = CdmsFile(path, mode, hostObj = hostObj)
312315
file1.close()

Packages/unidata/Lib/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
modification, or enhancement.
1717
1818
"""
19-
from udunits import udunits,addBaseUnit,addDimensionlessUnit,addScaledUnit,\
20-
addOffsettedUnit,addMultipliedUnits,addInvertedUnit,addDividedUnits
21-
udunits_init=0
19+
from udunits import udunits, addBaseUnit, addDimensionlessUnit, addScaledUnit # noqa
20+
from udunits import addOffsettedUnit, addMultipliedUnits, addInvertedUnit, addDividedUnits # noqa
21+
udunits_init = 0 # noqa

0 commit comments

Comments
 (0)