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