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

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

fixing bug with single time selection

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