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

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

fix to CRS catalogue and to ops_gridseriesfeature

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