source: TI02-CSML/trunk/parser/oldapi/apiDemo.py @ 1012

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/parser/oldapi/apiDemo.py@1178
Revision 1012, 3.0 KB checked in by domlowe, 14 years ago (diff)

moving files

Line 
1#!/usr/bin/env python
2
3#callstoapi.py
4#This document contains example calls to Parser csml api
5#Dominic Lowe 17th May 2006
6
7#import csml interface module:
8from csmldoc import *
9
10def main():
11    #opens (and parses) a csml file:
12    #f='gridseriestest.xml'
13    f='coapec.xml'
14    print '\n ----------------------------------------------------------------------------- \n Initialising dataset from file %s.' %f
15    csml=CSMLDataset(f)
16   
17    featureList = csml.getFeatureList()
18    print '\n Here are all the features in %s:' %f
19    print featureList
20   
21   
22    print '\n Selecting feature with gml:id = %s' %featureList[5]
23    #csml.getFeature is the method to  get a particular feature by name.
24    feature=csml.getFeature(featureList[5])
25    print '\n the best name for the feature is %s '%feature.getBestName()
26    print '\n The feature has the following methods:'
27    print '\n Feature is of type: %s' % feature.getFeatureType()
28    print '\n The feature has domain:' 
29    print feature.getDomain()
30    print '\n the following feature subsetting operations are allowed:'
31    print feature.getAllowedSubsettings()
32    #timeSelection=['2783-05-22T00:00:00', '2793-03-30T00:00:00']
33    timeSelection=['2778-12-14T00:00:00', '2779-12-09T00:00:00', '2780-12-03T00:00:00', '2781-11-28T00:00:00', '2782-11-23T00:00:00' ,'2783-11-18T00:00:00']
34    #timeSelection=['2783-05-22T00:00:00', '2793-03-30T00:00:00']
35    spatialSubsetDictionary= {}
36    spatialSubsetDictionary['latitude']=(0.,10.0)
37    spatialSubsetDictionary['longitude']=(90, 120.0)
38    subsetCSML, subsetNetCDF=feature.subsetToGridSeries(timeSelection, **spatialSubsetDictionary)
39    print subsetCSML
40    print subsetNetCDF
41    #try and call the test method on different types of feature
42#
43#     feature=csml.getFeature('feat01') #this happens to be a Point feature
44#     print "\n POINT FEATURE:  " + 'feat01'
45#     print 'Test method: ' + feature.testMethod()
46#     
47#     #Get another feature
48#     feature=csml.getFeature('feat02') #this happens to be a PointSeries feature
49#     print "\n POINTSERIES FEATURE " + 'feat02'
50#     print 'Test method: ' + feature.testMethod()
51#     
52#     #and another - this time, the testMethod is not overwritten (see csmldoc.py for details)
53#     feature=csml.getFeature('feat03') #this happens to be a Profile feature
54#     print "\n PROFILE FEATURE " + 'feat03'
55#     print 'Test method: ' + feature.testMethod()
56#
57#     #if these calls to getFeature have worked you should see different results for feature.testMethod() depending on the type of feature.
58#         
59#     '''Note:feature also has an attribute 'parsedFeature' which enables lower level access direct to Parser attributes/methods if required - although hopefully this will be avoided and access will usually be via higher level methods'''
60#     print '\n And to show you can do it here is something extracted from the low level parser objects:'
61#     print feature.parsedFeature.rangeSet.dataBlock.rangeParameters.valueComponents[0].uom
62#     print '\n'
63main()
Note: See TracBrowser for help on using the repository browser.