Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions Packages/cdms2/Lib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,22 @@ def designateTime(self, persistent=0, calendar=None):
if calendar is not None:
self.setCalendar(calendar, persistent)

# For isTime(), keep track of whether each id is for a time axis or not, for better performance.
# This dictionary is a class variable (not a member of any particular instance).
idtaxis = {} # id:type where type is 'T' for time, 'O' for other

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@painter1 what happens if you have mutliple files with same axis id, but only some are actually time? Wouldn't this break? I'm thinking auto generated arrays axis_0 etc...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would break! I've never seen such a thing, but among the changes I've made, this is the one which I was least sure about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should add a test? See if it's already in and if it is and type changes, throw a warning/error? I don't think it will ever happen but of course now that I said it it is bound to happen...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this is to not have to figure out what the type is - that involves reading from a file. So the way I would fix it is to use self.idtaxis only if the user does something to enable this feature, e.g. calls a method to initialize it.

# Return true iff the axis is a time axis
def isTime(self):
id = self.id.strip().lower()
if (hasattr(self,'axis') and self.axis=='T'): return 1
if hasattr(self,'axis'):
if self.axis=='T': return 1
elif self.axis is not None: return 0
# Have we saved the id-to-axis type information already?
if id in self.idtaxis:
if self.idtaxis[id]=='T':
return 1
else:
return 0
## Try to figure it out from units
try:
import genutil
Expand All @@ -747,15 +759,23 @@ def isTime(self):
if len(sp)>1:
t=genutil.udunits(1,"day")
s = sp[0].strip()
if s in t.available_units() and t.know_units()[s]=="TIME":
if s in t.available_units() and t.known_units()[s]=="TIME":
self.idtaxis[id] = 'T'
return 1
#try the plural version since udunits only as singular (day noy days)
s=s+"s"
if s in t.available_units() and t.know_units()[s]=="TIME":
if s in t.available_units() and t.known_units()[s]=="TIME":
self.idtaxis[id] = 'T'
return 1
except:
pass
return (id[0:4] == 'time') or (id in time_aliases)
#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
else:
self.idtaxis[id] = 'O'
return 0

# Return true iff the axis is a forecast axis
def isForecast(self):
Expand Down Expand Up @@ -896,6 +916,9 @@ def isCircularAxis(self):
# (2) self.topology is undefined, and the axis is a longitude
def isCircular(self):

if hasattr(self,'realtopology'):
if self.realtopology=='circular': return 1
elif self.realtopology=='linear': return 0
if(len(self) < 2):
return 0

Expand All @@ -918,6 +941,9 @@ def isCircular(self):
else:
iscircle = 0

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

def designateCircular(self, modulo, persistent=0):
Expand Down Expand Up @@ -1947,6 +1973,7 @@ def getExplicitBounds(self):
try:
boundsVar = self.parent[boundsName]
boundsArray = numpy.ma.filled(boundsVar)
self._boundsArray_ = boundsArray # for climatology performance
except KeyError,err:
print err
boundsArray = None
Expand Down
3 changes: 3 additions & 0 deletions Packages/cdms2/Lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None):
if hasattr(file1, libcf.CF_FILETYPE):
if getattr(file1, libcf.CF_FILETYPE) == libcf.CF_GLATT_FILETYPE_HOST:
file = gsHost.open(path, mode)
elif mode=='r' and hostObj is None:
# helps performance on machines where file open (in CdmsFile) is costly
file = file1
else:
file = CdmsFile(path, mode, hostObj = hostObj)
file1.close()
Expand Down