Changeset 1394
- Timestamp:
- May 16, 2005, 11:06:22 AM (20 years ago)
- Location:
- inundation/ga/storm_surge/pmesh/load_mesh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py
r1377 r1394 5 5 6 6 for example: 7 elevation 8 0.6 0.7 4.99 1.9 2.8 510 2.7 2.4 5.27 elevation, friction 8 0.6, 0.7, 4.9, 0.3 9 1.9, 2.8, 5, 0.3 10 2.7, 2.4, 5.2, 0.3 11 11 12 12 The first two columns are always implicitly assumed to be x, y coordinates. 13 13 Use the same delimiter for the attribute names and the data 14 14 15 15 The format for a Points dictionary is: … … 97 97 Note: This might throw a can't load file error 98 98 """ 99 100 if ofile[-4:]== ".tsh": 101 dict = _read_tsh_file(ofile) 102 elif ofile[-4:]== ".msh": 103 dict = _read_msh_file(ofile) 104 else: 105 msg = 'Extension %s is unknown' %ofile[-4:] 106 raise IOError, msg 99 try: 100 if ofile[-4:]== ".tsh": 101 dict = _read_tsh_file(ofile) 102 elif ofile[-4:]== ".msh": 103 dict = _read_msh_file(ofile) 104 else: 105 msg = 'Extension %s is unknown' %ofile[-4:] 106 raise IOError, msg 107 except SyntaxError: 108 msg = 'File could not be opened' 109 raise IOError, msg 110 except IndexError: 111 msg = 'File could not be opened' 112 raise IOError, msg 113 107 114 return dict 108 115 … … 1052 1059 msg = 'Could not open file %s ' %ofile 1053 1060 raise IOError, msg 1061 except SyntaxError: 1062 msg = 'File could not be opened' 1063 raise IOError, msg 1064 except IndexError: 1065 msg = 'File could not be opened' 1066 raise IOError, msg 1054 1067 1055 1068 elif ofile[-4:]== ".pts": … … 1260 1273 if len(att_names) != len(numbers): 1261 1274 fd.close() 1262 raise TitleAmountError 1263 1275 # It might not be a problem with the title 1276 #raise TitleAmountError 1277 raise IOError 1264 1278 for i,num in enumerate(numbers): 1265 1279 num.strip() … … 1311 1325 1312 1326 #FIXME (DSG) need an export_points_file method.. 1313 def export_xya_file( file_name, xya_dict, title, delimiter = ','):1327 def _write_xya_file( file_name, xya_dict, delimiter = ','): 1314 1328 """ 1315 1329 export a file, ofile, with the format … … 1324 1338 #FIXME, move the test for this from meshharness to loadasciiharness 1325 1339 points = xya_dict['pointlist'] 1326 pointattributes = xya_dict[' pointattributelist']1340 pointattributes = xya_dict['attributelist'] 1327 1341 1328 1342 fd = open(file_name,'w') 1329 1330 fd.write(title+"\n") 1343 1344 titlelist = "" 1345 for title in pointattributes.keys(): 1346 titlelist = titlelist + title + delimiter 1347 titlelist = titlelist[0:-len(delimiter)] # remove the last delimiter 1348 fd.write(titlelist+"\n") 1331 1349 #<vertex #> <x> <y> [attributes] 1332 for vert, vertatts in map(None, points, pointattributes): 1350 for i,vert in enumerate( points): 1351 1333 1352 attlist = "" 1334 for att in vertatts:1335 attlist = attlist + str( att)+ delimiter1353 for att in pointattributes.keys(): 1354 attlist = attlist + str(pointattributes[att][i])+ delimiter 1336 1355 attlist = attlist[0:-len(delimiter)] # remove the last delimiter 1337 1356 attlist.strip() -
inundation/ga/storm_surge/pmesh/load_mesh/test_loadASCII.py
r1376 r1394 163 163 pass 164 164 165 166 def FUNCTION_REMOVEDtest_import_mesh(self):167 168 dict = self.dict169 fileName = tempfile.mktemp(".txt")170 fd = open(fileName,'w')171 loadASCII._write_ASCII_outline(fd,dict)172 fd.close()173 loaded_dict = import_mesh(fileName) #FIXME function names are wacky174 os.remove(fileName)175 176 #gen_dict =177 #print "*********************"178 #print dict179 #print "**loaded_dict*******************"180 #print loaded_dict181 #print "*********************"182 183 184 self.failUnless(array(loaded_dict['points']) ==185 array(dict['points']),186 'test_import_mesh failed. Test 1')187 self.failUnless(array(loaded_dict['point_attributes']) ==188 array(dict['point_attributes']),189 'test_import_mesh failed. Test 2')190 self.failUnless(array(loaded_dict['outline_segments']) ==191 array(dict['outline_segments']),192 'test_import_mesh failed. Test 3')193 self.failUnless(array(loaded_dict['outline_segment_tags']) ==194 array(dict['outline_segment_tags']),195 'test_import_mesh failed. Test 4')196 self.failUnless(array(loaded_dict['regions']) ==197 array(dict['regions']),198 'test_import_mesh failed. Test 5')199 self.failUnless(array(loaded_dict['region_tags']) ==200 array(dict['region_tags']),201 'test_import_mesh failed. Test 5')202 self.failUnless(array(loaded_dict['region_max_areas']) ==203 array(dict['region_max_areas']),204 'test_import_mesh failed. Test 5')205 206 self.failUnless(array(loaded_dict['holes']) ==207 array(dict['holes']),208 'test_import_mesh failed. Test 6')209 165 210 166 def test_export_mesh_file(self): … … 486 442 'test_writepts failed. Test geo_reference') 487 443 444 def test_write_xya(self): 445 dict = {} 446 att_dict = {} 447 dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 448 att_dict['elevation'] = array([10.0, 0.0, 10.4]) 449 att_dict['brightness'] = array([10.0, 0.0, 10.4]) 450 dict['attributelist'] = att_dict 451 dict['geo_reference'] = Geo_reference(56,1.9,1.9) 452 453 454 fileName = tempfile.mktemp(".xya") 455 export_points_file(fileName, dict) 456 dict2 = import_points_file(fileName) 457 #print "fileName",fileName 458 os.remove(fileName) 459 #print "dict2",dict2 460 461 assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 462 assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4]) 463 answer = [10.0, 0.0, 10.4] 464 assert allclose(dict2['attributelist']['brightness'], answer) 465 488 466 489 467 def test_half_pts(self): … … 615 593 try: 616 594 dict = import_points_file(fileName,delimiter = ' ') 617 except TitleAmountError:595 except IOError: 618 596 pass 619 597 else: … … 622 600 623 601 os.remove(fileName) 602 603 def test_loadxy6(self): 604 import os 605 import tempfile 606 607 fileName = tempfile.mktemp(".xya") 608 file = open(fileName,"w") 609 file.write("elevation\n\ 610 1.0 0.0 10.0 \n\ 611 0.0 1.0\n\ 612 1.0 \n") 613 file.close() 614 #print fileName 615 try: 616 dict = import_points_file(fileName,delimiter = ' ') 617 except IOError: 618 pass 619 else: 620 self.failUnless(0 ==1, 621 'bad xya file did not raise error!') 622 623 os.remove(fileName) 624 624 625 626 def test_import_tsh(self): 627 import os 628 import tempfile 629 630 fileName = tempfile.mktemp(".tsh") 631 file = open(fileName,"w") 632 file.write("elevation\n\ 633 1.0 0.0 10.0 \n\ 634 0.0 1.0\n\ 635 1.0 \n") 636 file.close() 637 #print fileName 638 try: 639 dict = import_points_file(fileName,delimiter = ' ') 640 except IOError: 641 pass 642 else: 643 self.failUnless(0 ==1, 644 'bad tsh file did not raise error!') 645 646 os.remove(fileName) 647 648 def test_import_tsh2(self): 649 import os 650 import tempfile 651 652 fileName = tempfile.mktemp(".msh") 653 file = open(fileName,"w") 654 file.write("1.0 \n\ 655 1.0 0.0 10.0 \n\ 656 0.0 1.0\n\ 657 13.0 \n") 658 file.close() 659 #print fileName 660 try: 661 dict = import_points_file(fileName,delimiter = ' ') 662 except IOError: 663 pass 664 else: 665 self.failUnless(0 ==1, 666 'bad tsh file did not raise error!') 667 668 os.remove(fileName) 669 670 def test_import_tsh3(self): 671 import os 672 import tempfile 673 674 fileName = tempfile.mktemp(".tsh") 675 file = open(fileName,"w") 676 file.write("1.0 \n\ 677 showme1.0 0.0 10.0 \n\ 678 0.0 1.0\n\ 679 13.0 \n") 680 file.close() 681 #print fileName 682 try: 683 dict = import_points_file(fileName,delimiter = ' ') 684 except IOError: 685 pass 686 else: 687 self.failUnless(0 ==1, 688 'bad tsh file did not raise error!') 689 690 os.remove(fileName) 625 691 626 692 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.