Changeset 3068


Ignore:
Timestamp:
29/11/07 10:10:34 (12 years ago)
Author:
domlowe
Message:

fixed subsetting bug when handling times, and also removed dependence on longitude/latitude names

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

Legend:

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

    r3049 r3068  
    3939            if kwargs[kw][0] == kwargs[kw][1]: 
    4040                kwargs[kw]=kwargs[kw][0] 
    41      
    42      
    4341    strTimes=times 
    4442    subsetDomain={} 
     
    145143        times= domain[timeName] 
    146144    tone=csml.csmllibs.csmltime.getCDtime(times[0]) 
     145     
    147146    if len(times) == 2: 
    148147        #then this is a range of times (t1, tn), and not a list  
     
    204203 
    205204 
    206 def getTheData(feature, selection, times,timeName): 
     205def getTheData(feature, selection, times,timeName, timeAxis): 
    207206    #SOME OF THIS SHOULD PROBABLY BE IN THE DATA IO LAYER 
    208207    #add time range back into the selection  
     208 
    209209    if len(times)==1: 
    210210        selection[timeName]=times[0] 
    211211    else: 
    212212         selection[timeName]=(times[0], times[len(times)-1]) 
    213  
    214213    domain = feature.domain 
    215214    value=feature.value 
     
    238237            if filePos in filesFetched: 
    239238                continue #already got data from this file, try next time           
    240             data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection)           
     239            data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection) 
    241240            if filePos is None: 
    242241                files.append(comp.fileName.CONTENT) 
     
    247246                    files.append(comp.fileName.CONTENT) 
    248247                 
    249     #open the file 
    250              
     248 
    251249             
    252250            if fulldata is None: 
     
    260258    else: 
    261259        units.append ('unitsTBA') 
     260  
    262261    return strTimes, axisorder, units, fulldata, fillvalue 
    263262 
     
    279278    cat=csml.csmllibs.csmlcrs.CRSCatalogue() 
    280279    if type(feature) == csml.parser.GridSeriesFeature: 
    281         crs=cat.getCRS(feature.value.gridSeriesDomain.srsName,labels=feature.value.gridSeriesDomain.axisLabels) 
     280        crs=cat.getCRS(feature.value.gridSeriesDomain.srsName) 
    282281        gridordinates = feature.value.gridSeriesDomain.coordTransformTable.gridOrdinates 
    283282    elif type(feature) == csml.parser.ProfileSeriesFeature: 
    284         crs=cat.getCRS(feature.value.profileSeriesDomain.srsName,labels = feature.value.profileSeriesDomain.axisLabels) 
     283        crs=cat.getCRS(feature.value.profileSeriesDomain.srsName) 
    285284        gridordinates = feature.value.profileSeriesDomain.coordTransformTable.gridOrdinates 
    286285    elif type(feature) == csml.parser.TrajectoryFeature: 
    287         crs=cat.getCRS(feature.value.trajectoryDomain.srsName,labels = feature.value.trajectoryDomain.axisLabels) 
     286        crs=cat.getCRS(feature.value.trajectoryDomain.srsName) 
    288287        gridordinates = feature.value.trajectoryDomain.coordTransformTable.gridOrdinates 
    289288    timeName=crs.axes[crs.timeAxis] 
     
    299298    except KeyError: 
    300299        timeSelection=[] 
    301      
    302300    times=_getTimes(timeSelection, timeName,domain)         
    303301    return pathToSubsetNetCDF, kwargs, timeAxis,timeName, caltype, times 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r3050 r3068  
    114114    #get the CRS from a  the  catalogue 
    115115    cat=csml.csmllibs.csmlcrs.CRSCatalogue() 
    116     crs=cat.getCRS(self.value.gridSeriesDomain.srsName, self.value.gridSeriesDomain.axisLabels 
     116    crs=cat.getCRS(self.value.gridSeriesDomain.srsName 
    117117     
    118118    #non-feature specific setup code, mainly handles the time dimension/calendar 
    119119     
    120120    pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, self.outputdir, self.ncname, self.domain, kwargs) 
    121        
    122121    ##Get names of variables in file and relate them to the subset selection  
    123122    selection={} 
     
    126125    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    127126        try: 
    128             selection[gridOrd.gridAxesSpanned.CONTENT]=kwargs[gridOrd.coordAxisLabel.CONTENT] 
     127            selection[gridOrd.gridAxesSpanned.CONTENT]=kwargs[gridOrd.coordAxisLabel.CONTENT]             
    129128        except KeyError: 
    130129            allValues=tuple(self.domain[gridOrd.coordAxisLabel.CONTENT]) 
     
    140139    selection=self.getSliceIndices(selection)                 #commented out while fixing subsetting 
    141140 
    142     strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 
     141    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName, timeAxis) 
    143142    return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    144143     
     
    153152    pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(**kwargs)  
    154153    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
    155     #Writing out the CSML feature 
     154    #Writing out the CSML feature     
    156155     
    157156    # define domain/coverage  to use in 'value' attribute    
     
    248247    cat = csml.csmllibs.csmlcrs.CRSCatalogue() 
    249248    crsInfo=cat.determineCRS(knownCRSAxes=axes)     
    250     crs=cat.getCRS(crsInfo[0].srsName, labels=axes) 
     249    crs=cat.getCRS(crsInfo[0].srsName) 
    251250     
    252251    newdomain.coordTransformTable=cTT     
  • TI02-CSML/trunk/csml/API/ops_TrajectoryFeature.py

    r2979 r3068  
    1515    srsname=self.value.trajectoryDomain.srsName 
    1616    cat=csml.csmllibs.csmlcrs.CRSCatalogue() 
    17     crs=cat.getCRS(srsname,self.value.trajectoryDomain.axisLabels)       
     17    crs=cat.getCRS(srsname)       
    1818    axID=None 
    1919    if name == 'lon': 
  • TI02-CSML/trunk/csml/csmllibs/csmlcrs.py

    r3065 r3068  
    227227        return crs, axisorder 
    228228 
    229     def determineCRS(self, axes=None, units=None, stdNames=None): 
     229    def determineCRS(self, axes=None, units=None, knownCRSAxes=None,stdNames=None): 
    230230        '''given any list of axis names and a list of units for these axes attempt to determine the CRS and return the CRSystem object and an axis order list. 
    231231        e.g passing in: (axes=['t', 'ht', 'latitude', 'longitude'],units=['days since 1991-09-01 00:00:00', 'm', 'degrees_north', 'degrees_east']) 
     
    235235        axisorder=[] 
    236236        crs =None 
    237          
    238         #build a map of axes and units - use std names to help! 
    239         crsMap=[] 
    240         for axis in axes: 
    241             if stdNames[axes.index(axis)]: 
    242                 unittype=stdNames[axes.index(axis)] 
    243             else: 
    244                 unit=units[axes.index(axis)] 
    245                 unittype=self.getUnitType(unit)             
    246             crsMap.append(unittype) 
    247                
     237        if knownCRSAxes is not None: 
     238            crsMap=knownCRSAxes          
     239        else: 
     240            #build a map of axes and units - use std names to help! 
     241            crsMap=[] 
     242            for axis in axes: 
     243                if stdNames[axes.index(axis)]: 
     244                    unittype=stdNames[axes.index(axis)] 
     245                else: 
     246                    unit=units[axes.index(axis)] 
     247                    unittype=self.getUnitType(unit)             
     248                crsMap.append(unittype)               
    248249        match=0 
    249250        #now try and match up crsMap with known crsystems.         
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r3067 r3068  
    465465 
    466466    def getSubsetOfDataForVar(self, **kwargs):       
    467             
    468                 
    469         #put any slicing indices aside for later and use names     
     467        #put any slicing indices aside for later and use names             
    470468        try: 
    471469            upper=kwargs['upper'] 
     
    502500                            subset=subset1 
    503501            if type(subset) is not cdms.tvariable.TransientVariable: 
     502                for k in kwargs: 
     503                    if k=='time': 
     504                        kwargs[k]=(kwargs[k][0],kwargs[k][1],'ocb') #see cdms docs: 'mysterious third argument' 
    504505                subset=self.file(self.varobj.id,**kwargs) 
    505506        except:               
  • TI02-CSML/trunk/csml/csmllibs/csmltime.py

    r2894 r3068  
    7474        month=int(timecheck.split('-')[1]) 
    7575        day=int(timecheck.split('-')[2].split('T')[0]) 
    76         tcheck=cdtime.comptime(year,month,day) 
     76        hour=int(timecheck.split('T')[1].split(':')[0]) 
     77        minute=int(timecheck.split('T')[1].split(':')[1]) 
     78        sec=int(timecheck.split('T')[1].split(':')[2].split('.')[0]) 
     79        tcheck=cdtime.comptime(year,month,day, hour, minute, sec) 
    7780        timeok=0 
    7881        if tcheck.cmp(timemin) >= 0: 
Note: See TracChangeset for help on using the changeset viewer.