1 | '''apicalls.py - test the api''' |
---|
2 | |
---|
3 | import csml |
---|
4 | |
---|
5 | f='test.xml' |
---|
6 | |
---|
7 | #Initialise and parse the dataset |
---|
8 | csmldoc = csml.parser.Dataset() |
---|
9 | csmldoc.parse(f) |
---|
10 | |
---|
11 | |
---|
12 | #get list of features in the dataset |
---|
13 | flist= csmldoc.getFeatureList() |
---|
14 | print '\n Here are all the features in %s:' %f |
---|
15 | print flist |
---|
16 | |
---|
17 | #select a feature by name (gml:id) |
---|
18 | print '\n Selecting feature with gml:id = %s' %flist[4] |
---|
19 | feature=csmldoc.getFeature(flist[4]) |
---|
20 | |
---|
21 | #feature 'bestname' |
---|
22 | print feature.id |
---|
23 | print feature.description |
---|
24 | |
---|
25 | #get the domain of the feature |
---|
26 | print '\n The feature has domain reference:' |
---|
27 | print feature.getDomainReference() |
---|
28 | |
---|
29 | #get the domain complement of the feature |
---|
30 | print '\n The feature has domain complement :' |
---|
31 | print feature.getDomainComplement() |
---|
32 | |
---|
33 | #get combined domain |
---|
34 | print '\n The feature has domain:' |
---|
35 | #print feature.getDomain() |
---|
36 | |
---|
37 | #get list of allowed subsettings |
---|
38 | print '\n the following feature subsetting operations are allowed:' |
---|
39 | print feature.getAllowedSubsettings() |
---|
40 | |
---|
41 | |
---|
42 | #define a selection (based on the domain ref/complement) |
---|
43 | #timeSelection=['2881-3-16T0:0:0.0', '2881-4-16T0:0:0.0', '2881-5-16T0:0:0.0', '2881-6-16T0:0:0.0', '2881-7-16T0:0:0.0', '2881-8-16T0:0:0.0', '2881-9-16T0:0:0.0'] |
---|
44 | timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0'] |
---|
45 | |
---|
46 | spatialSubsetDictionary= {} |
---|
47 | spatialSubsetDictionary['latitude']=(-90,90) |
---|
48 | #spatialSubsetDictionary['longitude']=(330,359) |
---|
49 | spatialSubsetDictionary['longitude']=(-31.265,30.258) |
---|
50 | |
---|
51 | #request subsetted data from feature (can set paths here) |
---|
52 | subsetCSML, subsetNetCDF, arraySize=feature.subsetToGridSeries(timeSelection, csmlpath='myfile.xml', ncpath='myfile.nc',**spatialSubsetDictionary) |
---|
53 | |
---|
54 | #parse and pretty print the result |
---|
55 | # strCSML=parser_extra.PrettyPrint(subsetCSML) |
---|
56 | # strCSML=parser_extra.removeInlineNS(strCSML) |
---|
57 | # print strCSML #csml document (string) |
---|
58 | print subsetCSML |
---|
59 | print subsetNetCDF # netcdf file (file) |
---|
60 | print 'arraySize: %s' %arraySize |
---|