source: TI02-CSML/trunk/csml/testfiles/apicalls.py @ 2208

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

fixes to do with arrays/lists/nearestneighbours

RevLine 
[1901]1'''apicalls.py  - test the api'''
2
[1929]3import csml,sys
[1901]4
[1939]5f='./testfiles/gridseries/testout.xml'
[1901]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
[2205]26#print feature.description
[1901]27
28#get the domain of the feature
29
30print '\n The feature has domain:' 
[1932]31print feature.getDomain()
[1901]32
33#get list of allowed subsettings
34print '\n the following feature subsetting operations are allowed:'
35print feature.getAllowedSubsettings()
36
37
[1932]38#define a selection (based on the domain)
39subsetDictionary={}
[2206]40subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
41#subsetDictionary['t']=()
42subsetDictionary['latitude']=(-90,60)
[1932]43subsetDictionary['longitude']=(-31.265,30.258)
[2207]44
[1901]45#request subsetted data from features (can set paths here) and add to container
46#subset a feature
[2208]47#csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary))
[1901]48#subset another feature (in fact it's the same feature again, but it proves the concept)
[2207]49subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
[2208]50subsetDictionary['latitude']=(75.)
51subsetDictionary['longitude']=(48.8)
[2207]52csmlContainer.add(feature.subsetToProfileSeries(ncpath='myfile2.nc',**subsetDictionary))
[1901]53
54#when you have finished, get the contents of the container
55csmlbundle=csmlContainer.getContents()
56print 'CSML %s'%csmlbundle[0] # csml document
57paths=csmlbundle[1:]
58print paths #paths to netcdf files
Note: See TracBrowser for help on using the repository browser.