Changeset 1498


Ignore:
Timestamp:
07/09/06 14:57:52 (13 years ago)
Author:
domlowe
Message:

updated demoCreateCSML.py example and fixed a couple of error in the parser to do with DirectPosition? inside EnvelopeWithTimePeriod?

Location:
TI02-CSML/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/Examples/parsing/demoCreateCSML.py

    r1494 r1498  
    33 
    44from cElementTree import * 
    5 from Parser import * 
    6 from xml.dom.minidom import parseString 
     5import csml.parser 
     6import csml.parser_extra 
    77import elementtree.ElementTree as etree 
    8 import sys 
     8 
    99 
    1010 
     
    4040 
    4141#MetaDataProperty Object 
    42 md = MetaDataProperty() 
     42md = csml.parser.MetaDataProperty() 
    4343setattr(md, 'href', 'http://ndg.nerc.ac.uk/Metadata/home/users/domlowe/CSML/demodata') 
    4444 
     
    4949dm=[] 
    5050#UnitDefinition (s) 
    51 ud = UnitDefinition() 
    52 ud.description=Description('Conventional practical salinity units') 
    53 ud.name = Name(['practical salinity units']) 
     51ud = csml.parser.UnitDefinition() 
     52ud.description=csml.parser.Description('Conventional practical salinity units') 
     53ud.name = csml.parser.Name(['practical salinity units']) 
    5454ud.quantityType='sea water salinity' 
    55 ud.catalogSymbol=CodeType( 'psu', 'http://ndg.nerc.ac.uk/units') 
     55ud.catalogSymbol=csml.parser.CodeType( 'psu', 'http://ndg.nerc.ac.uk/units') 
    5656dm.append(ud) 
    5757 
    58 uds = UnitDefinitions(definitionMembers=dm) 
     58uds = csml.parser.UnitDefinitions(definitionMembers=dm) 
    5959############################################################### 
    6060 
     
    6767#empty list  to hold definitionMembers 
    6868dm = [] 
    69 ph =Phenomenon() 
     69ph =csml.parser.Phenomenon() 
    7070ph.id='rainfall' 
    7171dm.append(ph) 
    72 ph =Phenomenon() 
     72ph =csml.parser.Phenomenon() 
    7373ph.id='another Phenomenon name' 
    7474dm.append(ph) 
    75 pds = PhenomenonDefinitions(definitionMembers=dm) 
     75pds = csml.parser.PhenomenonDefinitions(definitionMembers=dm) 
    7676############################################################### 
    7777 
     
    8989 
    9090#Create a NASAAmesExtract 
    91 na1 = NASAAmesExtract() 
     91na1 = csml.parser.NASAAmesExtract() 
    9292#set attributes: 
    9393setattr(na1, 'id', 'naextract_one') 
     
    101101 
    102102#Create a second NASAAmesExtract 
    103 na2 = NASAAmesExtract() 
     103na2 = csml.parser.NASAAmesExtract() 
    104104#set attributes: 
    105105setattr(na2, 'id', 'naextract_two') 
     
    118118 
    119119#Create a NetCDFExtract 
    120 nc = NetCDFExtract() 
     120nc = csml.parser.NetCDFExtract() 
    121121#set attributes: 
    122122setattr(nc, 'id', 'feat04times') 
     
    128128 
    129129#Create another NetCDFExtract 
    130 nc = NetCDFExtract() 
     130nc = csml.parser.NetCDFExtract() 
    131131#set attributes: 
    132132setattr(nc, 'id', 'feat04azimuth') 
     
    138138 
    139139#Create another NetCDFExtract 
    140 nc = NetCDFExtract() 
     140nc = csml.parser.NetCDFExtract() 
    141141#set attributes: 
    142142setattr(nc, 'id', 'feat05times') 
     
    154154aalist=[] 
    155155#Create an AggregatedArray 
    156 aa = AggregatedArray() 
    157 nc1 = NetCDFExtract() 
    158 nc2 = NetCDFExtract() 
     156aa = csml.parser.AggregatedArray() 
     157nc1 = csml.parser.NetCDFExtract() 
     158nc2 = csml.parser.NetCDFExtract() 
    159159#set attributes for AggregatedArray 
    160160setattr(aa, 'id', 'feat05cruisetrack') 
     
    181181################### ArrayGenerator ############################ 
    182182#Create ArrayGenerator 
    183 ag =ArrayGenerator() 
     183ag =csml.parser.ArrayGenerator() 
    184184#set attributes: 
    185185setattr(ag, 'id', 'feat05depths') 
     
    197197 
    198198#### PointFeature: ##### 
    199 ptf=PointFeature() 
     199ptf=csml.parser.PointFeature() 
    200200ptf.id='feat01' 
    201 ptf.description=Description('Temperature reading from thermometer') 
    202 ptd=PointDomain() 
    203 p=Position() 
     201ptf.description=csml.parser.Description('Temperature reading from thermometer') 
     202ptd=csml.parser.PointDomain() 
     203p=csml.parser.Position() 
    204204p.srsName ='urn:EPSG:geographicCRS:4979' 
    205205p.axisLabels='Lat Long h' 
     
    209209ptd.domainReference=p 
    210210ptf.domain=ptd 
    211 rs=RangeSet() 
    212 rs.quantityList=MeasureOrNullList(uom='udunits.xml#degreesC',val = '10') 
     211rs=csml.parser.RangeSet() 
     212rs.quantityList=csml.parser.MeasureOrNullList(uom='udunits.xml#degreesC',val = '10') 
    213213ptf.rangeSet=rs 
    214 ptf.parameter=Phenomenon(href='CFStandardNames.xml#air_temperature')  #TO FIX 
     214ptf.parameter=csml.parser.Phenomenon(href='CFStandardNames.xml#air_temperature')  #TO FIX 
    215215fms.append(ptf) 
    216216 
    217217#### PointSeriesFeature: ##### 
    218 ptsf=PointSeriesFeature() 
     218ptsf=csml.parser.PointSeriesFeature() 
    219219ptsf.id='feat02' 
    220 ptsf.description=Description('January timeseries of raingauge measurements') 
    221 ptsd=PointSeriesDomain() 
    222 t=Trajectory() 
     220ptsf.description=csml.parser.Description('January timeseries of raingauge measurements') 
     221ptsd=csml.parser.PointSeriesDomain() 
     222t=csml.parser.Trajectory() 
    223223t.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') 
     224t.locations=csml.parser.DirectPositionList(vals='0.1 1.5 25') 
     225t.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') 
    226226ptsd.domainReference=t 
    227227ptsf.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') 
     228rs=csml.parser.RangeSet() 
     229rs.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') 
    230230ptsf.rangeSet=rs 
    231231fms.append(ptsf) 
    232232 
    233233#### ProfileFeature: ##### 
    234 prf=ProfileFeature() 
     234prf=csml.parser.ProfileFeature() 
    235235prf.id='feat03' 
    236 prf.description=Description('Vertical wind profile') 
    237 prd=ProfileDomain() 
    238 op=OrientedPosition(srsName='urn:EPSG:geographicCRS:4326') 
     236prf.description=csml.parser.Description('Vertical wind profile') 
     237prd=csml.parser.ProfileDomain() 
     238op=csml.parser.OrientedPosition(srsName='urn:EPSG:geographicCRS:4326') 
    239239op.location='-1 3' 
    240240op.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) 
     241horiz=csml.parser.AngleList('udunits.xml#degrees','0') 
     242vert=csml.parser.AngleList('udunits.xml#degrees','90') 
     243direct=csml.parser.DirectionVectorList(horiz,vert) 
    244244op.direction=direct 
    245245prd.domainReference=op 
    246 dpl =DirectPositionList('#RefSys02','10 20 30 40 50 60 70 80 90 100') 
     246dpl =csml.parser.DirectPositionList(srsName='#RefSys02',vals='10 20 30 40 50 60 70 80 90 100') 
    247247prd.domainComplement=dpl 
    248248prf.domain=prd 
    249 rs=RangeSet() 
     249rs=csml.parser.RangeSet() 
    250250valueComps=[] 
    251 vc1=Measure('udunits.xml#ms-1') 
     251vc1=csml.parser.Measure('udunits.xml#ms-1') 
    252252valueComps.append(vc1) 
    253 vc2 =Measure('udunits.xml#ms-1') 
     253vc2 =csml.parser.Measure('udunits.xml#ms-1') 
    254254valueComps.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') 
     255cv=csml.parser.CompositeValue(valueComponents=valueComps) 
     256db=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') 
    257257rs.dataBlock=db 
    258258prf.rangeSet=rs 
    259 cp=CompositePhenomenon() 
     259cp=csml.parser.CompositePhenomenon() 
    260260cp.id='wind' 
    261 cp.name = Name(['Vector Wind']) 
     261cp.name = csml.parser.Name(['Vector Wind']) 
    262262components=[] 
    263 component=Phenomenon(href='CFStandardNames.xml#eastward_wind') 
     263component=csml.parser.Phenomenon(href='CFStandardNames.xml#eastward_wind') 
    264264components.append(component) 
    265 component=Phenomenon(href='CFStandardNames.xml#northward_wind') 
     265component=csml.parser.Phenomenon(href='CFStandardNames.xml#northward_wind') 
    266266components.append(component) 
    267267cp.componentPhenomena=components 
     
    270270 
    271271#### ProfileSeriesFeature: (not-complete)##### 
    272 psf=ProfileSeriesFeature() 
     272psf=csml.parser.ProfileSeriesFeature() 
    273273psf.id='feat05' 
    274 psf.description=Description('Cruise CTD salinity') 
    275 psd =ProfileSeriesDomain() 
    276 ot=OrientedTrajectory() 
     274psf.description=csml.parser.Description('Cruise CTD salinity') 
     275psd =csml.parser.ProfileSeriesDomain() 
     276ot=csml.parser.OrientedTrajectory() 
    277277ot.srsName='urn:EPSG:geographicCRS:4326' 
    278278psd.domainReference=ot 
     
    284284 
    285285#instantiate FeatureCollection object: 
    286 fc=FeatureCollection(members=fms) 
    287 etp = EnvelopeWithTimePeriod() 
    288 etp.lowerCorner='-10 15' 
    289 etp.upperCorner='30 65' 
     286fc=csml.parser.FeatureCollection(members=fms) 
     287etp = csml.parser.EnvelopeWithTimePeriod() 
     288etp.lowerCorner=csml.parser.DirectPosition(vals='-10 15') 
     289etp.upperCorner=csml.parser.DirectPosition(vals='30 65') 
    290290etp.timePosition='1998-01-01' 
    291291etp.timePosition2='2003-12-31' 
     
    296296########### The Dataset  ############## 
    297297#Create an Empty Dataset 
    298 ds = Dataset() 
     298ds = csml.parser.Dataset() 
    299299#Set objects as attributes of dataset 
    300300setattr(ds,'id','TestDataSet') 
     
    307307 
    308308#call the toXML method of the Dataset object: 
    309 csml = ds.toXML() 
     309csmldoc = ds.toXML() 
    310310#parse and pretty print the result 
    311 strCSML= parseString(tostring(csml)).toprettyxml() 
     311strCSML=csml.parser_extra.PrettyPrint(csmldoc) 
    312312#tidy up elementtree style namespaces 
    313 strCSML=removeInlineNS(strCSML) 
     313strCSML=csml.parser_extra.removeInlineNS(strCSML) 
    314314#strCSML contains the csml doc. 
    315315print strCSML 
  • TI02-CSML/trunk/csml/parser.py

    r1479 r1498  
    250250    +axisLabels[0...]:NCNameList 
    251251    """ 
    252     def __init__(self,uomLabels=None,axisLabels=None): 
     252    def __init__(self,uomLabels=None,axisLabels=None, *args,**kwargs): 
    253253        if uomLabels: 
    254254            self.uomLabels=uomLabels 
     
    277277    +xlink:actuate[0..1]:string 
    278278    """ 
    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): 
    280280         if href: 
    281281             self.href=href 
Note: See TracChangeset for help on using the changeset viewer.