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

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

subsetting ProfileSeries? to Profile working more or less

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#print '\n this is the bounding box of the whole feature collection: '
15#print csmldoc.getBoundingBox
16#sys.exit()
17
18
19
20#get list of features in the dataset
21flist= csmldoc.getFeatureList() 
22print '\n Here are all the features in %s:' %f
23print flist
24for feature in  flist:
25    print feature
26    print flist.index(feature)
27
28#select a feature by name (gml:id)
29print '\n Selecting feature with gml:id = %s' %flist[47]
30feature=csmldoc.getFeature(flist[47])
31
32#feature 'bestname'
33print feature.id
34#print feature.description
35
36#get the domain of the feature
37
38print '\n The feature has domain:' 
39print feature.getDomain()
40
41#get list of allowed subsettings
42print '\n the following feature subsetting operations are allowed:'
43print feature.getAllowedSubsettings()
44
45
46#define a selection (based on the domain)
47subsetDictionary={}
48#subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
49##subsetDictionary['t']=()
50#subsetDictionary['latitude']=(-90,60)
51#subsetDictionary['longitude']=(-31.265,30.258)
52
53#request subsetted data from features (can set paths here) and add to container
54#subset a feature
55#csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary))
56#subset another feature (in fact it's the same feature again, but this time subsetting to a profileseries)
57#subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0')
58subsetDictionary['latitude']=(75)
59subsetDictionary['longitude']=(45)
60csmlContainer.add(feature.subsetToProfileSeries(ncpath='myfile2.nc',**subsetDictionary))
61
62#when you have finished, get the contents of the container
63csmlbundle=csmlContainer.getContents()
64print 'CSML %s'%csmlbundle[0] # csml document
65paths=csmlbundle[1:]
66print paths #paths to netcdf files
Note: See TracBrowser for help on using the repository browser.