Changeset 841
- Timestamp:
- Feb 7, 2005, 6:03:02 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/least_squares.py
r840 r841 167 167 #Reduce number of points a bit 168 168 points = points[::reduction] 169 elevation = attributes['elevation'][::reduction] 169 elevation = attributes['elevation'] #Must be elevation 170 elevation = elevation[::reduction] 170 171 171 172 if verbose: print 'Got %d data points' %len(points) -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r836 r841 25 25 def tearDown(self): 26 26 pass 27 28 27 29 28 def test_datapoint_at_centroid(self): … … 494 493 FN = 'xyatest' + str(time.time()) + '.xya' 495 494 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) ) 499 499 fid.close() 500 500 … … 502 502 pts2rectangular(FN, 4, 4, format = 'asc') 503 503 504 z1 = [2, 4] 505 z2 = [4, 8] 506 z3 = [4, 8] 504 507 505 data_coords = [ [1,1], [1,3], [3,1] ] 508 z = [ z1, z2, z3]506 z = [2, 4, 4] 509 507 510 508 ref = fit_to_mesh(points, triangles, data_coords, z) 511 509 510 #print attributes 511 #print ref 512 512 assert allclose(attributes, ref) 513 513 -
inundation/ga/storm_surge/pyvolution/test_util.py
r835 r841 343 343 FN = 'xyatest' + str(time.time()) + '.xya' 344 344 fid = open(FN, 'w') 345 fid.write(' %s %s %s\n' %('a1', 'a2', 'a3') ) 345 346 fid.write('%f %f %f %f %f\n' %(0,1,10,20,30) ) 346 347 fid.write('%f %f %f %f %f\n' %(1,0,30,20,10) ) … … 348 349 fid.close() 349 350 350 points, attributes , _= read_xya(FN, format = 'asc')351 351 points, attributes = read_xya(FN, format = 'asc') 352 352 353 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]) 355 357 356 358 os.remove(FN) … … 366 368 fid.close() 367 369 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 373 372 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 376 378 377 379 os.remove(FN) -
inundation/ga/storm_surge/pyvolution/util.py
r840 r841 335 335 lines = lines[1:] 336 336 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 = [] 341 344 for line in lines: 342 345 fields = line.strip().split() 343 346 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]) ) 345 349 346 350 return points, attributes
Note: See TracChangeset
for help on using the changeset viewer.