Ignore:
Timestamp:
06/02/07 15:43:35 (13 years ago)
Author:
domlowe
Message:

units and missing values now working properly in subsetgridseries

Location:
TI02-CSML/trunk/csml/API
Files:
4 edited

Legend:

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

    r2095 r2112  
    122122 
    123123def getTheData(feature, selection, times,timeName): 
     124    #SOME OF THIS SHOULD PROBABLY BE IN THE DATA IO LAYER 
    124125    domain = feature.domain 
    125126    value=feature.value 
     
    133134    #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... 
    134135    filesFetched=[] 
    135      
    136      
    137136    for time in times: 
    138137        listPosition=domain[timeName].index(time) 
    139138        strTimes= strTimes + ' ' + time 
     139        print value.rangeSet.valueArray.valueComponent.href 
    140140        for comp in csmlutils.listify(value.rangeSet.valueArray.valueComponent.quantityList.__insertedExtract.components):  
    141141            filePos=int(float(listPosition)/timeToFileRatio) 
    142142            if filePos in filesFetched: 
    143143                continue #already got data from this file, try next time 
    144             data=comp.getData(fileposition=filePos, **selection) 
     144            data, fillvalue=comp.getData(fileposition=filePos, **selection) 
    145145            files.append(comp.fileList.fileNames.CONTENT[filePos]) #TODO, get the right file name 
    146146            if fulldata ==[]: 
     
    150150                    fulldata.append(item) 
    151151            filesFetched.append(filePos) 
    152         axisorder = data.getAxisIds()  #will need later! 
    153    
    154     return strTimes, axisorder, fulldata 
     152        axisorder = data.getAxisIds()  
     153        units=[] 
     154        for axis in axisorder: 
     155            ax=data.getAxis(data.getAxisIndex(axis)) 
     156            if hasattr(ax, 'units'): 
     157                units.append(ax.units) 
     158            else: 
     159                units.append(None)                  
     160        units.append(value.rangeSet.valueArray.valueComponent.quantityList.uom) # final unit is that of the variable itself 
     161    return strTimes, axisorder, units, fulldata, fillvalue 
    155162 
    156163def genericSubset(feature, csmlpath, ncpath, domain, kwargs): 
  • TI02-CSML/trunk/csml/API/ops_Dataset.py

    r2061 r2112  
    3939    #returns a list of feature ids for the dataset 
    4040    self.featureList = [] 
    41     for member in self.featureCollection.featureMembers: 
     41    for member in csml.csmllibs.csmlextra.listify(self.featureCollection.featureMembers): 
    4242            self.featureList.append(member.id) 
    4343    return self.featureList 
     
    4545def getFeature(self, featureID): 
    4646    """ returns a single feature object """ 
    47     for member in self.featureCollection.featureMembers: 
     47    for member in csml.csmllibs.csmlextra.listify(self.featureCollection.featureMembers): 
    4848            if member.id == featureID: 
    4949                return member     
    5050 
    5151def getFileExtract(self,extractID): 
    52         for extract in self.dataset.arrayDescriptors: 
     52        for extract in csml.csmllibs.csmlextra.listify(self.dataset.arrayDescriptors): 
    5353            if  extract.id==extractID: 
    5454                return extract  
  • TI02-CSML/trunk/csml/API/ops_FileExtract.py

    r2071 r2112  
    2424    DI=DI.getUnknownInterfaceType(file) 
    2525    DI.openFile(file) 
     26    DI.setAxis(self.variableName.CONTENT) 
    2627     
    2728    try: 
    2829        DI.setAxis(self.variableName.CONTENT) 
    2930        data=DI.getDataForAxis() 
     31        fillvalue=None 
    3032    except: 
    3133        DI.setVariable(self.variableName.CONTENT) 
     34        #get fill value (if there is one)    
     35        fillvalue=DI.getVariableAttribute('_FillValue') 
    3236        if kwargs: 
    3337            #print 'getting data for %s'%kwargs 
     
    3640            data = DI.getDataForVar() 
    3741    DI.closeFile() 
    38     return data 
     42    return data, fillvalue 
    3943         
    4044def __calendar(file,timedim): 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2105 r2112  
    2525        name=gridOrd.coordAxisLabel.CONTENT 
    2626        if hasattr(gridOrd.coordAxisValues, '__insertedExtract'): 
    27             self.domain[name]=gridOrd.coordAxisValues.__insertedExtract.getData() 
     27            self.domain[name], fill=gridOrd.coordAxisValues.__insertedExtract.getData() 
    2828        else: 
    2929            vals=gridOrd.coordAxisValues.coordinateList.CONTENT 
     
    5959    
    6060     
    61     strTimes, axisorder, fulldata=csml.API.genSubset.getTheData(self, selection, times, timeName) 
     61    strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 
    6262    
    6363     
     
    6666     
    6767    # define domain/coverage  to use in 'value' attribute    
    68     domain=csml.parser.GridSeriesDomain() 
     68    newdomain=csml.parser.GridSeriesDomain() 
    6969    domainSubset, totalArraySize=csml.API.genSubset.subsetDomain(timeName,strTimes,self.domain, **kwargs) 
    7070    cTT=csml.API.genSubset.getCoordTransformTable(domainSubset, crs) 
    71     domain.coordTransformTable=cTT 
     71    newdomain.coordTransformTable=cTT 
    7272    rangeSet=csml.parser.RangeSet() 
    7373    rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     
    7676    cvg=csml.parser.GridSeriesCoverage() 
    7777    cvg.rangeSet=rangeSet 
    78     cvg.gridSeriesDomain=domain     
     78    cvg.gridSeriesDomain=newdomain     
    7979    csmlWrap=csml.csmllibs.csmlfeaturewrap.CSMLWrapper() 
    8080     
     
    8686    nc=csml.csmllibs.netCDFWriter.NCwriter(pathToSubsetNetCDF) 
    8787    ords=cTT.gridOrdinates 
    88     nc.genWriteVar(self.id,ords, times, calunits, caltype, axisorder, fulldata) 
     88    nc.genWriteVar(self.id,ords, times, calunits, caltype, axisorder, units, fulldata, fillvalue) 
    8989    nc.closeFinishedFile() 
    9090     
Note: See TracChangeset for help on using the changeset viewer.