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

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

fixing ID/naming issues and paths

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