1 | '''apicalls.py - test the api''' |
---|
2 | |
---|
3 | import csml,sys |
---|
4 | |
---|
5 | f='./testfiles/gridseries/testout.xml' |
---|
6 | |
---|
7 | #Initialise the CSML container |
---|
8 | csmlContainer=csml.API.csmlContainer.Container(csmlpath='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring") |
---|
9 | |
---|
10 | #Initialise and parse the dataset |
---|
11 | csmldoc = csml.parser.Dataset() |
---|
12 | csmldoc.parse(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[4] |
---|
22 | feature=csmldoc.getFeature(flist[4]) |
---|
23 | |
---|
24 | #feature 'bestname' |
---|
25 | print feature.id |
---|
26 | #print feature.description |
---|
27 | |
---|
28 | #get the domain of the feature |
---|
29 | |
---|
30 | print '\n The feature has domain:' |
---|
31 | print feature.getDomain() |
---|
32 | |
---|
33 | #get list of allowed subsettings |
---|
34 | print '\n the following feature subsetting operations are allowed:' |
---|
35 | print feature.getAllowedSubsettings() |
---|
36 | |
---|
37 | |
---|
38 | #define a selection (based on the domain) |
---|
39 | subsetDictionary={} |
---|
40 | subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0') |
---|
41 | #subsetDictionary['t']=() |
---|
42 | subsetDictionary['latitude']=(-90,60) |
---|
43 | subsetDictionary['longitude']=(-31.265,30.258) |
---|
44 | |
---|
45 | #request subsetted data from features (can set paths here) and add to container |
---|
46 | #subset a feature |
---|
47 | csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary)) |
---|
48 | #subset another feature (in fact it's the same feature again, but it proves the concept) |
---|
49 | subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0') |
---|
50 | subsetDictionary['latitude']=(75) |
---|
51 | subsetDictionary['longitude']=(41.25,45) |
---|
52 | csmlContainer.add(feature.subsetToProfileSeries(ncpath='myfile2.nc',**subsetDictionary)) |
---|
53 | |
---|
54 | #when you have finished, get the contents of the container |
---|
55 | csmlbundle=csmlContainer.getContents() |
---|
56 | print 'CSML %s'%csmlbundle[0] # csml document |
---|
57 | paths=csmlbundle[1:] |
---|
58 | print paths #paths to netcdf files |
---|