source: TI02-CSML/trunk/parser/ioDemo.py @ 929

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

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