Changeset 2198
- Timestamp:
- 21/02/07 13:25:11 (14 years ago)
- Location:
- TI02-CSML/trunk/csml/csmllibs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/csmllibs/csmlcrs.py
r2196 r2198 41 41 crs.timeAxis=2 42 42 43 # define lon lat height CRS: 44 crs=CRSystem(srsName='ndg:crs:xyh', axes =['longitude', 'latitude','height']) 45 self.systems['ndg:crs:xyh']=crs 46 crs.lonAxis=0 47 crs.latAxis=1 48 crs.timeAxis=None 49 50 43 51 # define height time CRS: 44 52 crs=CRSystem(srsName='ndg:crs:ht', axes =['height', 'time']) … … 72 80 return self.systems['ndg:crs:unknown'] 73 81 74 def determineCRS(self, axes, units): 82 def getUnitType(self, unit): 83 unittype='unknown' 84 if string.lower(unit) in ['second', 'seconds', 's', 'mins','minute','minutes','hour','hours','h','hr','hrs','day','days']: 85 unittype='time' 86 elif string.lower(unit)[:10] in ['days since', 'seconds si', 'minutes si', 'hours sinc','months sin', 'years sinc']: 87 unittype='time' 88 elif string.lower(unit) in ['mbar', 'pa','level']: 89 unittype='pressure' 90 elif string.lower(unit) in ['m', 'km']: 91 unittype='height' 92 elif string.lower(unit) in ['degrees_north', 'degrees_south']: 93 unittype='latitude' 94 elif string.lower(unit) in ['degrees_east','degrees_west']: 95 unittype='longitude' 96 return unittype 97 98 def determineCRS(self, axes=None, units=None, knownCRSAxes=None): 75 99 '''given any list of axis names and a list of units for these axes attempt to determine the CRS and return the CRSystem object and an axis order list. 76 100 e.g passing in: (axes=['t', 'ht', 'latitude', 'longitude'],units=['days since 1991-09-01 00:00:00', 'm', 'degrees_north', 'degrees_east']) 77 101 returns self.systems['ndg:crs:xypt'], [3,2,1,0] 78 Assumes the units are ordered to correspond with the axes! 102 Assumes the units are ordered to correspond with the axes 103 Alternatively, supply with a list of knownCRSAxes names (e.g. 'latitude', 'longitude', 'height') to get the right crs object 79 104 ''' 105 80 106 axisorder=[] 107 if knownCRSAxes is not None: 108 axes=knownCRSAxes 109 81 110 if len(axes)==2: 82 111 crs=self.systems['ndg:crs:unknown2d'] … … 87 116 else : 88 117 crs=self.systems['ndg:crs:unknown'] 89 crsMap=[] 90 #this can be extended to accomodate more units 91 for axis in axes: 92 print axis 93 unit=units[axes.index(axis)] 94 unittype='unknown' 95 if string.lower(unit) in ['second', 'seconds', 's', 'mins','minute','minutes','hour','hours','h','hr','hrs','day','days']: 96 unittype='time' 97 elif string.lower(unit)[:10] in ['days since', 'seconds si', 'minutes si', 'hours sinc','months sin', 'years sinc']: 98 unittype='time' 99 elif string.lower(unit) in ['mbar', 'pa','level']: 100 unittype='pressure' 101 elif string.lower(unit) in ['m', 'km']: 102 unittype='height' 103 elif string.lower(unit) in ['degrees_north', 'degrees_south']: 104 unittype='latitude' 105 elif string.lower(unit) in ['degrees_east','degrees_west']: 106 unittype='longitude' 107 crsMap.append(unittype) 118 119 #this can be extended to accomodate more units 120 if knownCRSAxes is not None: 121 crsMap=knownCRSAxes 122 else: 123 crsMap=[] 124 for axis in axes: 125 unit=units[axes.index(axis)] 126 unittype=self.getUnitType(unit) 127 crsMap.append(unittype) 128 108 129 109 130 #now try and match up crsMap with known crsystems. -
TI02-CSML/trunk/csml/csmllibs/csmlfeaturetypes.py
r2196 r2198 158 158 gcT.addChildElem('gridOrdinates',ord) 159 159 return gcT 160 161 def __getLocation(self): 162 #attempts to get a fixed location, eg for a ProfileSeriesFeature. 163 lonval=None 164 latval=None 165 heightval=None 166 vars=self.DI.getListofVariables() 167 cat = csml.csmllibs.csmlcrs.CRSCatalogue() 168 axes=[] 169 for var in vars: 170 self.DI.setVariable(var) 171 unitname=self.DI.getVariableAttribute('units') 172 unittype=cat.getUnitType(unitname) 173 if unittype == 'latitude': 174 latval=self.DI.getDataForVar() 175 axes.append(unittype) 176 elif unittype == 'longitude': 177 lonval=self.DI.getDataForVar() 178 axes.append(unittype) 179 elif unittype=='height': 180 heightval=self.DI.getDataForVar() 181 axes.append(unittype) 182 183 #returns lat lon height, but note that any of these may be None 184 crs=cat.determineCRS(knownCRSAxes =axes) #TODO, may need to rethink csmlcrs module a bit 185 srsName= crs[0].srsName 186 return latval, lonval, heightval, srsName 160 187 161 188 def __getCRS(self,varName,catalogue): … … 314 341 psFeature.parameter=csml.parser.Phenomenon(href='http://badc.rl.ac.uk/localparams#%s'%allVarNames[i]) 315 342 psFeature.value=psCoverage 316 317 psFeature.location=csml.parser.DirectPositionList(CONTENT='blahha', srsName='blah') 343 (latval, lonval, heightval, srs)=self.__getLocation() 344 posString ='%s %s %s'%(latval, lonval, heightval) 345 346 psFeature.location=csml.parser.DirectPositionList(CONTENT=posString, srsName=srs) 318 347 self.fms.append(psFeature) 319 348 self.DI.closeFile()
Note: See TracChangeset
for help on using the changeset viewer.