source: TI02-CSML/trunk/newparser/ioDemo.py @ 896

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/newparser/ioDemo.py@896
Revision 896, 2.3 KB checked in by domlowe, 14 years ago (diff)

Added some checking for mandatory csml elements

Line 
1#!/usr/bin/env python
2
3#ioDemo.py
4#This document contains example calls to Parser csml io interface
5#Dominic Lowe 25th April 2006
6
7#import csml io module:
8from csmlio import *
9
10#instantiate CSMLinterface object:
11csml =CSMLinterface()
12
13#parse in CSML document:
14#csml.parse('example.xml')
15csml.parse('gridseriestest.xml')
16#csml.parse('nagridseries.xml')
17
18#return CSML document as string:
19#strCSML=csml.getCSMLasString()
20#print strCSML
21
22#get list of features by name (gml:id):
23featureList = csml.getFeatureList()
24#print featureList
25
26#get type of feature (supply feature name)
27#get types of all features
28for i in range(0, len(featureList)):
29    featureType = csml.getFeatureType(featureList[i])
30    print featureType
31
32
33#get type of single feature
34#eg featureType=csml.getFeatureType('feat04')
35
36domainref=csml.getDomainReference('solar_3')
37print 'domainref: ' + str(domainref)
38domaincomp=csml.getDomainComplement('solar_3')
39print 'domaincomp: ' + str(domaincomp)
40domain=csml.getDomain('solar_3')
41print 'domain: ' + str(domain)
42#featureValues=csml.getDataForFeature('solar_3', None)
43
44
45timelist = domainref['t']
46#make some selection from the available times/spatialdomain:
47timeSelection = timelist.split()[:2]
48spatialSubsetDictionary= {}
49spatialSubsetDictionary['latitude']=(0.,10.0)
50spatialSubsetDictionary['longitude']=(90, 100.0)
51
52featureValues=csml.getDataForFeature('solar_3', timeSelection, **spatialSubsetDictionary)
53
54print featureValues
55#print type(featureValues)
56#print dir(featureValues)
57
58#get gml description (long name) of feature
59#fdesc= csml.getFeatureDescription('feat04')
60#print fdesc
61
62#get list of file extracts by gml:id
63fileExtractList=csml.getFileExtractList()
64#print fileExtractList
65
66
67
68#get data from file extract (supply name):
69#currently returns a list, but may need to consider masked arrays
70#dataArray = csml.getData(fileExtractID)
71#dataArray = csml.getData('feat04times')
72#for extract in fileExtractList:
73  #  print extract
74    #dataArray=csml.getDataForExtract(extract)
75    #print extract
76    #print dataArray
77
78#dataArray = csml.getData('2__ncextract_latitude')
79#print dataArray
80
81
82#Alternatively you can call getDatasetObj and then directly
83#interrogate the Parser.Dataset object returned thus bypassing the csmlio wrapper functions
84dataset = csml.getDatasetObj()
85#print dir(dataset)
86
Note: See TracBrowser for help on using the repository browser.