source: TI02-CSML/branches/CSML2/testfiles/apicalls.py @ 1902

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/branches/CSML2/testfiles/apicalls.py@1902
Revision 1902, 2.1 KB checked in by domlowe, 13 years ago (diff)

beginning to refactor API module

Line 
1'''apicalls.py  - test the api'''
2
3import csml
4
5f='csml/testfiles/testcoapec.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
24#feature '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 features (can set paths here) and add to container
55#subset a feature
56csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile.nc',**spatialSubsetDictionary))
57#subset another feature (in fact it's the same feature again, but it proves the concept)
58csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile2.nc',**spatialSubsetDictionary))
59
60#when you have finished, get the contents of the container
61csmlbundle=csmlContainer.getContents()
62print 'CSML %s'%csmlbundle[0] # csml document
63paths=csmlbundle[1:]
64print paths #paths to netcdf files
Note: See TracBrowser for help on using the repository browser.