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

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

some changes to allow cdml to be used as data source, not working properly yet though

Line 
1'''apicalls.py  - test the api'''
2
3import csml
4
5f='Examples/parsing/test.xml'
6
7#Initialise the CSML container
8csmlContainer=csml.API.csmlContainer.Container(csmlpath='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring")
9
10#Initialise and parse the dataset
11csmldoc = csml.parser.Dataset()
12csmldoc.parse(f)
13
14
15#get list of features in the dataset
16flist= csmldoc.getFeatureList() 
17print '\n Here are all the features in %s:' %f
18print flist
19
20#select a feature by name (gml:id)
21print '\n Selecting feature with gml:id = %s' %flist[4]
22feature=csmldoc.getFeature(flist[4])
23
24f#eature 'bestname'
25print feature.id
26print feature.description
27
28#get the domain of the feature
29print '\n The feature has domain reference:' 
30print feature.getDomainReference()
31
32#get the domain complement of the feature
33print '\n The feature has domain complement :' 
34print feature.getDomainComplement()
35
36#get combined domain
37print '\n The feature has domain:' 
38#print feature.getDomain()
39
40#get list of allowed subsettings
41print '\n the following feature subsetting operations are allowed:'
42print 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']
47timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0']
48
49spatialSubsetDictionary= {}
50spatialSubsetDictionary['latitude']=(-90,90)
51#spatialSubsetDictionary['longitude']=(330,359)
52spatialSubsetDictionary['longitude']=(-31.265,30.258)
53
54#request subsetted data from feature (can set paths here)
55feature.subsetToGridSeries(csmlContainer, timeSelection,  ncpath='myfile.nc',**spatialSubsetDictionary)
56csmlbundle=csmlContainer.getContents()
57
58print '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
Note: See TracBrowser for help on using the repository browser.