Changeset 839


Ignore:
Timestamp:
Feb 7, 2005, 5:04:54 PM (20 years ago)
Author:
ole
Message:

Slight change to pts format having attribute names as variables

Location:
inundation/ga/storm_surge/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r837 r839  
    823823    138.3698 137.4194 136.5062 135.5558 ..........
    824824
    825     Convert to NetCDF pts format
     825    Convert to NetCDF pts format which is
     826
     827    points:  (Nx2) Float array
     828    elevation: N Float array
    826829    """
    827830
     
    843846    cellsize = infile.cellsize[0]
    844847    NODATA_value = infile.NODATA_value[0]
    845     elevation = infile.variables['elevation']
     848    dem_elevation = infile.variables['elevation']
    846849
    847850    #Get output file                               
     
    860863
    861864   
    862     outfile.attribute_names = 'elevation' #This is the attribute always present in DEMs
    863     #FIXME (Ole): We would really like this to be Python list,
    864     #but I am not sure if
    865     #that is possible in NetCDF???
    866    
    867 
    868865    # dimension definitions
    869866    outfile.createDimension('number_of_points', nrows*ncols)   
    870     outfile.createDimension('number_of_attributes', 1) #Always 1 with the dem fmt
    871867    outfile.createDimension('number_of_dimensions', 2) #This is 2d data
    872868   
    873 
    874869    # variable definitions
    875870    outfile.createVariable('points', Float, ('number_of_points',
    876871                                             'number_of_dimensions'))
    877     outfile.createVariable('attributes', Float, ('number_of_points',
    878                                                  'number_of_attributes'))
     872    outfile.createVariable('elevation', Float, ('number_of_points',))
    879873
    880874    # Get handles to the variables
    881875    points = outfile.variables['points']
    882     attributes = outfile.variables['attributes']
     876    elevation = outfile.variables['elevation']
    883877
    884878    #Store data
     
    893887            x = j*cellsize
    894888            points[index, :] = [x,y]
    895             attributes[index, 0] = elevation[i, j]           
     889            elevation[index] = dem_elevation[i, j]           
    896890
    897891    infile.close()           
  • inundation/ga/storm_surge/pyvolution/test_data_manager.py

    r837 r839  
    521521
    522522        ref_points = []
    523         ref_attributes = []
     523        ref_elevation = []
    524524        for i in range(6):
    525525            y = (6-i)*25.0           
     
    529529
    530530                ref_points.append( [x,y] )
    531                 ref_attributes.append([z])
     531                ref_elevation.append(z)
    532532                fid.write('%f ' %z)
    533533            fid.write('\n')   
     
    544544     
    545545        # Get the variables
     546        #print fid.variables.keys()
    546547        points = fid.variables['points']
    547         attributes = fid.variables['attributes']
    548         attribute_names = fid.attribute_names
     548        elevation = fid.variables['elevation']
    549549
    550550        #Check values
     
    555555
    556556        #print attributes[:]
    557         #print ref_attributes
    558         assert allclose(attributes, ref_attributes)       
     557        #print ref_elevation
     558        assert allclose(elevation, ref_elevation)       
    559559     
    560560        #Cleanup
Note: See TracChangeset for help on using the changeset viewer.