source: TI02-CSML/trunk/parser/apicalls.py @ 1438

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/parser/apicalls.py@1438
Revision 1438, 1.8 KB checked in by domlowe, 13 years ago (diff)

Fix for XML unicode problems (I think). Tests files to see what format they are then passes the correct encoding information to elementtree. Requres further testing

Line 
1'''apicalls.py  - test the api'''
2
3#from parser api import *
4import API
5
6f='../Scanner/test.xml'
7
8#Initialise and parse the dataset
9csml = API.Parser.Dataset()
10csml.parse(f)
11
12
13#get list of features in the dataset
14flist= csml.getFeatureList() 
15print '\n Here are all the features in %s:' %f
16print flist
17
18#select a feature by name (gml:id)
19print '\n Selecting feature with gml:id = %s' %flist[4]
20feature=csml.getFeature(flist[4])
21
22#feature 'bestname'
23print feature.id
24print feature.description
25
26#get the domain of the feature
27print '\n The feature has domain reference:' 
28print feature.getDomainReference()
29
30#get the domain complement of the feature
31print '\n The feature has domain complement :' 
32print feature.getDomainComplement()
33
34#get combined domain
35print '\n The feature has domain:' 
36#print 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 ref/complement)
44#timeSelection=['2881-3-16T0:0:0.0', '2881-4-16T0:0:0.0', '2881-5-16T0:0:0.0', '2881-6-16T0:0:0.0', '2881-7-16T0:0:0.0', '2881-8-16T0:0:0.0', '2881-9-16T0:0:0.0']
45timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0']
46
47spatialSubsetDictionary= {}
48spatialSubsetDictionary['latitude']=(-90,90)
49#spatialSubsetDictionary['longitude']=(330,359)
50spatialSubsetDictionary['longitude']=(-31.265,30.258)
51
52#request subsetted data from feature (can set paths here)
53subsetCSML, subsetNetCDF, arraySize=feature.subsetToGridSeries(timeSelection,  csmlpath='myfile.xml', ncpath='myfile.nc',**spatialSubsetDictionary)
54
55#parse and pretty print the result
56# strCSML=parser_extra.PrettyPrint(subsetCSML)
57# strCSML=parser_extra.removeInlineNS(strCSML)
58# print strCSML #csml document (string)
59print subsetCSML
60print subsetNetCDF # netcdf file (file)
61print 'arraySize: %s' %arraySize
Note: See TracBrowser for help on using the repository browser.