Changeset 3058
 Timestamp:
 27/11/07 12:40:24 (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

TI02CSML/trunk/csml/csmllibs/csmlcrs.py
r3049 r3058 95 95 crs.timeAxis=1 96 96 97 #define rotated_latitude_longitude CRS (test) 98 crs=CRSystem(srsName='ndg:crs:rlonrlatsurft', axes =['rotated_longitude', 'rotated_latitude','surface', 'time']) 99 self.systems['ndg:crs:rlonrlatsurft']=crs 100 crs.lonAxis=0 101 crs.latAxis=1 102 crs.timeAxis=3 103 97 104 #define unknown 2D CRS: 98 105 crs=CRSystem(srsName='ndg:crs:undefined_xt', axes=['tba','time']) … … 116 123 crs.timeAxis=3 117 124 118 #define unknown 5D CRS :125 #define unknown 5D CRS (test): 119 126 crs=CRSystem(srsName='ndg:crs:undefined5d_lonlatzt', axes=['probAx','time','tba', 'latitude','longitude']) 120 127 self.pseudosystems['ndg:crs:undefined5d_lonlatzt']=crs … … 139 146 self.systems['ndg:crs:unknown4d']=crs 140 147 141 def getCRS(self, srsName , labels=None):148 def getCRS(self, srsName): 142 149 #given the name of a CRS e.g. 'ndg:crs:xypt' return the CRSystem object 143 #labels are only required if it is a ndg:pseudoCRS144 150 try: 145 151 return self.systems[srsName] 146 152 except: 147 153 return self.pseudosystems[srsName] 154 148 155 149 156 def getUnitType(self, unit): … … 167 174 unittype = unit 168 175 return unittype 169 170 def determineCRS(self, axes=None, units=None, knownCRSAxes=None): 176 177 def __generatePseudoCRS(self,crsMap, axes, units): 178 ''' if a suitable crs cannot be found a pseudo crs is created''' 179 for psystem in self.pseudosystems: 180 if len(self.pseudosystems[psystem].axes) == len(crsMap): 181 axisorder={} 182 indexes=[] 183 for ax in crsMap: 184 if ax in self.pseudosystems[psystem].axes: 185 axisorder[ax]=crsMap.index(ax) 186 indexes.append(crsMap.index(ax)) 187 188 if len(axisorder)== len(self.pseudosystems[psystem].axes)  1: 189 for ax in enumerate(crsMap): 190 if ax[1] not in axisorder: 191 for i in range(3): 192 if i not in indexes: 193 axisorder[axes[ax[0]]]=i 194 break 195 196 axisLabels='' 197 orderedNewAxes=[] 198 for ax in self.pseudosystems[psystem].axes: 199 orderedNewAxes.append(ax) 200 for key in axisorder: 201 if key in orderedNewAxes: 202 pass 203 else: 204 orderedNewAxes[orderedNewAxes.index('tba')] = key 205 206 for ax in orderedNewAxes: 207 axisLabels=axisLabels + ax + ' ' 208 209 #crs=CRSystem('ndg:pseudoCRS', orderedNewAxes) #this should be ordered list. 210 crs=CRSystem(psystem, orderedNewAxes) #this should be ordered list. 211 crs.axisLabels=axisLabels 212 crs.timeAxis=self.pseudosystems[psystem].timeAxis 213 crs.latAxis=self.pseudosystems[psystem].latAxis 214 crs.latAxis=self.pseudosystems[psystem].lonAxis 215 orderedunits=[] 216 for a in crs.axes: 217 orderedunits.append(units[axisorder[a]]) 218 crs.units=csml.csmllibs.csmlextra.stringify(orderedunits) 219 return crs, axisorder 220 221 def determineCRS(self, axes=None, units=None): 171 222 '''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. 172 223 e.g passing in: (axes=['t', 'ht', 'latitude', 'longitude'],units=['days since 19910901 00:00:00', 'm', 'degrees_north', 'degrees_east']) 173 224 returns self.systems['ndg:crs:xypt'], [3,2,1,0] 174 225 Assumes the units are ordered to correspond with the axes 175 Alternatively, supply with a list of knownCRSAxes names (e.g. 'latitude', 'longitude', 'height') to get the right crs object176 226 ''' 227 177 228 axisorder=[] 178 179 if knownCRSAxes is not None:180 axes=knownCRSAxes181 229 crs =None 182 230 183 #this can be extended to accomodate more units 184 if knownCRSAxes is not None: 185 crsMap=knownCRSAxes 186 else: 187 crsMap=[] 188 for axis in axes: 189 unit=units[axes.index(axis)] 190 unittype=self.getUnitType(unit) 191 crsMap.append(unittype) 231 #build a map of axes and units 232 crsMap=[] 233 for axis in axes: 234 unit=units[axes.index(axis)] 235 unittype=self.getUnitType(unit) 236 crsMap.append(unittype) 192 237 193 match= 1238 match=0 194 239 #now try and match up crsMap with known crsystems. 195 240 #axisorder stores the order of the supplied axes against the known crs. … … 200 245 #wrong dimensionality, skip this crs 201 246 continue 202 match= 0247 match=1 203 248 axisorder={} 204 249 for ax in self.systems[system].axes: … … 206 251 axisorder[ax]=crsMap.index(ax) 207 252 else: 208 match = 1253 match = 0 209 254 break 210 if match == 0:255 if match == 1: 211 256 crs=self.systems[system] 212 257 break 213 if match==1: #couldn't find a match  generate a pseudo crs 214 for psystem in self.pseudosystems: 215 if len(self.pseudosystems[psystem].axes) == len(crsMap): 216 axisorder={} 217 indexes=[] 218 for ax in crsMap: 219 if ax in self.pseudosystems[psystem].axes: 220 axisorder[ax]=crsMap.index(ax) 221 indexes.append(crsMap.index(ax)) 222 223 if len(axisorder)== len(self.pseudosystems[psystem].axes)  1: 224 for ax in enumerate(crsMap): 225 if ax[1] not in axisorder: 226 for i in range(3): 227 if i not in indexes: 228 axisorder[axes[ax[0]]]=i 229 break 230 231 axisLabels='' 232 orderedNewAxes=[] 233 for ax in self.pseudosystems[psystem].axes: 234 orderedNewAxes.append(ax) 235 for key in axisorder: 236 if key in orderedNewAxes: 237 pass 238 else: 239 orderedNewAxes[orderedNewAxes.index('tba')] = key 240 241 for ax in orderedNewAxes: 242 axisLabels=axisLabels + ax + ' ' 243 244 #crs=CRSystem('ndg:pseudoCRS', orderedNewAxes) #this should be ordered list. 245 crs=CRSystem(psystem, orderedNewAxes) #this should be ordered list. 246 crs.axisLabels=axisLabels 247 crs.timeAxis=self.pseudosystems[psystem].timeAxis 248 crs.latAxis=self.pseudosystems[psystem].latAxis 249 crs.latAxis=self.pseudosystems[psystem].lonAxis 250 orderedunits=[] 251 for a in crs.axes: 252 orderedunits.append(units[axisorder[a]]) 253 crs.units=csml.csmllibs.csmlextra.stringify(orderedunits) 254 return crs, axisorder 258 259 if match==0: #if couldn't find a match  generate a pseudo crs 260 crs, axisorder=self.__generatePseudoCRS(crsMap, axes, units) 261 255 262 if crs.units is None: 263 #if no units are defined, set the units to be those of the original data 256 264 if units is not None: 257 265 orderedunits=[]
Note: See TracChangeset
for help on using the changeset viewer.