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

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

Basic csml i/o - reading csml doc and extracting correct data from file

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
43featureValues=csml.getDataForFeature('solar_3')
44print type(featureValues)
45#print dir(featureValues)
46#print featureValues
47#print 'Feature rangeSet:' +str(featureValues)
48sys.exit()
49
50#get gml description (long name) of feature
51#fdesc= csml.getFeatureDescription('feat04')
52#print fdesc
53
54#get list of file extracts by gml:id
55fileExtractList=csml.getFileExtractList()
56#print fileExtractList
57
58
59
60#get data from file extract (supply name):
61#currently returns a list, but may need to consider masked arrays
62#dataArray = csml.getData(fileExtractID)
63#dataArray = csml.getData('feat04times')
64for extract in fileExtractList:
65    print extract
66    dataArray=csml.getDataForExtract(extract)
67    #print extract
68    #print dataArray
69
70#dataArray = csml.getData('2__ncextract_latitude')
71#print dataArray
72
73
74#Alternatively you can call getDatasetObj and then directly
75#interrogate the Parser.Dataset object returned thus bypassing the csmlio wrapper functions
76dataset = csml.getDatasetObj()
77#print dir(dataset)
78
Note: See TracBrowser for help on using the repository browser.