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

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

subsetting of profileseries, pointseries retested and fixed

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