- Timestamp:
- 07/09/06 14:57:52 (13 years ago)
- Location:
- TI02-CSML/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/Examples/parsing/demoCreateCSML.py
r1494 r1498 3 3 4 4 from cElementTree import * 5 from Parser import * 6 from xml.dom.minidom import parseString 5 import csml.parser 6 import csml.parser_extra 7 7 import elementtree.ElementTree as etree 8 import sys 8 9 9 10 10 … … 40 40 41 41 #MetaDataProperty Object 42 md = MetaDataProperty()42 md = csml.parser.MetaDataProperty() 43 43 setattr(md, 'href', 'http://ndg.nerc.ac.uk/Metadata/home/users/domlowe/CSML/demodata') 44 44 … … 49 49 dm=[] 50 50 #UnitDefinition (s) 51 ud = UnitDefinition()52 ud.description= Description('Conventional practical salinity units')53 ud.name = Name(['practical salinity units'])51 ud = csml.parser.UnitDefinition() 52 ud.description=csml.parser.Description('Conventional practical salinity units') 53 ud.name = csml.parser.Name(['practical salinity units']) 54 54 ud.quantityType='sea water salinity' 55 ud.catalogSymbol= CodeType( 'psu', 'http://ndg.nerc.ac.uk/units')55 ud.catalogSymbol=csml.parser.CodeType( 'psu', 'http://ndg.nerc.ac.uk/units') 56 56 dm.append(ud) 57 57 58 uds = UnitDefinitions(definitionMembers=dm)58 uds = csml.parser.UnitDefinitions(definitionMembers=dm) 59 59 ############################################################### 60 60 … … 67 67 #empty list to hold definitionMembers 68 68 dm = [] 69 ph = Phenomenon()69 ph =csml.parser.Phenomenon() 70 70 ph.id='rainfall' 71 71 dm.append(ph) 72 ph = Phenomenon()72 ph =csml.parser.Phenomenon() 73 73 ph.id='another Phenomenon name' 74 74 dm.append(ph) 75 pds = PhenomenonDefinitions(definitionMembers=dm)75 pds = csml.parser.PhenomenonDefinitions(definitionMembers=dm) 76 76 ############################################################### 77 77 … … 89 89 90 90 #Create a NASAAmesExtract 91 na1 = NASAAmesExtract()91 na1 = csml.parser.NASAAmesExtract() 92 92 #set attributes: 93 93 setattr(na1, 'id', 'naextract_one') … … 101 101 102 102 #Create a second NASAAmesExtract 103 na2 = NASAAmesExtract()103 na2 = csml.parser.NASAAmesExtract() 104 104 #set attributes: 105 105 setattr(na2, 'id', 'naextract_two') … … 118 118 119 119 #Create a NetCDFExtract 120 nc = NetCDFExtract()120 nc = csml.parser.NetCDFExtract() 121 121 #set attributes: 122 122 setattr(nc, 'id', 'feat04times') … … 128 128 129 129 #Create another NetCDFExtract 130 nc = NetCDFExtract()130 nc = csml.parser.NetCDFExtract() 131 131 #set attributes: 132 132 setattr(nc, 'id', 'feat04azimuth') … … 138 138 139 139 #Create another NetCDFExtract 140 nc = NetCDFExtract()140 nc = csml.parser.NetCDFExtract() 141 141 #set attributes: 142 142 setattr(nc, 'id', 'feat05times') … … 154 154 aalist=[] 155 155 #Create an AggregatedArray 156 aa = AggregatedArray()157 nc1 = NetCDFExtract()158 nc2 = NetCDFExtract()156 aa = csml.parser.AggregatedArray() 157 nc1 = csml.parser.NetCDFExtract() 158 nc2 = csml.parser.NetCDFExtract() 159 159 #set attributes for AggregatedArray 160 160 setattr(aa, 'id', 'feat05cruisetrack') … … 181 181 ################### ArrayGenerator ############################ 182 182 #Create ArrayGenerator 183 ag = ArrayGenerator()183 ag =csml.parser.ArrayGenerator() 184 184 #set attributes: 185 185 setattr(ag, 'id', 'feat05depths') … … 197 197 198 198 #### PointFeature: ##### 199 ptf= PointFeature()199 ptf=csml.parser.PointFeature() 200 200 ptf.id='feat01' 201 ptf.description= Description('Temperature reading from thermometer')202 ptd= PointDomain()203 p= Position()201 ptf.description=csml.parser.Description('Temperature reading from thermometer') 202 ptd=csml.parser.PointDomain() 203 p=csml.parser.Position() 204 204 p.srsName ='urn:EPSG:geographicCRS:4979' 205 205 p.axisLabels='Lat Long h' … … 209 209 ptd.domainReference=p 210 210 ptf.domain=ptd 211 rs= RangeSet()212 rs.quantityList= MeasureOrNullList(uom='udunits.xml#degreesC',val = '10')211 rs=csml.parser.RangeSet() 212 rs.quantityList=csml.parser.MeasureOrNullList(uom='udunits.xml#degreesC',val = '10') 213 213 ptf.rangeSet=rs 214 ptf.parameter= Phenomenon(href='CFStandardNames.xml#air_temperature') #TO FIX214 ptf.parameter=csml.parser.Phenomenon(href='CFStandardNames.xml#air_temperature') #TO FIX 215 215 fms.append(ptf) 216 216 217 217 #### PointSeriesFeature: ##### 218 ptsf= PointSeriesFeature()218 ptsf=csml.parser.PointSeriesFeature() 219 219 ptsf.id='feat02' 220 ptsf.description= Description('January timeseries of raingauge measurements')221 ptsd= PointSeriesDomain()222 t= Trajectory()220 ptsf.description=csml.parser.Description('January timeseries of raingauge measurements') 221 ptsd=csml.parser.PointSeriesDomain() 222 t=csml.parser.Trajectory() 223 223 t.srsName='urn:EPSG:geographicCRS:4979' 224 t.locations= DirectPositionList(vals='0.1 1.5 25')225 t.times= TimePositionList('#RefSys01','0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 26 27 28 29 30 31')224 t.locations=csml.parser.DirectPositionList(vals='0.1 1.5 25') 225 t.times=csml.parser.TimePositionList('#RefSys01','0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 26 27 28 29 30 31') 226 226 ptsd.domainReference=t 227 227 ptsf.domain=ptsd 228 rs= RangeSet()229 rs.quantityList= MeasureOrNullList('udunits.xml#mm', '5 3 10 1 2 8 10 2 5 10 20 21 12 3 5 19 12 23 32 10 8 8 2 0 0 1 5 6 10 17 20')228 rs=csml.parser.RangeSet() 229 rs.quantityList=csml.parser.MeasureOrNullList('udunits.xml#mm', '5 3 10 1 2 8 10 2 5 10 20 21 12 3 5 19 12 23 32 10 8 8 2 0 0 1 5 6 10 17 20') 230 230 ptsf.rangeSet=rs 231 231 fms.append(ptsf) 232 232 233 233 #### ProfileFeature: ##### 234 prf= ProfileFeature()234 prf=csml.parser.ProfileFeature() 235 235 prf.id='feat03' 236 prf.description= Description('Vertical wind profile')237 prd= ProfileDomain()238 op= OrientedPosition(srsName='urn:EPSG:geographicCRS:4326')236 prf.description=csml.parser.Description('Vertical wind profile') 237 prd=csml.parser.ProfileDomain() 238 op=csml.parser.OrientedPosition(srsName='urn:EPSG:geographicCRS:4326') 239 239 op.location='-1 3' 240 240 op.time='1999-07-21T10:00:00' 241 horiz= AngleList('udunits.xml#degrees','0')242 vert= AngleList('udunits.xml#degrees','90')243 direct= DirectionVectorList(horiz,vert)241 horiz=csml.parser.AngleList('udunits.xml#degrees','0') 242 vert=csml.parser.AngleList('udunits.xml#degrees','90') 243 direct=csml.parser.DirectionVectorList(horiz,vert) 244 244 op.direction=direct 245 245 prd.domainReference=op 246 dpl = DirectPositionList('#RefSys02','10 20 30 40 50 60 70 80 90 100')246 dpl =csml.parser.DirectPositionList(srsName='#RefSys02',vals='10 20 30 40 50 60 70 80 90 100') 247 247 prd.domainComplement=dpl 248 248 prf.domain=prd 249 rs= RangeSet()249 rs=csml.parser.RangeSet() 250 250 valueComps=[] 251 vc1= Measure('udunits.xml#ms-1')251 vc1=csml.parser.Measure('udunits.xml#ms-1') 252 252 valueComps.append(vc1) 253 vc2 = Measure('udunits.xml#ms-1')253 vc2 =csml.parser.Measure('udunits.xml#ms-1') 254 254 valueComps.append(vc2) 255 cv= CompositeValue(valueComponents=valueComps)256 db= DataBlock(rangeParameters=cv, doubleOrNullTupleList='2.0 1.1 2.4 0.8 3.3 0.1 2.6 -0.2 5.6 0.1 4.5 1.3 6.3 0.1 5.7 0.9 4.2 1.1 3.2 -0.1')255 cv=csml.parser.CompositeValue(valueComponents=valueComps) 256 db=csml.parser.DataBlock(rangeParameters=cv, doubleOrNullTupleList='2.0 1.1 2.4 0.8 3.3 0.1 2.6 -0.2 5.6 0.1 4.5 1.3 6.3 0.1 5.7 0.9 4.2 1.1 3.2 -0.1') 257 257 rs.dataBlock=db 258 258 prf.rangeSet=rs 259 cp= CompositePhenomenon()259 cp=csml.parser.CompositePhenomenon() 260 260 cp.id='wind' 261 cp.name = Name(['Vector Wind'])261 cp.name = csml.parser.Name(['Vector Wind']) 262 262 components=[] 263 component= Phenomenon(href='CFStandardNames.xml#eastward_wind')263 component=csml.parser.Phenomenon(href='CFStandardNames.xml#eastward_wind') 264 264 components.append(component) 265 component= Phenomenon(href='CFStandardNames.xml#northward_wind')265 component=csml.parser.Phenomenon(href='CFStandardNames.xml#northward_wind') 266 266 components.append(component) 267 267 cp.componentPhenomena=components … … 270 270 271 271 #### ProfileSeriesFeature: (not-complete)##### 272 psf= ProfileSeriesFeature()272 psf=csml.parser.ProfileSeriesFeature() 273 273 psf.id='feat05' 274 psf.description= Description('Cruise CTD salinity')275 psd = ProfileSeriesDomain()276 ot= OrientedTrajectory()274 psf.description=csml.parser.Description('Cruise CTD salinity') 275 psd =csml.parser.ProfileSeriesDomain() 276 ot=csml.parser.OrientedTrajectory() 277 277 ot.srsName='urn:EPSG:geographicCRS:4326' 278 278 psd.domainReference=ot … … 284 284 285 285 #instantiate FeatureCollection object: 286 fc= FeatureCollection(members=fms)287 etp = EnvelopeWithTimePeriod()288 etp.lowerCorner= '-10 15'289 etp.upperCorner= '30 65'286 fc=csml.parser.FeatureCollection(members=fms) 287 etp = csml.parser.EnvelopeWithTimePeriod() 288 etp.lowerCorner=csml.parser.DirectPosition(vals='-10 15') 289 etp.upperCorner=csml.parser.DirectPosition(vals='30 65') 290 290 etp.timePosition='1998-01-01' 291 291 etp.timePosition2='2003-12-31' … … 296 296 ########### The Dataset ############## 297 297 #Create an Empty Dataset 298 ds = Dataset()298 ds = csml.parser.Dataset() 299 299 #Set objects as attributes of dataset 300 300 setattr(ds,'id','TestDataSet') … … 307 307 308 308 #call the toXML method of the Dataset object: 309 csml = ds.toXML()309 csmldoc = ds.toXML() 310 310 #parse and pretty print the result 311 strCSML= parseString(tostring(csml)).toprettyxml()311 strCSML=csml.parser_extra.PrettyPrint(csmldoc) 312 312 #tidy up elementtree style namespaces 313 strCSML= removeInlineNS(strCSML)313 strCSML=csml.parser_extra.removeInlineNS(strCSML) 314 314 #strCSML contains the csml doc. 315 315 print strCSML -
TI02-CSML/trunk/csml/parser.py
r1479 r1498 250 250 +axisLabels[0...]:NCNameList 251 251 """ 252 def __init__(self,uomLabels=None,axisLabels=None ):252 def __init__(self,uomLabels=None,axisLabels=None, *args,**kwargs): 253 253 if uomLabels: 254 254 self.uomLabels=uomLabels … … 277 277 +xlink:actuate[0..1]:string 278 278 """ 279 def __init__(self, href=None, role=None,arcrole=None,title=None,show=None,actuate=None ):279 def __init__(self, href=None, role=None,arcrole=None,title=None,show=None,actuate=None,*args,**kwargs): 280 280 if href: 281 281 self.href=href
Note: See TracChangeset
for help on using the changeset viewer.