Changeset 841


Ignore:
Timestamp:
Feb 7, 2005, 6:03:02 PM (20 years ago)
Author:
ole
Message:
 
Location:
inundation/ga/storm_surge/pyvolution
Files:
4 edited

Legend:

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

    r840 r841  
    167167    #Reduce number of points a bit
    168168    points = points[::reduction]
    169     elevation = attributes['elevation'][::reduction]
     169    elevation = attributes['elevation']  #Must be elevation
     170    elevation = elevation[::reduction]
    170171   
    171172    if verbose: print 'Got %d data points' %len(points)
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r836 r841  
    2525    def tearDown(self):
    2626        pass
    27 
    2827
    2928    def test_datapoint_at_centroid(self):
     
    494493        FN = 'xyatest' + str(time.time()) + '.xya'
    495494        fid = open(FN, 'w')
    496         fid.write('%f %f %f %f\n' %(1,1,2,4) )
    497         fid.write('%f %f %f %f\n' %(1,3,4,8) )
    498         fid.write('%f %f %f %f\n' %(3,1,4,8) )         
     495        fid.write(' %s \n' %('elevation'))       
     496        fid.write('%f %f %f\n' %(1,1,2) )
     497        fid.write('%f %f %f\n' %(1,3,4) )
     498        fid.write('%f %f %f\n' %(3,1,4) )               
    499499        fid.close()
    500500       
     
    502502                pts2rectangular(FN, 4, 4, format = 'asc')
    503503       
    504         z1 = [2, 4]
    505         z2 = [4, 8]
    506         z3 = [4, 8]
     504
    507505        data_coords = [ [1,1], [1,3], [3,1] ]
    508         z = [z1, z2, z3]
     506        z = [2, 4, 4]
    509507
    510508        ref = fit_to_mesh(points, triangles, data_coords, z)           
    511        
     509
     510        #print attributes
     511        #print ref
    512512        assert allclose(attributes, ref)
    513513
  • inundation/ga/storm_surge/pyvolution/test_util.py

    r835 r841  
    343343        FN = 'xyatest' + str(time.time()) + '.xya'
    344344        fid = open(FN, 'w')
     345        fid.write('      %s %s %s\n' %('a1', 'a2', 'a3') )       
    345346        fid.write('%f %f %f %f %f\n' %(0,1,10,20,30) )
    346347        fid.write('%f %f %f %f %f\n' %(1,0,30,20,10) )
     
    348349        fid.close()
    349350       
    350         points, attributes, _ = read_xya(FN, format = 'asc')
    351        
     351        points, attributes = read_xya(FN, format = 'asc')
     352
    352353        assert allclose(points, [ [0,1], [1,0], [1,1] ])
    353         assert allclose(attributes, [ [10,20,30], [30,20,10],
    354                 [40.2,40.3,40.4] ])
     354        assert allclose(attributes['a1'], [10,30,40.2])
     355        assert allclose(attributes['a2'], [20,20,40.3])
     356        assert allclose(attributes['a3'], [30,10,40.4])       
    355357       
    356358        os.remove(FN)
     
    366368        fid.close()
    367369       
    368         points, attributes, attribute_names = read_xya(FN, format = 'asc')
    369 
    370         assert attribute_names[0] == 'a1'
    371         assert attribute_names[1] == 'a2'
    372         assert attribute_names[2] == 'a3'       
     370        points, attributes = read_xya(FN, format = 'asc')
     371
    373372        assert allclose(points, [ [0,1], [1,0], [1,1] ])
    374         assert allclose(attributes, [ [10,20,30], [30,20,10],
    375                 [40.2,40.3,40.4] ])
     373
     374        assert allclose(attributes['a1'], [10,30,40.2])
     375        assert allclose(attributes['a2'], [20,20,40.3])
     376        assert allclose(attributes['a3'], [30,10,40.4])       
     377
    376378       
    377379        os.remove(FN)
  • inundation/ga/storm_surge/pyvolution/util.py

    r840 r841  
    335335            lines = lines[1:]
    336336        else:
    337             attribute_names = None
    338    
    339         points = []     
    340         attributes = []
     337            attribute_names = ['elevation']  #HACK
     338
     339        attributes = {}   
     340        for key in attribute_names:
     341            attributes[key] = []
     342
     343        points = []
    341344        for line in lines:
    342345            fields = line.strip().split()
    343346            points.append( (float(fields[0]), float(fields[1])) )
    344             attributes.append( [float(z) for z in fields[2:] ] )
     347            for i, key in enumerate(attribute_names):
     348                attributes[key].append( float(fields[2+i]) )
    345349       
    346350    return points, attributes
Note: See TracChangeset for help on using the changeset viewer.