Changeset 2395 for TI02-CSML/trunk


Ignore:
Timestamp:
11/04/07 12:18:15 (12 years ago)
Author:
domlowe
Message:

calendering now does not rely on "days since" etc.

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

Legend:

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

    r2389 r2395  
    8787            try: 
    8888                caltype=gridOrd.coordAxisValues.timePositionList.frame.split(':',2)[1] 
    89                 calunits=gridOrd.coordAxisValues.timePositionList.frame.split(':',2)[2] 
    9089                csml.csmllibs.csmltime.setcdtimeCalendar(caltype) 
    9190                calset=True 
     
    9594    try: 
    9695        caltype=gridOrd.coordAxisValues.timePositionList.frame.split(':',2)[1] 
    97         calunits=gridOrd.coordAxisValues.timePositionList.frame.split(':',2)[2] 
    9896        csml.csmllibs.csmltime.setcdtimeCalendar(caltype) 
    9997    except: 
    10098        csml.csmllibs.csmltime.setcdtimeCalendar(csml.csmllibs.csmltime.cdtime.DefaultCalendar)         
    101     return calunits, caltype 
     99    return caltype 
    102100 
    103101 
     
    184182        #dealing with aggregated array 
    185183         componentlist = csmlutils.listify(value.rangeSet.valueArray.valueComponent.quantityList.__insertedExtract.components) 
    186         
    187184    for time in times: 
    188185        listPosition=domain[timeName].index(time) 
     
    238235            break 
    239236    #set the reference system for the time axis 
    240     calunits, caltype=_setCalendar(feature, timeName, gridordinates) 
     237    caltype=_setCalendar(feature, timeName, gridordinates) 
    241238     
    242239    try: 
     
    246243     
    247244    times=_getTimes(timeSelection, timeName,domain)     
    248     return pathToSubsetNetCDF, kwargs, timeAxis,timeName, calunits, caltype, times 
     245    return pathToSubsetNetCDF, kwargs, timeAxis,timeName, caltype, times 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2393 r2395  
    6161     
    6262    #non-feature specific setup code, mainly handles the time dimension/calendar 
    63     pathToSubsetNetCDF, kwargs, timeAxis, timeName,calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
     63     
     64    pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
    6465       
    6566    ##Get names of variables in file and relate them to the subset selection  
     
    7677 
    7778    del selection[timeAxis] #NOTE: Haven't resolved the single CRS issue so cannot subset by time within an individual file for now 
     79    print timeName 
    7880    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 
    79     return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs 
     81 
     82    return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    8083     
    8184def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    8285    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    83     pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     86    pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
    8487     
    8588    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
     
    139142    for a in axisorder: 
    140143        axislist.append(self.gridnames[a]) 
    141     nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue) 
     144    nc.genWriteVar(self.id,ords, times, caltype, axislist, units, fulldata, fillvalue) 
    142145    nc.closeFinishedFile() 
    143146    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
     
    150153     
    151154    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    152     pathToSubsetNetCDF, crs,frame, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     155    pathToSubsetNetCDF, crs,frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
    153156     
    154157    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
     
    218221    for a in axisorder: 
    219222        axislist.append(self.gridnames[a]) 
    220     nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue, latitude=kwargs[latName], longitude=kwargs[lonName]) 
     223    nc.genWriteVar(self.id,ords, times, caltype, axislist, units, fulldata, fillvalue, latitude=kwargs[latName], longitude=kwargs[lonName]) 
    221224    nc.closeFinishedFile() 
    222225     
  • TI02-CSML/trunk/csml/csmllibs/csmlfeaturetypes.py

    r2387 r2395  
    145145                    timeposList=cp.TimePositionList() 
    146146                    timeposList.CONTENT=self.timeString 
    147                     timeposList.frame='ndg:%s:%s'%(self.caltype,self.units) 
     147                    timeposList.frame='ndg:%s'%self.caltype 
    148148                    sptList.timePositionList=timeposList 
    149149            else:  #for all other dimensions, create ordinates 
  • TI02-CSML/trunk/csml/csmllibs/csmltime.py

    r2357 r2395  
    108108    return cdTimeVal 
    109109 
     110def getBaseUnits(cdtime): 
     111    baseunit='days' 
     112    units=['second', 'minute', 'hour'] 
     113    for unit in units: 
     114        val=getattr(cdtime, unit) 
     115        if val > 0: 
     116            baseunit=unit 
     117            break 
     118    return '%s since %s'%(baseunit, cdtime) 
     119     
     120 
     121 
    110122def getFileTimeList(filelist, timedim): 
    111123        #**************************************************************************************** 
  • TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py

    r2389 r2395  
    5252        self.nc.write(dataarray) 
    5353 
    54     def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, unitlist, fulldata, fillvalue, **kwargs): 
     54    def genWriteVar(self,varid, ordinates, times, caltype, axisorder, unitlist, fulldata, fillvalue, **kwargs): 
    5555        #**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.      
    5656        axesdone=[] 
     57        floatTimes=[] 
    5758         
    58         floatTimes=[] 
     59        #determine base units for times: 
     60        tOne=csml.csmllibs.csmltime.getCDtime(times[0]) 
     61        tbase=csml.csmllibs.csmltime.getBaseUnits(tOne) 
     62         
    5963        for time in times: 
    60             time=csml.csmllibs.csmltime.getCDtime(time).torel(calunits) 
     64            time=csml.csmllibs.csmltime.getCDtime(time).torel(tbase) 
    6165            floatTimes.append(time.value) 
    62         self.addAxis('time',floatTimes,isTime=1,units=calunits,calendar=caltype) 
     66        self.addAxis('time',floatTimes,isTime=1,units=tbase,calendar=caltype) 
     67     
    6368        axesdone.append('time') 
    6469        if ordinates is not None: 
     
    100105                vals=(kwargs[kw],) 
    101106                self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[position]) 
    102                 axesdone.append(name) 
    103              
    104         print 'Axesdone:' 
    105         print axesdone 
    106         print axisorder 
    107          
     107                axesdone.append(name)         
    108108                 
    109109        self.addVariable(fulldata,varid, axisorder, fillvalue, units=unitlist[-1] ) #to do, units attribute for CF compliance 
Note: See TracChangeset for help on using the changeset viewer.