source: TI02-CSML/trunk/csml/testfiles/gridseries/subset.py @ 2520

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/testfiles/gridseries/subset.py@2520
Revision 2520, 3.0 KB checked in by domlowe, 12 years ago (diff)

fixed list bug in csmlfeaturetypes.py

Line 
1'''apicalls.py  - test the api'''
2
3import csml,sys
4
5f='../gridseries/testout.xml'
6
7#Initialise the CSML container
8csmlContainer=csml.API.csmlContainer.Container(csmlpath='out.xml',docID="mycsmldoc_1", metadata="mymetadatastring")
9
10#Initialise and parse the dataset
11csmldoc = csml.parser.Dataset()
12csmldoc.parse(f)
13
14#csmltree=csmldoc.toXML() 
15#print csml.parser_extra.PrettyPrint(csmltree)
16#sys.exit()
17
18#get list of features in the dataset
19flist= csmldoc.getFeatureList() 
20print '\n Here are all the features in %s:' %f
21print flist
22
23
24#select a feature by name (gml:id)
25print '\n Selecting feature with gml:id = %s' %flist[4]
26feature=csmldoc.getFeature(flist[4])
27
28#feature 'bestname'
29print feature.id
30print feature.description.CONTENT
31
32#get the domain of the feature
33
34print '\n The feature has domain:' 
35print feature.getDomain()
36
37#get list of allowed subsettings
38print '\n the following feature subsetting operations are allowed:'
39print feature.getAllowedSubsettings()
40
41
42#define a selection (based on the domain)
43subsetDictionary={}
44subsetDictionary['time']=('2794-12-1T0:0:0.0', '2804-12-1T0:0:0.0')
45#subsetDictionary['latitude']=(-90,60)
46#subsetDictionary['longitude']=(-31.1265,30.258)
47subsetDictionary['latitude']=(-5,5)
48subsetDictionary['longitude']=(-31.1265,30.258)
49#request subsetted data from features (can set paths here) and add to container
50#subset a feature
51csmlContainer.add(feature.subsetToGridSeries(ncpath='mygridseries.nc',**subsetDictionary))
52
53#subset another feature (in fact it's the same feature again, but this time subsetting to a profileseries)
54subsetDictionary={}
55subsetDictionary['time']=('2794-12-1T0:0:0.0','2904-12-1T0:0:0.0')
56subsetDictionary['latitude']=(75)
57subsetDictionary['longitude']=(45)
58
59##assigning profileseries feature to variable
60#print 'subset grid to profileseries'
61psfeature, file, descriptor =feature.subsetToProfileSeries(ncpath='myprofileseries.nc',**subsetDictionary)
62csmlContainer.add([psfeature,file, descriptor])
63
64#Now subset this New ProfileSeries feature into a Profile feature
65#print 'subset  profileseries to profile'
66#subsetDictionary={}
67#subsetDictionary['time']=('2794-12-1T0:0:0.0')
68#csmlContainer.add(psfeature.subsetToProfile(ncpath='myprofile1.nc',**subsetDictionary))
69
70
71#Now try the subset to profile method of the grid series feature -BROKEN
72#subsetDictionary={}
73#subsetDictionary['time']=('2804-12-1T0:0:0.0')
74#subsetDictionary['latitude']=(80)
75#subsetDictionary['longitude']=(55)
76#csmlContainer.add(feature.subsetToProfile(ncpath='myprofile.nc',**subsetDictionary))
77
78#Now try the subset to PointSeries method of the grid series feature
79#subsetDictionary={}
80#subsetDictionary['time']=('2794-12-1T0:0:0.0','2904-12-1T0:0:0.0')
81#subsetDictionary['latitude']=(80)
82#subsetDictionary['longitude']=(55)
83##subsetDictionary['pressure']=(0)  #BROKEN
84#csmlContainer.add(feature.subsetToPointSeries(ncpath='mypointseries.nc',**subsetDictionary))
85
86
87
88#when you have finished, get the contents of the container
89csmlbundle=csmlContainer.getContents()
90print 'CSML %s'%csmlbundle[0] # csml document
91paths=csmlbundle[1:]
92print paths #paths to netcdf files
93
Note: See TracBrowser for help on using the repository browser.