source: TI02-CSML/trunk/csml/testfiles/apicalls.py @ 2215

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/testfiles/apicalls.py@2215
Revision 2215, 1.9 KB checked in by domlowe, 13 years ago (diff)

adding online parser to svn

Line 
1'''apicalls.py  - test the api'''
2
3import csml,sys
4
5f='./testfiles/gridseries/testout.xml'
6
7#Initialise the CSML container
8csmlContainer=csml.API.csmlContainer.Container(csmlpath='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring")
9
10#Initialise and parse the dataset
11csmldoc = csml.parser.Dataset()
12csmldoc.parse(f)
13
14print '\n this is the bounding box of the whole feature collection: '
15print csmldoc.getBoundingBox
16sys.exit()
17
18
19
20#get list of features in the dataset
21flist= csmldoc.getFeatureList() 
22print '\n Here are all the features in %s:' %f
23print flist
24
25#select a feature by name (gml:id)
26print '\n Selecting feature with gml:id = %s' %flist[4]
27feature=csmldoc.getFeature(flist[4])
28
29#feature 'bestname'
30print feature.id
31#print feature.description
32
33#get the domain of the feature
34
35print '\n The feature has domain:' 
36print feature.getDomain()
37
38#get list of allowed subsettings
39print '\n the following feature subsetting operations are allowed:'
40print feature.getAllowedSubsettings()
41
42
43#define a selection (based on the domain)
44subsetDictionary={}
45subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
46#subsetDictionary['t']=()
47subsetDictionary['latitude']=(-90,60)
48subsetDictionary['longitude']=(-31.265,30.258)
49
50#request subsetted data from features (can set paths here) and add to container
51#subset a feature
52csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary))
53#subset another feature (in fact it's the same feature again, but this time subsetting to a profileseries)
54subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
55subsetDictionary['latitude']=(75.)
56subsetDictionary['longitude']=(48.8)
57csmlContainer.add(feature.subsetToProfileSeries(ncpath='myfile2.nc',**subsetDictionary))
58
59#when you have finished, get the contents of the container
60csmlbundle=csmlContainer.getContents()
61print 'CSML %s'%csmlbundle[0] # csml document
62paths=csmlbundle[1:]
63print paths #paths to netcdf files
Note: See TracBrowser for help on using the repository browser.