Changeset 1404
- Timestamp:
- 16/08/06 11:44:36 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/Scanner/csmllibs/csmlfeaturetypes.py
r1403 r1404 27 27 #get the featuretype of the first representative file in the ffmap object 28 28 self.featuretype= self.ffmap.getRepresentativeFiles()[0].getFeatureType() 29 #and create the features 29 30 if self.featuretype == 'GridSeries': 30 print 'creating grids'31 31 self.createCSMLGridSeriesFeatures() 32 32 elif self.featuretype == 'PointSeries': … … 35 35 #after the features have been generated append all featureMembers to the feature collection 36 36 self.gml_FeatureCollection_element.members=self.fms 37 38 39 #Some internal methods that are of use to all feature types: 40 def _getDescriptiveName(self,DI): 41 #given a data interface class with the variable or axis set, try to get a descriptive name 42 #eg. long name 43 try: 44 descName=DI.getVariableAttribute('long_name') 45 except AttributeError: 46 descName = "missing name" 47 descName=descName.replace('&','&') #remove ampersands TODO- extend this 48 return descName 49 50 def _populateListOfFiles(self,repfile): 51 #given a representative file, get list of files: one representative file + all related files 52 listOfFiles=[] 53 repfilename=repfile.getRepresentativeFileName() 54 listOfFiles.append(repfilename) 55 relfiles = repfile.getRelatedFiles() 56 for f in relfiles: 57 fname = f.getRelatedFileName() 58 listOfFiles.append(fname) 59 return repfilename,listOfFiles 60 61 def _getFilesAndTimes(self): 62 #TODO try and speed up csmllibs.csmltime.getFileTimeList 63 OrderedFileTimeList,self.caltype,self.units = csmllibs.csmltime.getFileTimeList(self.listOfFiles,self.timedim) 64 #build strings to hold times/filenames for current gridseriesfeature 65 self.timeString ='' 66 self.filesinDir = '' 67 for j in range (0, len(OrderedFileTimeList)): 68 t= OrderedFileTimeList[j][0] 69 f = OrderedFileTimeList[j][1] 70 self.timeString = self.timeString + ' ' + str(t) 71 self.filesinDir = self.filesinDir + ' ' + f 72 73 def _getCorrectExtractType(self): 74 #returns an empty parser file extract object of the correct type. 75 if self.extractType=='NetCDFExtract': 76 fe = csmllibs.Parser.NetCDFExtract() 77 if self.extractType=='NASAAmesExtract': 78 fe = csmllibs.Parser.NASAAmesExtract() 79 if self.extractType=='GRIBExtract': 80 fe = csmllibs.Parser.GRIBExtract() 81 if self.extractType=='PPExtract': 82 fe = csmllibs.Parser.PPExtract() 83 return fe 37 84 38 85 def createCSMLGridSeriesFeatures(self): … … 41 88 42 89 representativeFiles=self.ffmap.getRepresentativeFiles() 43 #fileid=0 #prefix used to distinguish variable names for similar variables from different files44 #don't use this - same variables should not be in same data granule.45 90 for repfile in representativeFiles: 46 #fileid=fileid+1 47 listOfFiles=[] 48 repfilename=repfile.getRepresentativeFileName() 49 listOfFiles.append(repfilename) 50 relfiles = repfile.getRelatedFiles() 51 for f in relfiles: 52 fname = f.getRelatedFileName() 53 listOfFiles.append(fname) 54 55 #THIS IS THE REALLY SLOW FUNCTION CALL!!!!!######################### 56 OrderedFileTimeList,caltype,units = csmllibs.csmltime.getFileTimeList(listOfFiles,self.timedim) 57 #build strings to hold times/filenames for current gridseriesfeature 58 #cal type returns the type of calendar used 59 timeString ='' 60 filesinDir = '' 61 for j in range (0, len(OrderedFileTimeList)): 62 t= OrderedFileTimeList[j][0] 63 f = OrderedFileTimeList[j][1] 64 timeString = timeString + ' ' + str(t) 65 filesinDir = filesinDir + ' ' + f 66 #Open representative file and create feature members: 91 self.repfilename,self.listOfFiles=self._populateListOfFiles(repfile) 92 self._getFilesAndTimes() 93 94 #Open representative file and create feature members: 67 95 DI = csmllibs.csmldataiface.DataInterface() 68 DI=DI.getUnknownInterfaceType( repfilename)69 DI.openFile( repfilename)96 DI=DI.getUnknownInterfaceType(self.repfilename) 97 DI.openFile(self.repfilename) 70 98 allVarNames=DI.getListofVariables() 71 99 numFeatures=len(allVarNames) … … 79 107 80 108 GridSeriesFeature_element=csmllibs.Parser.GridSeriesFeature() 81 #GridSeriesFeature_element.id=str(fileid)+'__'+str(allVarNames[i])82 109 GridSeriesFeature_element.id=str(allVarNames[i]) 83 #description: need to get the attribute called long_name (?? TODO - is this CF compliant??) 84 #use Ag's getbestname from nappy package? 85 desc=DI.getVariableAttribute('long_name') 86 try: 87 desc=DI.getVariableAttribute('long_name') 88 except AttributeError: 89 desc = "missing name" 90 91 desc=desc.replace('&','&') 110 desc = self._getDescriptiveName(DI) 92 111 GridSeriesFeature_element.description=csmllibs.Parser.Description(desc) 93 112 … … 102 121 tpl=csmllibs.Parser.TimePositionList() 103 122 if self.timestorage =='inline': 104 tpl.timePositions= timeString105 tpl.frame='%s:%s'%( caltype,units)123 tpl.timePositions=self.timeString 124 tpl.frame='%s:%s'%(self.caltype,self.units) 106 125 else: 107 126 # do something to create a single extract for the times (from the representative file). 108 tpl.timePositions = csmllibs.csmlfileextracts.createSingleExtract(self.extractType, repfilename, self.timedim, len( timeString.split()))109 tpl.frame='%s:%s'%( caltype,units)127 tpl.timePositions = csmllibs.csmlfileextracts.createSingleExtract(self.extractType, repfilename, self.timedim, len(self.timeString.split())) 128 tpl.frame='%s:%s'%(self.caltype,self.units) 110 129 111 130 gsDomain.domainReference=tpl … … 143 162 #FileExtract (fe) element will be NetCDF/GRIB/PPExtract element (As defined earlier in ExtractType) 144 163 self.extractType= DI.extractType 145 if self.extractType=='NetCDFExtract': 146 fe = csmllibs.Parser.NetCDFExtract() 147 if self.extractType=='NASAAmesExtract': 148 fe = csmllibs.Parser.NASAAmesExtract() 149 if self.extractType=='GRIBExtract': 150 fe = csmllibs.Parser.GRIBExtract() 151 if self.extractType=='PPExtract': 152 fe = csmllibs.Parser.PPExtract() 164 fe = self._getCorrectExtractType() 165 153 166 varSize=DI.getShapeOfVar() 154 167 fe.arraySize=varSize 155 fe.fileName= filesinDir168 fe.fileName=self.filesinDir 156 169 fe.variableName=allVarNames[i] 157 170 aa.component=[fe] … … 191 204 #look up file extract name in dictionary 192 205 #(axisid stored in dictionary = current filename + variable name) 193 axisid= repfilename+dimName206 axisid=self.repfilename+dimName 194 207 if self.spatialstorage=='fileextract': 195 208 #refer to extract … … 207 220 208 221 209 ######################################################################### 210 211 222 223 #This function needs revising in light of a) csml parser and b) new profile feature types 212 224 def createCSMLProfileFeature(csmldoc, dataset_element, gml_FeatureCollection_element, ffmap, timedim): 213 225 representativeFiles=ffmap.getRepresentativeFiles() … … 262 274 263 275 #gml_timePositionList_element = csmldoc.createElement("gml:TimePositionList") 264 #gml_timePositionList_element.appendChild(csmldoc.createTextNode( timeString))276 #gml_timePositionList_element.appendChild(csmldoc.createTextNode(self.timeString)) 265 277 #domainReference_element.appendChild(gml_timePositionList_element) 266 278 ProfileDomain_element.appendChild(domainReference_element)
Note: See TracChangeset
for help on using the changeset viewer.