source: TI02-CSML/trunk/csml/Examples/Parsing/apicalls.py @ 3296

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/Examples/Parsing/apicalls.py@3296
Revision 3296, 1.3 KB checked in by domlowe, 12 years ago (diff)

fixing example parser and point series subsetting of inline content

Line 
1'''apicalls.py  - test the api'''
2
3import csml
4
5f='example.xml'
6outputdir = 'out'
7
8#Initialise the CSML container
9csmlContainer=csml.API.csmlContainer.Container(outputdir,csmlname='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring")
10
11#Initialise and parse the dataset
12csmldoc = csml.parser.Dataset(file=f)
13
14
15#get list of features in the dataset
16flist= csmldoc.getFeatureList() 
17print '\n Here are all the features in %s:' %f
18print flist
19
20#select a feature by name (gml:id)
21print '\n Selecting feature with gml:id = %s' %flist[0]
22feature=csmldoc.getFeature(flist[0])
23
24f#eature 'bestname'
25print feature.id
26print feature.description
27
28#get the domain of the feature
29print '\n The feature has domain: '
30print feature.getDomain()
31
32#get list of allowed subsettings
33print '\n the following feature subsetting operations are allowed:'
34print feature.getAllowedSubsettings()
35
36
37#define a selection (based on the domain)
38timeSelection=['2007-08-12T10:45:00', '2007-08-12T11:45:00']
39
40#request subsetted data from features (can set paths here) and add to container
41#subset a feature
42csmlContainer.add(feature.subsetToPointSeries(times=timeSelection,  ncname='myfile.nc'))
43
44#when you have finished, get the contents of the container
45csmlbundle=csmlContainer.getContents()
46print 'CSML %s'%csmlbundle[0] # csml document
47paths=csmlbundle[1:]
48print paths #paths to netcdf files
Note: See TracBrowser for help on using the repository browser.