Changeset 1422


Ignore:
Timestamp:
21/08/06 09:15:20 (13 years ago)
Author:
domlowe
Message:

netcdf writing now done with cdms rather than scientific python

Location:
TI02-CSML/trunk/parser/API
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/parser/API/NetCDFWriter.py

    r1421 r1422  
    2424        elif isTime is not None: 
    2525            ax.designateTime() 
     26        for key in kwargs: 
     27            setattr(ax, key,kwargs[key]) 
    2628        self.axes.append(ax) 
    2729        pass 
  • TI02-CSML/trunk/parser/API/ops_GridSeriesFeature.py

    r1414 r1422  
    11''' ops_GridSeriesFeature  contains operations for GridSeriesFeatures''' 
    2 from API import * 
     2from API import NetCDFWriter 
    33from CSMLDocument import * 
    44from Scientific.IO.NetCDF import *  #use this instead of cdms for now for it's simple write interface.. 
     
    182182    output.close() 
    183183 
    184     ### create and write netcdf - uses scientific python#### 
    185     ncfile=NetCDFFile(pathToSubsetNetCDF,'w') 
    186     # create the dimensions 
    187     ncfile.createDimension ( 't', len(self.times)) 
    188     time_var = ncfile.createVariable ( 't', Float, ('t',) ) 
    189     time_var.longname = 't' 
     184    ### write netcdf using NCWriter class (wraps cdms) ### 
     185    #nc=NetCDFWriter.NCwriter(pathToSubsetNetCDF) 
     186    nc=NetCDFWriter.NCwriter('temp.nc') 
    190187    floatTimes=[] 
    191188    for time in self.times: 
    192189        time=ops_AbstractFeature.__getCDtime(time).torel(calunits) 
    193190        floatTimes.append(time.value) 
    194     time_var[:] =floatTimes[:] 
    195     time_var.units=calunits 
    196     time_var.calendar=caltype 
    197  
     191    nc.addAxis('t',floatTimes,isTime=1,units=calunits,calendar=caltype) 
    198192    for ordinate in ordinates: 
    199         ncfile.createDimension(ordinate.definesAxis, len(ordinate.axisValues.split())) 
    200         item_var = ncfile.createVariable (ordinate.definesAxis, Float, (ordinate.definesAxis,) ) 
    201193        #convert to list 
    202194        vals=[] 
    203195        for val in ordinate.axisValues.split(','): 
    204196            vals.append(float(val)) 
    205         if ordinate.definesAxis=='latitude': 
    206             #this is just a fix till I work out what's going wrong 
    207             vals.reverse() 
    208         item_var[:]=vals[:] 
    209     #this needs reconsidering - do the shapes always match up?? 
    210  
    211  
     197        nc.addAxis(ordinate.definesAxis,vals) 
     198    #nc.addVariable(data,'lala', axes,history='blah blah', units='flakesperminute',long_name='snowfall_at_surface') 
    212199    if len(ordinates)==3: 
    213         feature_var = ncfile.createVariable (self.id, Float,('t',axisorder[1],axisorder[2],axisorder[3])) 
     200        axes=['t',axisorder[1],axisorder[2],axisorder[3]] 
    214201    elif len(grid.ordinates)==2: 
    215         feature_var =ncfile.createVariable (self.id, Float,('t',axisorder[1],axisorder[2])) 
    216     print feature_var.shape 
    217     print shape(fulldata) 
    218     feature_var[:]=fulldata[:] 
    219     ncfile.close() 
     202        axes=['t',axisorder[1],axisorder[2]] 
     203    nc.addVariable(fulldata,self.id, axes) 
     204    nc.closeFinishedFile() 
    220205    return pathToSubsetCSML,pathToSubsetNetCDF, totalArraySize 
Note: See TracChangeset for help on using the changeset viewer.