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

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

fixing example parser and point series subsetting of inline content

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#get  'gml:id' xml attribute
30print feature.id
31
32#get the contents of the feature <description> element
33print feature.description.CONTENT
34
35#get the domain of the feature
36print '\n The feature has domain:' 
37print feature.getDomain()
38
39#get list of allowed subsettings
40print '\n the following feature subsetting operations are allowed:'
41print feature.getAllowedSubsettings()
42
43
44#define a selection (based on the domain)
45#subsetDictionary={}
46##subsetDictionary['time']=('2794-12-1T0:0:0.0', '2804-12-1T0:0:0.0')
47#subsetDictionary['time']='2704-12-01T00:00:00.0'
48##subsetDictionary['latitude']=(-90,60)
49##subsetDictionary['longitude']=(-31.1265,30.258)
50#subsetDictionary['latitude']=(-5,5)
51#subsetDictionary['longitude']=(-31.1265,30.258)
52#request subsetted data from features (can set paths here) and add to container
53#subset a feature
54
55#f.subsetToGridSeries(ncname='tmp1.nc', outputdir='.', latitude=(-90, 90), longitude=(-180,180), time='1975-07-15T00:00:00.0')
56
57    #csmlContainer.add(feature.subsetToGridSeries(outputdir,ncname='mygridseries.nc',**subsetDictionary))
58csmlContainer.add(feature.subsetToGridSeries(outputdir,ncname='mygridseries.nc',latitude=(-90,90), longitude=(-180,180),time=('2804-12-01T00:00:00.0','2904-12-01T00:00:00.0')))
59
60#csmlContainer.add(feature.subsetToGridSeries(outputdir,ncname='mygridseries.nc',latitude=(60), longitude=(180),time=('2804-12-01T00:00:00.0','2904-12-01T00:00:00.0')))
61
62##subset another feature (in fact it's the same feature again, but this time subsetting to a profileseries)
63#subsetDictionary={}
64#subsetDictionary['time']=('2804-12-01T00:00:00.0','2904-12-01T00:00:00.0')
65#subsetDictionary['latitude']=(75)
66#subsetDictionary['longitude']=(45)
67
68###assigning profileseries feature to variable
69##print 'subset grid to profileseries'
70#psfeature, file, descriptor =feature.subsetToProfileSeries(outputdir, ncname='myprofileseries.nc',**subsetDictionary)
71#csmlContainer.add([psfeature,file, descriptor])
72
73#csmlContainer.add(feature.subsetToProfileSeries(outputdir,ncname='myprofileseries.nc',latitude=(75), longitude=(45),time=('2804-12-01T00:00:00.0','2904-12-01T00:00:00.0')))
74
75##Now subset this New ProfileSeries feature into a Profile feature
76#print 'subset  profileseries to profile'
77#subsetDictionary={}
78#subsetDictionary['time']=('2804-12-01T00:00:00.0')
79#csmlContainer.add(psfeature.subsetToProfile(outputdir, ncname='myprofile.nc',**subsetDictionary))
80
81
82#Now try the subset to profile method of the grid series feature -BROKEN
83print 'subsetting gridseries to profile'
84subsetDictionary={}
85subsetDictionary['time']=('2804-12-01T00:00:00.0')
86subsetDictionary['latitude']=(80)
87subsetDictionary['longitude']=(55)
88csmlContainer.add(feature.subsetToProfile(outputdir, ncname='myprofile.nc',**subsetDictionary))
89
90#Now try the subset to PointSeries method of the grid series feature
91print 'subsetting gridseries to pointseries'
92subsetDictionary={}
93subsetDictionary['time']=('2804-12-01T00:00:00.0','2904-12-01T00:00:00.0')
94subsetDictionary['latitude']=80
95subsetDictionary['longitude']=55
96#subsetDictionary['pressure']=(0)  #BROKEN
97csmlContainer.add(feature.subsetToPointSeries(outputdir,ncname='mypointseries.nc',**subsetDictionary))
98
99
100
101#when you have finished, get the contents of the container
102csmlbundle=csmlContainer.getContents()
103print 'CSML %s'%csmlbundle[0] # csml document
104paths=csmlbundle[1:]
105print paths #paths to netcdf files
106
Note: See TracBrowser for help on using the repository browser.