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

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

nearest neighbour working for times, plus separation of subsetting into core functions and feature specific ones

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