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

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

basic temporal subsetting implemented, basic spatial part done

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