source: TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py @ 2225

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py@2282
Revision 2225, 4.7 KB checked in by domlowe, 13 years ago (diff)

more on profile features

Line 
1''' ops_ProfileSeriesFeature  contains operations for ProfileSeriesFeatures'''
2import csml
3
4def testmethod(self):
5    print 'testmethod for profileSeries feature'
6    return 'testmethod profileseries'
7
8
9def getDomain(self):
10    #returns domain as a dictionary of ordinates {name: [values], ...}
11    self.domain={}
12    self.gridnames={}
13    for gridOrd in self.value.profileSeriesDomain.coordTransformTable.gridOrdinates:
14        name=gridOrd.coordAxisLabel.CONTENT
15        self.gridnames[gridOrd.gridAxesSpanned.CONTENT]=name
16        if hasattr(gridOrd.coordAxisValues, '__insertedExtract'):
17            self.domain[name], fill, axisorder, units=gridOrd.coordAxisValues.__insertedExtract.getData()
18        else:
19            vals=gridOrd.coordAxisValues.coordinateList.CONTENT
20            valList=[]
21            for val in vals.split(): 
22                valList.append(val)
23            self.domain[name]=valList
24    return self.domain
25
26def _subsetProfileSeries(self, csmlpath=None, ncpath=None,**kwargs):
27    '''this takes a selection from a ProfileSeries object '''
28           
29    #set self.domain:
30    self.getDomain()     
31   
32    #if request doesn't match domain points find nearest neighbours
33    kwargs=csml.API.genSubset.checkNeighbours(self.domain, self.gridnames, **kwargs)
34    #get the CRS from a  the  catalogue
35    cat=csml.csmllibs.csmlcrs.CRSCatalogue()
36    crs=cat.getCRS(self.value.profileSeriesDomain.srsName) 
37   
38    #non-feature specific setup code, mainly handles the time dimension/calendar
39    pathToSubsetNetCDF, kwargs, timeAxis, timeName,calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs)
40     
41    ##Get names of variables in file and relate them to the subset selection
42    selection={}
43    for gridOrd in self.value.profileSeriesDomain.coordTransformTable.gridOrdinates:
44        try:
45            selection[gridOrd.gridAxesSpanned.CONTENT]=kwargs[gridOrd.coordAxisLabel.CONTENT]
46        except KeyError:
47            allValues=tuple(self.domain[gridOrd.coordAxisLabel.CONTENT])
48    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName)
49    return pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs
50           
51           
52def subsetToProfile(self, csmlpath=None, ncpath=None,**kwargs):
53    #perform the subset
54    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs) 
55   
56    print crs
57    print timeName
58    print times
59    print strTimes
60    print calunits
61    print caltype
62    print axisorder
63    print units
64    print fillvalue
65    print kwargs 
66    import sys
67   
68   
69    (time, lat, lon)=(crs.axes[crs.timeAxis],crs.axes[crs.latAxis], crs.axes[crs.lonAxis])
70    for axis in axisorder:
71        if axis not in [time, lat, lon]:
72            #this should be the 'profile' axis
73            prof=self.domain[axis]
74   
75   
76    #Okay, got the data now. Need to write CSML feature and NetCDF files.
77    #Writing out the CSML feature
78    # define domain/coverage  to use in 'value' attribute   
79   
80    newdomain=csml.parser.csString(prof)
81   
82    rangeSet=csml.parser.RangeSet()
83    #rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize))
84   
85    #gridseries coverage
86    cvg=csml.parser.ProfileSeriesCoverage()
87    cvg.rangeSet=rangeSet
88    cvg.profileSeriesDomain=newdomain   
89   
90    #parameter, as before subsetting.
91    param = self.parameter
92       
93    #create 'location' attribute:
94    loc=self.location  #locataion attribute of profile is same as that of parent profileseries
95   
96    #create 'time' attribute
97    tName=crs.axes[crs.timeAxis]
98    try:
99        t=kwargs[tName]
100    except:
101        t=csml.parser.csString('unknown')
102               
103    #create a stand alone profile feature containing this coverage
104    csmlWrap=csml.csmllibs.csmlfeaturewrap.CSMLWrapper()
105    subsettedFeature=csmlWrap.createProfileFeature(value=cvg,parameter=param,location=loc, time=t, featureID=self.id,description=self.description)
106 
107    ### write netcdf using NCWriter class (wraps cdms) ###
108    #nc=csml.csmllibs.netCDFWriter.NCwriter(pathToSubsetNetCDF)
109    #ords=None
110    #axislist=[]
111    #for a in axisorder:
112        #axislist.append(self.gridnames[a])
113    #nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue)
114    #nc.closeFinishedFile()
115    print 'NetCDF file written to %s'%pathToSubsetNetCDF
116    return subsettedFeature, pathToSubsetNetCDF
Note: See TracBrowser for help on using the repository browser.