Changeset 1887 for TI02-CSML/branches/CSML2/csmllibs/csmlfeaturetypes.py
- Timestamp:
- 18/12/06 12:15:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/branches/CSML2/csmllibs/csmlfeaturetypes.py
r1622 r1887 23 23 #empty list to hold featureMembers 24 24 self.fms =[] 25 25 26 26 #at the moment, only one featuretype per CSML Dataset is supported. 27 27 #get the featuretype of the first representative file in the ffmap object … … 45 45 try: 46 46 descName=DI.getVariableAttribute('long_name') 47 descName 47 48 except AttributeError: 48 49 descName = "missing name" … … 85 86 return fe 86 87 88 87 89 def createCSMLGridSeriesFeatures(self): 88 90 #This method assumes that the variables (features) are shared across identically structured files 89 91 #should be supplied with a featurefilemap object (see csmlfiles for FileMapMaker) 92 print 'is this working at all?' 90 93 representativeFiles=self.ffmap.getRepresentativeFiles() 91 94 for repfile in representativeFiles: … … 105 108 #it's an axis or bounds not a feature, try next variable 106 109 continue 107 GridSeriesFeature_element=csml.parser.GridSeriesFeature()108 GridSeriesFeature_element.id=str(allVarNames[i])110 gsFeature=csml.parser.GridSeriesFeature() 111 gsFeature.id=str(allVarNames[i]) 109 112 desc = self._getDescriptiveName(DI) 110 GridSeriesFeature_element.description=csml.parser.Description(desc) 113 #GridSeriesFeature_element.description=csml.parser.Description(desc) 114 gsFeature.description=desc 111 115 #DOMAIN 116 gsCoverage=csml.parser.GridSeriesCoverage() 112 117 gsDomain=csml.parser.GridSeriesDomain() 113 #DOMAIN REFERENCE 114 tpl=csml.parser.TimePositionList() 115 if self.timestorage =='inline': 116 tpl.timePositions=self.timeString 117 tpl.frame='%s:%s'%(self.caltype,self.units) 118 else: 119 # do something to create a single extract for the times (from the representative file). 120 tpl.timePositions = csml.csmllibs.csmlfileextracts.createSingleExtract(self.extractType, repfilename, self.timedim, len(self.timeString.split())) 121 tpl.frame='%s:%s'%(self.caltype,self.units) 122 gsDomain.domainReference=tpl 123 grid=csml.parser.Grid() 124 #COVERAGE FUNCTION 125 mr =csml.parser.MappingRule(csml.csmllibs.csmlextra.getMappingRule(len(dimNames))) 126 GridSeriesFeature_element.coverageFunction=mr 127 #RANGESET 128 arrSz = DI.getArraySizeOfVar() 129 try: 130 strUom = DI.getVariableAttribute('units') 131 except AttributeError: 132 # if units attribute doesn't exist: 133 strUom ="dimensionless or units not determined" 134 rs=csml.parser.RangeSet() 135 if self.valuestorage=='inline': 136 #TO DO, store the rangeset inline - use Datablock class??? 137 pass 138 else: 139 #store the rangeSet as an aggregatedArray 140 aa=csml.parser.AggregatedArray() 141 aa.arraySize=[] 142 aa.arraySize.append(arrSz) 143 aa.uom=strUom 144 aa.aggType='new' #can it be anything else? 145 aa.aggIndex='1' 146 #FileExtract (fe) element will be NetCDF/GRIB/PPExtract element (As defined earlier in ExtractType) 147 self.extractType= DI.extractType 148 fe = self._getCorrectExtractType() 149 varSize=DI.getShapeOfVar() 150 fe.arraySize=varSize 151 fe.fileName=self.filesinDir 152 fe.variableName=allVarNames[i] 153 aa.component=[fe] 154 rs.aggregatedArray=aa 155 GridSeriesFeature_element.rangeSet=rs 156 #DOMAIN COMPLEMENT 157 grid.srsName='urn:EPSG:GeographicCRS:4326' 158 numSpDims=len(varSize) -1 159 grid.srsDimension=str(numSpDims) 160 grid.dimension=str(numSpDims) 161 ge =csml.parser.GridEnvelope(low=DI.getLowLimits(), high=DI.getHighLimits()) 162 grid.limits=ge 163 #add an axisName element(s) for each spatial dimension. 164 # and an ordinate element 165 axes=[] 166 for i in range (1, len(dimNames)): 167 #axisNames 168 axisname ='dim'+str(i) 169 axes.append(axisname) 170 #ordinates 171 grid.ordinates=[] 172 for i in range (1, len(dimNames)): 173 ord=csml.parser.GridOrdinateDescription() 174 ord.gridAxesSpanned='dim' + str(i) 175 ord.sequenceRule=csml.csmllibs.csmlextra.getSeqRule(len(dimNames)) 176 dimName=dimNames[len(dimNames)-i] 177 ord.definesAxis=dimName 178 #look up file extract name in dictionary 179 #(axisid stored in dictionary = current filename + variable name) 180 axisid=self.repfilename+dimName 181 if self.spatialstorage=='fileextract': 182 #refer to extract 183 ord.axisValues='#'+self.fileExtractDictionary[axisid] 184 else: 185 #store inline 186 DI.setAxis(dimName) 187 ord.axisValues=csml.csmllibs.csmlextra.cleanString(str(DI.getDataForAxis())) 188 grid.ordinates.append(ord) 189 grid.axisNames=axes 190 gsDomain.domainComplement=grid 191 GridSeriesFeature_element.domain=gsDomain 192 GridSeriesFeature_element.parameter=csml.parser.Phenomenon(href='http://badc.rl.ac.uk/localparams#%s'%allVarNames[i]) 193 self.fms.append(GridSeriesFeature_element) 118 gsCoverage.gridSeriesDomain=gsDomain 119 gsFeature.value=gsCoverage 120 #gsDomain=csml.parser.GridSeriesDomain() 121 ##DOMAIN REFERENCE 122 #tpl=csml.parser.TimePositionList() 123 #if self.timestorage =='inline': 124 #tpl.timePositions=self.timeString 125 #tpl.frame='%s:%s'%(self.caltype,self.units) 126 #else: 127 ## do something to create a single extract for the times (from the representative file). 128 #tpl.timePositions = csml.csmllibs.csmlfileextracts.createSingleExtract(self.extractType, repfilename, self.timedim, len(self.timeString.split())) 129 #tpl.frame='%s:%s'%(self.caltype,self.units) 130 #gsDomain.domainReference=tpl 131 #grid=csml.parser.Grid() 132 ##COVERAGE FUNCTION 133 #mr =csml.parser.MappingRule(csml.csmllibs.csmlextra.getMappingRule(len(dimNames))) 134 #GridSeriesFeature_element.coverageFunction=mr 135 ##RANGESET 136 #arrSz = DI.getArraySizeOfVar() 137 #try: 138 #strUom = DI.getVariableAttribute('units') 139 #except AttributeError: 140 ## if units attribute doesn't exist: 141 #strUom ="dimensionless or units not determined" 142 #rs=csml.parser.RangeSet() 143 #if self.valuestorage=='inline': 144 ##TO DO, store the rangeset inline - use Datablock class??? 145 #pass 146 #else: 147 ##store the rangeSet as an aggregatedArray 148 #aa=csml.parser.AggregatedArray() 149 #aa.arraySize=[] 150 #aa.arraySize.append(arrSz) 151 #aa.uom=strUom 152 #aa.aggType='new' #can it be anything else? 153 #aa.aggIndex='1' 154 ##FileExtract (fe) element will be NetCDF/GRIB/PPExtract element (As defined earlier in ExtractType) 155 #self.extractType= DI.extractType 156 #fe = self._getCorrectExtractType() 157 #varSize=DI.getShapeOfVar() 158 #fe.arraySize=varSize 159 #fe.fileName=self.filesinDir 160 #fe.variableName=allVarNames[i] 161 #aa.component=[fe] 162 #rs.aggregatedArray=aa 163 #GridSeriesFeature_element.rangeSet=rs 164 ##DOMAIN COMPLEMENT 165 #grid.srsName='urn:EPSG:GeographicCRS:4326' 166 #numSpDims=len(varSize) -1 167 #grid.srsDimension=str(numSpDims) 168 #grid.dimension=str(numSpDims) 169 #ge =csml.parser.GridEnvelope(low=DI.getLowLimits(), high=DI.getHighLimits()) 170 #grid.limits=ge 171 ##add an axisName element(s) for each spatial dimension. 172 ## and an ordinate element 173 #axes=[] 174 #for i in range (1, len(dimNames)): 175 ##axisNames 176 #axisname ='dim'+str(i) 177 #axes.append(axisname) 178 ##ordinates 179 #grid.ordinates=[] 180 #for i in range (1, len(dimNames)): 181 #ord=csml.parser.GridOrdinateDescription() 182 #ord.gridAxesSpanned='dim' + str(i) 183 #ord.sequenceRule=csml.csmllibs.csmlextra.getSeqRule(len(dimNames)) 184 #dimName=dimNames[len(dimNames)-i] 185 #ord.definesAxis=dimName 186 ##look up file extract name in dictionary 187 ##(axisid stored in dictionary = current filename + variable name) 188 #axisid=self.repfilename+dimName 189 #if self.spatialstorage=='fileextract': 190 ##refer to extract 191 #ord.axisValues='#'+self.fileExtractDictionary[axisid] 192 #else: 193 ##store inline 194 #DI.setAxis(dimName) 195 #ord.axisValues=csml.csmllibs.csmlextra.cleanString(str(DI.getDataForAxis())) 196 #grid.ordinates.append(ord) 197 #grid.axisNames=axes 198 #gsDomain.domainComplement=grid 199 #GridSeriesFeature_element.domain=gsDomain 200 #GridSeriesFeature_element.parameter=csml.parser.Phenomenon(href='http://badc.rl.ac.uk/localparams#%s'%allVarNames[i]) 201 self.fms.append(gsFeature) 194 202 DI.closeFile() 195 203 ###End of createCSMLGridSeriesFeatures###
Note: See TracChangeset
for help on using the changeset viewer.