source: TI02-CSML/trunk/Examples/parsing/apicalls.py @ 1493

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/Examples/parsing/apicalls.py@1493
Revision 1493, 1.8 KB checked in by domlowe, 15 years ago (diff)

moving example files

Line 
1'''apicalls.py  - test the api'''
2
3import csml
4
5f='test.xml'
6
7#Initialise and parse the dataset
8csmldoc = csml.parser.Dataset()
9csmldoc.parse(f)
10
11
12#get list of features in the dataset
13flist= csmldoc.getFeatureList() 
14print '\n Here are all the features in %s:' %f
15print flist
16
17#select a feature by name (gml:id)
18print '\n Selecting feature with gml:id = %s' %flist[4]
19feature=csmldoc.getFeature(flist[4])
20
21#feature 'bestname'
22print feature.id
23print feature.description
24
25#get the domain of the feature
26print '\n The feature has domain reference:' 
27print feature.getDomainReference()
28
29#get the domain complement of the feature
30print '\n The feature has domain complement :' 
31print feature.getDomainComplement()
32
33#get combined domain
34print '\n The feature has domain:' 
35#print feature.getDomain()
36
37#get list of allowed subsettings
38print '\n the following feature subsetting operations are allowed:'
39print 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']
44timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0']
45
46spatialSubsetDictionary= {}
47spatialSubsetDictionary['latitude']=(-90,90)
48#spatialSubsetDictionary['longitude']=(330,359)
49spatialSubsetDictionary['longitude']=(-31.265,30.258)
50
51#request subsetted data from feature (can set paths here)
52subsetCSML, 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)
58print subsetCSML
59print subsetNetCDF # netcdf file (file)
60print 'arraySize: %s' %arraySize
Note: See TracBrowser for help on using the repository browser.