@@ -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
0 commit comments