Changeset 2061 for TI02-CSML/trunk/csml
- Timestamp:
- 26/01/07 15:01:10 (13 years ago)
- Location:
- TI02-CSML/trunk/csml
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/API/csmlContainer.py
r1902 r2061 15 15 #Create an Empty Dataset & FeatureCollection 16 16 self.ds = csml.parser.Dataset() 17 self.fc=csml.parser.FeatureCollection()18 17 #Set attributes of dataset 19 18 #if 'metadata' is a URI, set it as href attribute if MetaDataProperty instance, … … 31 30 self.dm=[] #empty list to hold definition members (e.g. UnitDefinitions) 32 31 self.fm=[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures) 33 self. ad=[] #empty list to hold arraydescriptors (e.g. NetCDFExtract)32 self.sd=[] #empty list to hold storage descriptors (e.g. NetCDFExtract) 34 33 #the dataset is now initialised. now you can add features/defintions/arraydescriptors 35 34 #using the methods supplied. … … 62 61 63 62 def getContents(self): 64 self.ds. arrayDescriptors=self.ad65 self.ds.featureCollection=csml.parser. FeatureCollection(members=self.fm)63 self.ds.storageDescriptor=self.sd 64 self.ds.featureCollection=csml.parser.CSMLFeatureCollection(featureMembers=self.fm) 66 65 csmlout=self.ds.toXML() 67 66 #parse and pretty print the result to file -
TI02-CSML/trunk/csml/API/ops_AbstractFeature.py
r1932 r2061 10 10 return ['none'] 11 11 12 def _identifyTimeAxis(self,listToCheck): 12 def _identifyTimeAxis(self,listToCheck): 13 13 #given a list of possible axes, find the one which is most probably the time axis. 14 14 for name in listToCheck: … … 18 18 19 19 def __compareTimes(timemin, timecheck, timemax): 20 timeok=0 20 21 try: 21 22 year=int(timecheck.split('-')[0]) … … 27 28 if tcheck.cmp(timemax) < 1: 28 29 timeok = 1 30 print 'TMIN time %s'%timemin 31 print 'CHECK time %s'%tcheck 32 print 'TMAX time %s'%timemax 29 33 except: 30 34 #if it's not a proper internet time e.g. time = '6' then just compare numerically -
TI02-CSML/trunk/csml/API/ops_Dataset.py
r1922 r2061 39 39 #returns a list of feature ids for the dataset 40 40 self.featureList = [] 41 for member in self.featureCollection. members:41 for member in self.featureCollection.featureMembers: 42 42 self.featureList.append(member.id) 43 43 return self.featureList … … 45 45 def getFeature(self, featureID): 46 46 """ returns a single feature object """ 47 for member in self.featureCollection. members:47 for member in self.featureCollection.featureMembers: 48 48 if member.id == featureID: 49 49 return member -
TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py
r2000 r2061 22 22 for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 23 23 name=gridOrd.coordAxisLabel.CONTENT 24 if isinstance(gridOrd.coordAxisValues, csml.parser.FileExtract): 25 #not tested with file extracts yet: (01/01/07) 26 self.domain[name]=gridOrd.coordAxisValues.getData() 24 if hasattr(gridOrd.coordAxisValues, '__insertedExtract'): 25 self.domain[name]=gridOrd.coordAxisValues.__insertedExtract.getData() 27 26 else: 28 27 vals=gridOrd.coordAxisValues.coordinateList.CONTENT 29 28 valList=[] 30 for val in vals.split(','): #remove commas 29 print 'splitting' 30 for val in vals.split(): 31 31 valList.append(val) 32 print val 32 33 self.domain[name]=valList 33 34 return self.domain … … 41 42 42 43 self.getDomain() 44 45 #TODO - incoporate the crsCatalogue. into this 43 46 #deal with longitude requests 44 47 #if the request is in -ve,+ve eg (-30,30) but the data is in (0,360) need to handle this by changing the args. 45 48 kwargs=csmlutils.fixLongitude(self.domain,kwargs) 46 #deal with times 47 timeAxis=self._identifyTimeAxis(self.domain.keys()) 48 self.times=kwargs[timeAxis] 49 50 #deal with times 51 #need to find the time axis: 52 cat=csml.csmllibs.csmlcrs.CRSCatalogue() 53 crs=cat.getCRS(self.value.gridSeriesDomain.srsName) 54 #get the position of the time axis in crs/ axis labels 55 timeAxisPos=crs.timeAxis 56 #get the name of the time axis in the crs 57 timeName=crs.axes[timeAxisPos] 58 #get the ordinate with that name and find the original time name for the file. 59 for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 60 if gridOrd.coordAxisLabel.CONTENT==timeName: 61 timeAxis = gridOrd.gridAxesSpanned.CONTENT #only works for regular grids atm 62 else: 63 print 'crs not supported' 64 65 66 #here, timeName is the name given to the time axis by the CRS, 67 #and timeAxis is the name given to the time axis in the file. 68 #currently supporting domain subsetting only by CRS name 69 #(but should be easy to extend later) 70 self.times=kwargs[timeName] 49 71 self.files=[] 50 72 strTimes='' … … 52 74 53 75 #set the reference system for the time axis 54 76 calset=False 55 77 for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 56 if gridOrd.coordAxisLabel.CONTENT==time Axis:78 if gridOrd.coordAxisLabel.CONTENT==timeName: 57 79 try: 58 80 caltype=gridOrd.coordAxisValues.frame.split(':',1)[0] … … 69 91 except: 70 92 csml.csmllibs.csmltime.setcdtimeCalendar(csml.csmllibs.csmltime.cdtime.DefaultCalendar) 71 72 93 94 73 95 if len(self.times) == 2: 74 96 #then this is a range of times (t1, tn) 75 97 try: 76 tone= ops_AbstractFeature.__getCDtime(self.times[0])98 tone=csml.API.ops_AbstractFeature.__getCDtime(self.times[0]) 77 99 except: 78 100 tone=self.times[0] 79 101 try: 80 ttwo= ops_AbstractFeature.__getCDtime(self.times[1])102 ttwo=csml.API.ops_AbstractFeature.__getCDtime(self.times[1]) 81 103 except: 82 104 ttwo=self.times[1] … … 86 108 else: 87 109 self.getDomain() 88 for time in self.domain[timeAxis][0].split(): 110 111 for time in self.domain[timeName]: 89 112 timeok=csml.API.ops_AbstractFeature.__compareTimes(tone,time,ttwo) 90 113 if timeok ==1: 91 114 self.times.append(time) 115 #okay up to here! 116 92 117 if hasattr(self.value.rangeSet, 'aggregatedArray'): 93 118 #handle aggregatedArray … … 159 184 straxisValues='' 160 185 #now deal with each argument: 161 162 print "KWARGS" 163 print kwargs 164 print "DOM" 165 print self.domain 186 166 187 if key in kwargs: 167 if kwargs[key][0] < kwargs[key][1]: 188 if key ==timeName: 189 continue #dealt with time earlier 190 elif kwargs[key][0] < kwargs[key][1]: 168 191 for val in self.domain[key]: 169 print self.domain[key]170 192 if val is not '': 171 193 if float(val) >= kwargs[key][0]: … … 173 195 arraySize=arraySize+1 174 196 straxisValues=straxisValues+ str(val) + ', ' 175 176 197 else:#this if deals with selections such as longitude (330,30) where the lower limit is 'greater' than the upper limit in a mathematical sense. 177 198 for val in self.domain[key]: … … 210 231 floatTimes.append(time.value) 211 232 nc.addAxis('t',floatTimes,isTime=1,units=calunits,calendar=caltype) 233 #USE CRS! 212 234 for ordinate in ordinates: 213 235 lon,lat=None,None … … 223 245 if len(ordinates)==3: 224 246 axes=['t',axisorder[1],axisorder[2],axisorder[3]] 225 elif len( grid.ordinates)==2:247 elif len(ordinates)==2: 226 248 axes=['t',axisorder[1],axisorder[2]] 227 249 nc.addVariable(fulldata,self.id, axes,units='') #to do, units attribute for CF compliance -
TI02-CSML/trunk/csml/csmllibs/csmlcrs.py
r2060 r2061 37 37 crs=CRSystem(srsName='ndg:crs:xyt', axes =['Lon', 'Lat','Time']) 38 38 self.systems['ndg:crs:xyt']=crs 39 crs.lonAxis=0 40 crs.latAxis=1 41 crs.timeAxis=2 39 42 40 43 #define unknown 1D CRS: -
TI02-CSML/trunk/csml/csmllibs/csmldataiface.py
r2016 r2061 19 19 import sys 20 20 import csml.csmllibs.csmltime 21 # This is required to prevent Numeric arrays being truncated when printed. 22 import MA 23 MA.set_print_limit(0) 24 21 25 22 26 class DataInterface(object): -
TI02-CSML/trunk/csml/testfiles/basictest.py
r2060 r2061 15 15 # 1. Test parsing from CSML file 16 16 #tree = ElementTree(file='../XMLInstances/CSMLExample_SuperWrap.xml') 17 tree = ElementTree(file='../ testfiles/gridseries/testout.xml')17 tree = ElementTree(file='../DDCTestfiles/DDCout.xml') 18 18 19 19
Note: See TracChangeset
for help on using the changeset viewer.