1 | '''apicalls.py - test the api''' |
---|
2 | |
---|
3 | import csml |
---|
4 | |
---|
5 | f='Examples/parsing/test.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 | 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 reference:' |
---|
30 | print feature.getDomainReference() |
---|
31 | |
---|
32 | #get the domain complement of the feature |
---|
33 | print '\n The feature has domain complement :' |
---|
34 | print feature.getDomainComplement() |
---|
35 | |
---|
36 | #get combined domain |
---|
37 | print '\n The feature has domain:' |
---|
38 | #print feature.getDomain() |
---|
39 | |
---|
40 | #get list of allowed subsettings |
---|
41 | print '\n the following feature subsetting operations are allowed:' |
---|
42 | print feature.getAllowedSubsettings() |
---|
43 | |
---|
44 | |
---|
45 | #define a selection (based on the domain ref/complement) |
---|
46 | #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'] |
---|
47 | timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0'] |
---|
48 | |
---|
49 | spatialSubsetDictionary= {} |
---|
50 | spatialSubsetDictionary['latitude']=(-90,90) |
---|
51 | #spatialSubsetDictionary['longitude']=(330,359) |
---|
52 | spatialSubsetDictionary['longitude']=(-31.265,30.258) |
---|
53 | |
---|
54 | #request subsetted data from feature (can set paths here) |
---|
55 | feature.subsetToGridSeries(csmlContainer, timeSelection, ncpath='myfile.nc',**spatialSubsetDictionary) |
---|
56 | csmlbundle=csmlContainer.getContents() |
---|
57 | |
---|
58 | print 'CSML %s'%csmlbundle[0] # csml document |
---|
59 | |
---|
60 | #parse and pretty print the result |
---|
61 | # strCSML=parser_extra.PrettyPrint(subsetCSML) |
---|
62 | # strCSML=parser_extra.removeInlineNS(strCSML) |
---|
63 | # print strCSML #csml document (string) |
---|
64 | # print subsetCSML |
---|
65 | # print subsetNetCDF # netcdf file (file) |
---|
66 | # print 'arraySize: %s' %arraySize |
---|