Changeset 2206 for TI02-CSML/trunk/csml


Ignore:
Timestamp:
26/02/07 14:03:46 (13 years ago)
Author:
domlowe
Message:

nearest neighbour working for times, plus separation of subsetting into core functions and feature specific ones

Location:
TI02-CSML/trunk/csml
Files:
1 deleted
7 edited
1 copied

Legend:

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

    r2159 r2206  
    5151 
    5252##GridSeriesFeature methods: 
    53 addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom]) 
     53addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom, ops_GridSeriesFeature._subsetGrid]) 
    5454 
    5555##TrajectoryFeature methods: 
  • TI02-CSML/trunk/csml/API/csmlutils.py

    r2156 r2206  
    11'''csml utils contains useful  utility functions''' 
    2  
     2import csml 
    33 
    44def listify(item): 
     
    4040        rtMessage="" 
    4141        newValue=None 
     42                 
     43        def __fixTimes(value, axisValues): 
     44            newValue = csml.csmllibs.csmltime.getTimeAsValue(value) 
     45            newAxisValues=[] 
     46            for ax in axisValues: 
     47                newAxisValues.append(csml.csmllibs.csmltime.getTimeAsValue(ax)) 
     48            return newValue, newAxisValues                
    4249         
    43         if value in axisValues: 
     50        if value in axisValues: 
    4451            newValue=value 
    45         else: 
     52        else:             
     53            if str(value).find('T') != -1: 
     54                value, axisValues=__fixTimes(value,axisValues) 
    4655            sortedAxis=[] 
    4756            for i in axisValues: 
    4857                sortedAxis.append(i) 
    49             sortedAxis.sort() 
    50              
     58            sortedAxis.sort()    
    5159            if value<sortedAxis[0]: 
    5260                newValue=sortedAxis[0] 
     
    6169                            nextone=current 
    6270                            current=tempc 
    63                      
    6471                        if value>current and value<nextone: 
    6572                            lowergap=value-current 
     
    7481            if newValue==None: 
    7582                rtMessage="%s axis selected value '%s' nudged to nearest value in real axis '%s' ;" % (axisType, value, newValue)        
    76                 print rtMessage          
    77                      
     83        #        print rtMessage                 
     84        if type(newValue) is float: 
     85            if len(str(int(newValue))) ==14: # it's a time 
     86                print newValue 
     87                newValue=csml.csmllibs.csmltime.convertValueToCSML(newValue)    
    7888        return (newValue)                             
  • TI02-CSML/trunk/csml/API/genSubset.py

    r2205 r2206  
    88 
    99def checkNeighbours(domain, gridnames, **kwargs): 
    10     print domain 
    1110    #for any non-range requests, get nearest neighbour 
    1211    #e.g if 'latitude': (11) requested, latitude=12 may be the nearest value 
     
    106105        times=timeSelection 
    107106     
    108     
    109     #times=timeSelection 
    110      
    111     print times 
    112     print len(times) 
    113107    if len(times)==0: 
    114108        #no time specified, select all. 
     
    176170            if filePos in filesFetched: 
    177171                continue #already got data from this file, try next time 
    178             print selection              
    179172            data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection) 
    180173            files.append(comp.fileList.fileNames.CONTENT[filePos]) #TODO, get the right file name 
     
    202195    crs=cat.getCRS(feature.value.gridSeriesDomain.srsName) 
    203196    timeName=crs.axes[crs.timeAxis] 
    204      #set the reference system for the time axis 
     197    #Find the original time name (timeAxis) for the file. 
     198    for gridOrd in feature.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
     199        if gridOrd.coordAxisLabel.CONTENT==timeName: 
     200            timeAxis = gridOrd.gridAxesSpanned.CONTENT  #only works for regular grids atm 
     201            break 
     202    #set the reference system for the time axis 
    205203    calunits, caltype=_setCalendar(feature, timeName) 
    206204     
    207205    #selection by time - get explcit time values, not just a range mint, maxt 
     206     
    208207    try: 
    209         timeSelection=kwargs[timeName] 
     208        timeSelection=kwargs[timeAxis] 
    210209    except KeyError: 
    211210        timeSelection=[] 
     211         
    212212    times=_getTimes(timeSelection, timeName,domain) 
    213213     
    214214     
    215     return pathToSubsetNetCDF, kwargs, timeName, calunits, caltype, times 
     215    return pathToSubsetNetCDF, kwargs, timeAxis,timeName, calunits, caltype, times 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2205 r2206  
    4444        uom =None 
    4545    return uom 
    46         
    47      
    48 def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    49         
     46 
     47def _subsetGrid(self, csmlpath=None, ncpath=None,**kwargs): 
     48    '''this takes a selection from a gridseries object (be it a profile, a grid, whatever, it is still just a selection''' 
     49            
    5050    #set self.domain: 
    5151    self.getDomain()       
     
    5353    #if request doesn't match domain points find nearest neighbours 
    5454    kwargs=csml.API.genSubset.checkNeighbours(self.domain, self.gridnames, **kwargs) 
    55      
    5655    #get the CRS from a  the  catalogue 
    5756    cat=csml.csmllibs.csmlcrs.CRSCatalogue() 
     
    5958     
    6059    #non-feature specific setup code, mainly handles the time dimension/calendar 
    61     pathToSubsetNetCDF, kwargs, timeName, calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
     60    pathToSubsetNetCDF, kwargs, timeAxis, timeName,calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
    6261       
    63     #Find the original time name (timeAxis) for the file. 
    64     for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    65         if gridOrd.coordAxisLabel.CONTENT==timeName: 
    66             timeAxis = gridOrd.gridAxesSpanned.CONTENT  #only works for regular grids atm 
    67         else:  
    68             print 'crs not supported' 
    69   
    7062    ##Get names of variables in file and relate them to the subset selection  
    7163    selection={} 
     
    7668            allValues=tuple(self.domain[gridOrd.coordAxisLabel.CONTENT]) 
    7769    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 
     70    return pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    7871     
     72def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     73    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
     74    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
    7975     
    8076    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
  • TI02-CSML/trunk/csml/csmllibs/csmltime.py

    r2196 r2206  
    6666                timeok = 1 
    6767    return timeok 
     68 
     69def getTimeAsValue(time): 
     70    year=int(time.split('-')[0]) 
     71    month=int(time.split('-')[1]) 
     72    day=int(time.split('-')[2].split('T')[0]) 
     73    hour=int(time.split('-')[2].split('T')[1].split(':')[0]) 
     74    minute=int(time.split('-')[2].split('T')[1].split(':')[1]) 
     75    second=float(time.split('-')[2].split('T')[1].split(':')[2]) 
     76    return (10000000000*year+100000000*month + (1000000 * day) + (10000*hour) + (100*minute) + second) 
     77 
     78def convertValueToCSML(t): 
     79    #this may need to be more robust 
     80    csmlt='%s-%s-%sT%s:%s:%s.%s'%(int(t/10000000000),str(int(t/100000000))[-2:],str(int(t/1000000))[-2:] 
     81,str(int(t/10000))[-2:],str(int(t/100))[-2:],str(int(t))[-2:],0) 
     82    return csmlt 
     83 
    6884 
    6985def getCDtime(time):  
  • TI02-CSML/trunk/csml/csmlprofilescan.py

    r2191 r2206  
    195195 
    196196if __name__=='__main__': 
    197     #print 'profiling..' 
     197    print 'profiling..' 
    198198    #profile.run('main()') 
    199     main() 
    200  
    201  
    202  
    203  
    204  
    205  
    206  
    207  
    208  
    209  
    210  
    211  
    212  
    213  
     199    profile.run('import csml') 
     200    subdir='/home/dom/Desktop/SVN/trunk/csml/chilbolton/' 
     201    f=[] 
     202    for item in os.listdir(subdir): 
     203        name=os.path.join(subdir,item) 
     204        if os.path.isfile(name): 
     205            if name[-3:]=='.nc': 
     206                f.append(name) 
     207    profile.run("csml.csmllibs.csmltime.getFileTimeList(f,'time')") 
     208     
     209     
     210    #main() 
     211 
     212 
     213 
     214 
     215 
     216 
     217 
     218 
     219 
     220 
     221 
     222 
     223 
     224 
  • TI02-CSML/trunk/csml/csmlscan.py

    r2191 r2206  
    194194 
    195195 
    196 if __name__=='__main__': 
    197     #print 'profiling..' 
    198     #profile.run('main()') 
     196if __name__=='__main__':     
    199197    main() 
    200198 
  • TI02-CSML/trunk/csml/testfiles/apicalls.py

    r2205 r2206  
    3838#define a selection (based on the domain) 
    3939subsetDictionary={} 
    40 subsetDictionary['t']=('2794-12-1T0:0:0.0', '2813-12-1T0:0:0.0') 
    41 subsetDictionary['latitude']=(-90,90) 
     40subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0') 
     41#subsetDictionary['t']=() 
     42subsetDictionary['latitude']=(-90,60) 
    4243subsetDictionary['longitude']=(-31.265,30.258) 
    4344#request subsetted data from features (can set paths here) and add to container 
Note: See TracChangeset for help on using the changeset viewer.