source: TI02-CSML/trunk/csml/DDC/ddcsubset.py @ 2123

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/DDC/ddcsubset.py@2123
Revision 2123, 1.6 KB checked in by domlowe, 12 years ago (diff)

adding DDC testfiles to SVN (to be removed later)

Line 
1'''apicalls.py  - test the api'''
2
3import csml,sys
4
5f='./DDC2/DDC2out.xml'
6
7#Initialise the CSML container
8csmlContainer=csml.API.csmlContainer.Container(csmlpath='./DDC2/DDC2subs.xml',docID="subsdoc_2", metadata='DDC Subsetted Data')
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() 
17#print '\n Here are all the features in %s:' %f
18#print flist
19
20#select a feature by name (gml:id)
21#print '\n Selecting feature with gml:id = %s' %flist[1]
22feature=csmldoc.getFeature(flist[0])
23
24#feature 'bestname'
25#print feature.id
26#print feature.description
27
28#get the domain of the feature
29
30print '\n The feature has domain:' 
31#print feature.getDomain()
32
33#get list of allowed subsettings
34print '\n the following feature subsetting operations are allowed:'
35#print feature.getAllowedSubsettings()
36
37
38#define a selection (based on the domain)
39subsetDictionary={}
40subsetDictionary['time']=('1985-1-15T0:0:0.0','1985-4-15T0:0:0.0')
41subsetDictionary['latitude']=(40, 41)
42subsetDictionary['longitude']=(0,4)
43#request subsetted data from features (can set paths here) and add to container
44#subset a feature
45csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary))
46subsetDictionary['longitude']=(-1,4)
47csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile2.nc',**subsetDictionary))
48
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.