Changeset 2112 for TI02-CSML/trunk


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
Files:
8 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     
  • TI02-CSML/trunk/csml/csml2Moles/addnewElemTest.py

    r1904 r2112  
    2020    dgSK=M.dgStructuredKeyword(dgValidTerm=strValidTerm, dgValidTermID=dgVTID) 
    2121    dgMeta.dgMetadataRecord.addChildElem('dgStructuredKeyword', dgSK) 
     22     
     23 
    2224 
    2325    #regenerate XML from python 
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r2081 r2112  
    386386 
    387387    def getVariableAttribute(self,attName): 
    388  
    389         #atts=self.varobj.getattributes(attName) 
    390         #print atts 
     388        #NEED TO REWRITE THIS! 
    391389        if attName == 'long_name': 
    392390            try: 
     
    399397            except: 
    400398                attribValue='no_units_found' 
    401  
     399        elif attName == '_FillValue': 
     400            try: 
     401                attribValue=self.varobj._FillValue 
     402                attribValue=attribValue.toscalar() 
     403            except: 
     404                try: 
     405                    attribValue=self.varobj.missing_value 
     406                    attribValue=attribValue.toscalar() 
     407                except: 
     408                    attribValue = None   
    402409        return attribValue 
    403410 
  • TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py

    r2095 r2112  
    3636        pass 
    3737     
    38     def addVariable(self,data, variableName,axesList,  **kwargs): 
     38    def addVariable(self,data, variableName,axesList, fillvalue,  **kwargs):         
    3939        #creates a new variable containing data with named attributes from **kwargs 
    4040        dataarray=MV.array(data) 
     
    5050                        dataarray.setAxis(axisCount,ax) 
    5151                        axisCount = axisCount +1 
     52        setattr(dataarray, 'missing_value' ,fillvalue) 
    5253        self.nc.write(dataarray) 
    5354 
    54     def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, fulldata): 
     55    def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, unitlist, fulldata, fillvalue): 
    5556        floatTimes=[] 
    5657        for time in times: 
     
    7475                name='latitude' 
    7576            else: 
    76                 name=ord.coordAxisLabel.CONTENT 
    77             self.addAxis(name,vals,isLon=lon,isLat=lat,units='')#to do, units attribute for CF compliance 
    78         if len(ordinates)==3: 
    79             axes=['time',axisorder[1],axisorder[2]] 
    80         elif len(ordinates)==2: 
    81             axes=['time',axisorder[1]] 
    82         self.addVariable(fulldata,varid, axes,units='') #to do, units attribute for CF compliance 
     77                name=ord.coordAxisLabel.CONTENT    
     78            self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[axisorder.index(name)])#to do, units attribute for CF compliance 
     79        self.addVariable(fulldata,varid, axisorder, fillvalue, units=unitlist[-1] ) #to do, units attribute for CF compliance 
    8380                 
    8481         
  • TI02-CSML/trunk/csml/parser_extra.py

    r2060 r2112  
    135135        
    136136        # now handle any xlinks in the domain: 
    137         for feature in self.dataset.featureCollection.featureMembers: 
     137        for feature in csml.csmllibs.csmlextra.listify(self.dataset.featureCollection.featureMembers): 
    138138            cvg = feature.value 
    139139            for att in ['gridSeriesDomain', 'pointDomain', 'blah blah']: 
Note: See TracChangeset for help on using the changeset viewer.