Changeset 2288 for TI02-CSML


Ignore:
Timestamp:
16/03/07 12:13:19 (13 years ago)
Author:
domlowe
Message:

subsetting grid to profileseries to profile 99 percent working..

Location:
TI02-CSML/trunk/csml
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/API/genSubset.py

    r2282 r2288  
    9999    except: 
    100100        csml.csmllibs.csmltime.setcdtimeCalendar(csml.csmllibs.csmltime.cdtime.DefaultCalendar) 
     101         
    101102    return calunits, caltype 
    102103 
     
    137138            return len(domain[timeName])/numFiles 
    138139 
    139 def getCoordTransformTable(domainSubset, crs): 
     140def getCoordTransformTable(domainSubset, crs, frame): 
    140141    cTT=csml.parser.GridCoordinatesTable() 
    141142    ords =[] 
     
    146147        go.coordAxisValues = csml.parser.SpatialOrTemporalPositionList() 
    147148        if key==crs.axes[crs.timeAxis]: 
    148             go.coordAxisValues.timePositionList=csml.parser.csString(domainSubset[key]) #self.domain.key placeholder 
     149            go.coordAxisValues.timePositionList=csml.parser.csString(domainSubset[key]) 
     150            go.coordAxisValues.frame = frame 
     151            #self.domain.key placeholder 
    149152        else: 
    150153            go.coordAxisValues.coordinateList=csml.parser.csString(domainSubset[key]) #self.domain.key placeholder 
     
    171174    #list to keep track of files that have already been fetched. eg. if multiple times are in a single file only need to get data from that file once... 
    172175    filesFetched=[] 
     176       
     177    if hasattr(value.rangeSet, 'arrayDescriptor'): 
     178        #then just dealing with one file. 
     179        componentlist = csmlutils.listify(value.rangeSet.arrayDescriptor) 
     180    else: 
     181        #dealing with aggregated array 
     182         componentlist = csmlutils.listify(value.rangeSet.valueArray.valueComponent.quantityList.__insertedExtract.components) 
     183        
    173184    for time in times: 
    174185        listPosition=domain[timeName].index(time) 
    175         strTimes= strTimes + ' ' + time 
    176         for comp in csmlutils.listify(value.rangeSet.valueArray.valueComponent.quantityList.__insertedExtract.components):  
    177             filePos=int(float(listPosition)/timeToFileRatio) 
     186        strTimes= strTimes + ' ' + time                     
     187        for comp in componentlist: 
     188            if timeToFileRatio == None: 
     189                filePos=None 
     190            else: 
     191                filePos=int(float(listPosition)/timeToFileRatio) 
    178192            if filePos in filesFetched: 
    179193                continue #already got data from this file, try next time           
    180             data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection) 
    181             files.append(comp.fileList.fileNames.CONTENT[filePos]) #TODO, get the right file name 
     194            data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection)           
     195            if filePos is None: 
     196                files.append(comp.fileName.CONTENT) 
     197            else: 
     198                files.append(comp.fileList.fileNames.CONTENT[filePos]) #TODO, get the right file name 
     199             
    182200            if fulldata is None: 
    183201                fulldata=data 
     
    186204                fulldata=newfulldata 
    187205            filesFetched.append(filePos) 
    188     units.append(value.rangeSet.valueArray.valueComponent.quantityList.uom) # final unit is that of the 
     206    if hasattr(value.rangeSet, 'valueArrayl'): 
     207        units.append(value.rangeSet.valueArray.valueComponent.quantityList.uom) # final unit is that of the parameter 
     208    else: 
     209        units.append ('unitsTBA') 
    189210    return strTimes, axisorder, units, fulldata, fillvalue 
    190211 
  • TI02-CSML/trunk/csml/API/ops_FileExtract.py

    r2275 r2288  
    3838    if fileposition is not None: 
    3939        file =self.fileList.fileNames.CONTENT.split()[fileposition] 
    40         #file=self.fileName.CONTENT.split()[fileposition] 
    4140    else: 
    4241        file=self.fileName.CONTENT 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2282 r2288  
    2929            self.domain[name], fill, axisorder, units=gridOrd.coordAxisValues.__insertedExtract.getData() 
    3030        else: 
    31             vals=gridOrd.coordAxisValues.coordinateList.CONTENT 
     31            try: 
     32                vals=gridOrd.coordAxisValues.coordinateList.CONTENT 
     33            except: 
     34                vals=gridOrd.coordAxisValues.timePositionList.CONTENT 
    3235            valList=[] 
    3336            for val in vals.split():   
     
    6265    ##Get names of variables in file and relate them to the subset selection  
    6366    selection={} 
     67    frame='' 
    6468    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    6569        try: 
     
    6771        except KeyError: 
    6872            allValues=tuple(self.domain[gridOrd.coordAxisLabel.CONTENT]) 
     73        if hasattr(gridOrd.coordAxisValues, 'timePositionList'): 
     74            if hasattr(gridOrd.coordAxisValues, 'frame'): 
     75                frame=gridOrd.coordAxisValues.frame 
     76 
    6977    del selection[timeAxis] #NOTE: Haven't resolved the single CRS issue so cannot subset by time within an individual file for now 
    7078    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 
    71     return pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs 
     79    return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    7280     
    7381def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    7482    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    75     pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     83    pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
    7684     
    7785    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
     
    8189    newdomain=csml.parser.GridSeriesDomain() 
    8290    domainSubset, totalArraySize=csml.API.genSubset.subsetDomain(timeName,strTimes,self.domain, **kwargs) 
    83     cTT=csml.API.genSubset.getCoordTransformTable(domainSubset, crs) 
     91    cTT=csml.API.genSubset.getCoordTransformTable(domainSubset, crs, frame) 
    8492    newdomain.coordTransformTable=cTT 
     93    newdomain.srsName=self.value.gridSeriesDomain.srsName   
     94    newdomain.axisLabels=self.value.gridSeriesDomain.axisLabels 
     95    newdomain.srsDimension=self.value.gridSeriesDomain.srsDimension 
    8596    rangeSet=csml.parser.RangeSet() 
    8697    rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     
    115126     
    116127    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    117     pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     128    pathToSubsetNetCDF, crs,frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
    118129     
    119130    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
     
    123134    newdomain=csml.parser.ProfileSeriesDomain() 
    124135    domainSubset, totalArraySize=csml.API.genSubset.subsetDomain(timeName,strTimes,self.domain, **kwargs) 
    125     cTT=csml.API.genSubset.getCoordTransformTable(domainSubset, crs) 
    126     newdomain.coordTransformTable=cTT 
     136    cTT=csml.API.genSubset.getCoordTransformTable(domainSubset, crs, frame)   
     137     
     138    #Need to remove location (lat/lon) axes from the cTT 
     139    newGridOrds=[] 
     140    for gridOrd in cTT.gridOrdinates: 
     141        if gridOrd.coordAxisLabel.CONTENT not in  ['latitude', 'longitude']: 
     142            newGridOrds.append(gridOrd) 
     143    cTT.gridOrdinates=newGridOrds 
     144    
     145     
     146     
     147    newdomain.coordTransformTable=cTT     
     148    #TODO need to remove 'location' from this srs 
     149    newdomain.srsName=self.value.gridSeriesDomain.srsName   
     150    newdomain.axisLabels=self.value.gridSeriesDomain.axisLabels 
     151    newdomain.srsDimension=self.value.gridSeriesDomain.srsDimension 
    127152    rangeSet=csml.parser.RangeSet() 
    128153    rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     
    155180    ords=cTT.gridOrdinates 
    156181    axislist=[] 
     182         
    157183    for a in axisorder: 
    158184        axislist.append(self.gridnames[a]) 
    159     nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue) 
     185    nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue, latitude=kwargs[latName], longitude=kwargs[lonName]) 
    160186    nc.closeFinishedFile() 
    161187     
  • TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py

    r2225 r2288  
    99def getDomain(self): 
    1010    #returns domain as a dictionary of ordinates {name: [values], ...} 
     11    #For ProfileSeries this is a combination of the location attribute and the time ordinate. 
    1112    self.domain={} 
    1213    self.gridnames={} 
     
    1415        name=gridOrd.coordAxisLabel.CONTENT 
    1516        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 
     17        #handle time axis 
     18        if hasattr(gridOrd.coordAxisValues, 'timePositionList'):  #..it should do.. 
     19            if hasattr(gridOrd.coordAxisValues, '__insertedExtract'): 
     20                self.domain[name], fill, axisorder, units=gridOrd.timePositionList.__insertedExtract.getData() 
     21            else: 
     22                vals=gridOrd.coordAxisValues.timePositionList.CONTENT              
     23                valList=[] 
     24                for val in vals.split():   
     25                    valList.append(val) 
     26                self.domain[name]=valList 
     27        #handle other axes , eg pressure levels, but ignore location 
     28        #TODO should use lonAxis at latAxis from CRS rather than latitude, longitude. 
     29        if hasattr(gridOrd.coordAxisValues, 'coordinateList'):  
     30            if gridOrd.coordAxisLabel not in ['latitude', 'longitude']: 
     31                if hasattr(gridOrd.coordAxisValues, '__insertedExtract'): 
     32                    self.domain[name], fill, axisorder, units=gridOrd.coordinateList.__insertedExtract.getData() 
     33                else: 
     34                    vals=gridOrd.coordAxisValues.coordinateList.CONTENT              
     35                    valList=[] 
     36                    for val in vals.split():   
     37                        valList.append(val) 
     38                    self.domain[name]=valList 
    2439    return self.domain 
    2540 
    2641def _subsetProfileSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    27     '''this takes a selection from a ProfileSeries object ''' 
     42    '''this takes a temporal selection from a ProfileSeries object  - i.e. returns one or more 'profiles', can be used to make another ProfileSeriesFeature or a Profile feature in the case of a single selection''' 
    2843            
    2944    #set self.domain: 
     
    4156    ##Get names of variables in file and relate them to the subset selection  
    4257    selection={} 
     58     
     59     
    4360    for gridOrd in self.value.profileSeriesDomain.coordTransformTable.gridOrdinates: 
    4461        try: 
     
    5471    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs)  
    5572     
    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 
     73    #print crs 
     74    #print timeName 
     75    #print times 
     76    #print strTimes 
     77    #print calunits 
     78    #print caltype 
     79    #print axisorder 
     80    #print units 
     81    #print fillvalue 
     82    #print kwargs   
     83    #import sys 
    6784     
    6885     
    6986    (time, lat, lon)=(crs.axes[crs.timeAxis],crs.axes[crs.latAxis], crs.axes[crs.lonAxis]) 
     87    print axisorder 
    7088    for axis in axisorder: 
    7189        if axis not in [time, lat, lon]: 
  • TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py

    r2216 r2288  
    5252        self.nc.write(dataarray) 
    5353 
    54     def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, unitlist, fulldata, fillvalue): 
     54    def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, unitlist, fulldata, fillvalue, **kwargs): 
     55        #**kwargs may contain additional axes not contained in a GridCoordinatesTable - e.g latitude, longitude may be stored in other attribute not in the rectified grid. 
     56         
     57        axesdone=[] 
     58         
    5559        floatTimes=[] 
    5660        for time in times: 
     
    5862            floatTimes.append(time.value) 
    5963        self.addAxis('time',floatTimes,isTime=1,units=calunits,calendar=caltype) 
     64        axesdone.append('time') 
    6065        for ord in enumerate(ordinates): 
    6166            vals=[] 
     
    7883                if ax[1]==name: 
    7984                    position=ax[0] 
     85            axesdone.append(name) 
    8086            self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[position])#to do, units attribute for CF compliance 
     87         
     88        if kwargs is not None: 
     89            for kw in kwargs: 
     90                lon,lat=None,None 
     91                if kw=='longitude': 
     92                    lon=1 
     93                    name='longitude' 
     94                elif kw == 'latitude': 
     95                    lat=1 
     96                    name = 'latitude' 
     97                for ax in enumerate(axisorder): 
     98                    if ax[1]==name: 
     99                        position=ax[0] 
     100                vals=(kwargs[kw],) 
     101                self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[position]) 
    81102        self.addVariable(fulldata,varid, axisorder, fillvalue, units=unitlist[-1] ) #to do, units attribute for CF compliance 
    82103         
Note: See TracChangeset for help on using the changeset viewer.