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

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

spatial temporal selection on any axis implemented (for netcdf)

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')
37#print 'domainref: ' + str(domainref)
38domaincomp=csml.getDomainComplement('solar_3')
39#print 'domaincomp: ' + str(domaincomp)
40domain=csml.getDomain('solar_3')
41#print 'domain: ' + str(domain)
42#featureValues=csml.getDataForFeature('solar_3', None)
43
44
45timelist = domainref['t']
46#make some selection from the available times:
47timeSelection = timelist.split()[:2]
48#featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0))
49spatialSubsetDictionary= {}
50spatialSubsetDictionary['latitude']=(0.,10.0)
51spatialSubsetDictionary['longitude']=(90, 100.0)
52
53featureValues=csml.getDataForFeature('solar_3', timeSelection, **spatialSubsetDictionary)
54
55#same as:
56#featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0))
57print featureValues
58sys.exit()
59
60print type(featureValues)
61#print dir(featureValues)
62#print featureValues
63
64#print 'Feature rangeSet:' +str(featureValues)
65
66
67#get gml description (long name) of feature
68#fdesc= csml.getFeatureDescription('feat04')
69#print fdesc
70
71#get list of file extracts by gml:id
72fileExtractList=csml.getFileExtractList()
73#print fileExtractList
74
75
76
77#get data from file extract (supply name):
78#currently returns a list, but may need to consider masked arrays
79#dataArray = csml.getData(fileExtractID)
80#dataArray = csml.getData('feat04times')
81for extract in fileExtractList:
82    print extract
83    dataArray=csml.getDataForExtract(extract)
84    #print extract
85    #print dataArray
86
87#dataArray = csml.getData('2__ncextract_latitude')
88#print dataArray
89
90
91#Alternatively you can call getDatasetObj and then directly
92#interrogate the Parser.Dataset object returned thus bypassing the csmlio wrapper functions
93dataset = csml.getDatasetObj()
94#print dir(dataset)
95
Note: See TracBrowser for help on using the repository browser.