Changeset 6154
- Timestamp:
- Jan 13, 2009, 3:03:31 PM (16 years ago)
- Location:
- anuga_core/source/anuga/load_mesh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/load_mesh/loadASCII.py
r6086 r6154 58 58 59 59 from string import find, rfind 60 from Numeric import array, Float, Int16, Int32, Character,reshape, \ 61 concatenate, take 60 import Numeric as num 62 61 from os.path import splitext 63 62 … … 650 649 # in more detail. 651 650 652 IntType = Int32651 IntType = num.Int32 653 652 #IntType = Int 654 653 655 654 #the triangulation 656 mesh['vertices'] = array(mesh['vertices']).astype(Float)655 mesh['vertices'] = num.array(mesh['vertices']).astype(num.Float) 657 656 if mesh['vertex_attributes'] != None: 658 657 mesh['vertex_attributes'] = \ 659 array(mesh['vertex_attributes']).astype(Float)658 num.array(mesh['vertex_attributes']).astype(num.Float) 660 659 mesh['vertex_attribute_titles'] = \ 661 array(mesh['vertex_attribute_titles']).astype(Character)662 mesh['segments'] = array(mesh['segments']).astype(IntType)663 mesh['segment_tags'] = array(mesh['segment_tags']).astype(Character)664 mesh['triangles'] = array(mesh['triangles']).astype(IntType)665 mesh['triangle_tags'] = array(mesh['triangle_tags']) #.astype(Character)660 num.array(mesh['vertex_attribute_titles']).astype(num.Character) 661 mesh['segments'] = num.array(mesh['segments']).astype(IntType) 662 mesh['segment_tags'] = num.array(mesh['segment_tags']).astype(num.Character) 663 mesh['triangles'] = num.array(mesh['triangles']).astype(IntType) 664 mesh['triangle_tags'] = num.array(mesh['triangle_tags']) #.astype(Character) 666 665 mesh['triangle_neighbors'] = \ 667 array(mesh['triangle_neighbors']).astype(IntType)666 num.array(mesh['triangle_neighbors']).astype(IntType) 668 667 669 668 #the outline 670 mesh['points'] = array(mesh['points']).astype(Float)671 mesh['point_attributes'] = array(mesh['point_attributes']).astype(Float)672 mesh['outline_segments'] = array(mesh['outline_segments']).astype(IntType)669 mesh['points'] = num.array(mesh['points']).astype(num.Float) 670 mesh['point_attributes'] = num.array(mesh['point_attributes']).astype(num.Float) 671 mesh['outline_segments'] = num.array(mesh['outline_segments']).astype(IntType) 673 672 mesh['outline_segment_tags'] = \ 674 array(mesh['outline_segment_tags']).astype(Character)675 mesh['holes'] = array(mesh['holes']).astype(Float)676 mesh['regions'] = array(mesh['regions']).astype(Float)677 mesh['region_tags'] = array(mesh['region_tags']).astype(Character)678 mesh['region_max_areas'] = array(mesh['region_max_areas']).astype(Float)673 num.array(mesh['outline_segment_tags']).astype(num.Character) 674 mesh['holes'] = num.array(mesh['holes']).astype(num.Float) 675 mesh['regions'] = num.array(mesh['regions']).astype(num.Float) 676 mesh['region_tags'] = num.array(mesh['region_tags']).astype(num.Character) 677 mesh['region_max_areas'] = num.array(mesh['region_max_areas']).astype(num.Float) 679 678 680 679 #mesh = mesh_dict2array(mesh) … … 707 706 if (mesh['vertices'].shape[0] > 0): 708 707 outfile.createDimension('num_of_vertices', mesh['vertices'].shape[0]) 709 outfile.createVariable('vertices', Float, ('num_of_vertices',710 'num_of_dimensions'))708 outfile.createVariable('vertices', num.Float, ('num_of_vertices', 709 'num_of_dimensions')) 711 710 outfile.variables['vertices'][:] = mesh['vertices'] 712 711 if mesh['vertex_attributes'] != None \ … … 718 717 mesh['vertex_attribute_titles'].shape[1]) 719 718 outfile.createVariable('vertex_attributes', 720 Float,719 num.Float, 721 720 ('num_of_vertices', 722 721 'num_of_vertex_attributes')) 723 722 outfile.createVariable('vertex_attribute_titles', 724 Character,723 num.Character, 725 724 ('num_of_vertex_attributes', 726 725 'num_of_vertex_attribute_title_chars')) … … 740 739 mesh['segment_tags'].shape[1]) 741 740 outfile.createVariable('segment_tags', 742 Character,741 num.Character, 743 742 ('num_of_segments', 744 743 'num_of_segment_tag_chars')) … … 761 760 mesh['triangle_tags'].shape[1]) 762 761 outfile.createVariable('triangle_tags', 763 Character,762 num.Character, 764 763 ('num_of_triangles', 765 764 'num_of_triangle_tag_chars')) … … 770 769 if (mesh['points'].shape[0] > 0): 771 770 outfile.createDimension('num_of_points', mesh['points'].shape[0]) 772 outfile.createVariable('points', Float, ('num_of_points',773 'num_of_dimensions'))771 outfile.createVariable('points', num.Float, ('num_of_points', 772 'num_of_dimensions')) 774 773 outfile.variables['points'][:] = mesh['points'] 775 774 if mesh['point_attributes'].shape[0] > 0 \ … … 778 777 mesh['point_attributes'].shape[1]) 779 778 outfile.createVariable('point_attributes', 780 Float,779 num.Float, 781 780 ('num_of_points', 'num_of_point_attributes')) 782 781 outfile.variables['point_attributes'][:] = mesh['point_attributes'] … … 795 794 mesh['outline_segment_tags'].shape[1]) 796 795 outfile.createVariable('outline_segment_tags', 797 Character,796 num.Character, 798 797 ('num_of_outline_segments', 799 798 'num_of_outline_segment_tag_chars')) … … 804 803 if (mesh['holes'].shape[0] > 0): 805 804 outfile.createDimension('num_of_holes', mesh['holes'].shape[0]) 806 outfile.createVariable('holes', Float, ('num_of_holes',807 'num_of_dimensions'))805 outfile.createVariable('holes', num.Float, ('num_of_holes', 806 'num_of_dimensions')) 808 807 outfile.variables['holes'][:] = mesh['holes'] 809 808 … … 811 810 if (mesh['regions'].shape[0] > 0): 812 811 outfile.createDimension('num_of_regions', mesh['regions'].shape[0]) 813 outfile.createVariable('regions', Float, ('num_of_regions',814 'num_of_dimensions'))815 outfile.createVariable('region_max_areas', Float, ('num_of_regions',))812 outfile.createVariable('regions', num.Float, ('num_of_regions', 813 'num_of_dimensions')) 814 outfile.createVariable('region_max_areas', num.Float, ('num_of_regions',)) 816 815 outfile.variables['regions'][:] = mesh['regions'] 817 816 outfile.variables['region_max_areas'][:] = mesh['region_max_areas'] … … 819 818 outfile.createDimension('num_of_region_tag_chars', 820 819 mesh['region_tags'].shape[1]) 821 outfile.createVariable('region_tags', Character,820 outfile.createVariable('region_tags', num.Character, 822 821 ('num_of_regions', 823 822 'num_of_region_tag_chars')) … … 854 853 mesh['vertices'] = fid.variables['vertices'][:] 855 854 except KeyError: 856 mesh['vertices'] = array([])855 mesh['vertices'] = num.array([]) 857 856 858 857 try: … … 874 873 mesh['segments'] = fid.variables['segments'][:] 875 874 except KeyError: 876 mesh['segments'] = array([])875 mesh['segments'] = num.array([]) 877 876 878 877 mesh['segment_tags'] =[] … … 889 888 mesh['triangle_neighbors'] = fid.variables['triangle_neighbors'][:] 890 889 except KeyError: 891 mesh['triangles'] = array([])892 mesh['triangle_neighbors'] = array([])890 mesh['triangles'] = num.array([]) 891 mesh['triangle_neighbors'] = num.array([]) 893 892 894 893 mesh['triangle_tags'] =[] … … 917 916 mesh['outline_segments'] = fid.variables['outline_segments'][:] 918 917 except KeyError: 919 mesh['outline_segments'] = array([])918 mesh['outline_segments'] = num.array([]) 920 919 921 920 mesh['outline_segment_tags'] =[] … … 931 930 mesh['holes'] = fid.variables['holes'][:] 932 931 except KeyError: 933 mesh['holes'] = array([])932 mesh['holes'] = num.array([]) 934 933 935 934 try: 936 935 mesh['regions'] = fid.variables['regions'][:] 937 936 except KeyError: 938 mesh['regions'] = array([])937 mesh['regions'] = num.array([]) 939 938 940 939 mesh['region_tags'] =[] … … 950 949 mesh['region_max_areas'] = fid.variables['region_max_areas'][:] 951 950 except KeyError: 952 mesh['region_max_areas'] = array([])951 mesh['region_max_areas'] = num.array([]) 953 952 #mesh[''] = fid.variables[''][:] 954 953 … … 1019 1018 # [max_x, max_y], [min_x, max_y]] 1020 1019 def extent(points): 1021 points = array(points).astype(Float)1020 points = num.array(points).astype(num.Float) 1022 1021 1023 1022 max_x = min_x = points[0][0] … … 1033 1032 if y < min_y: min_y = y 1034 1033 1035 extent = array([[min_x, min_y],1036 [max_x, min_y],1037 [max_x, max_y],1038 [min_x, max_y]])1034 extent = num.array([[min_x, min_y], 1035 [max_x, min_y], 1036 [max_x, max_y], 1037 [min_x, max_y]]) 1039 1038 1040 1039 return extent … … 1096 1095 def point_atts2array(point_atts): 1097 1096 # convert attribute list to array of floats 1098 point_atts['pointlist'] = array(point_atts['pointlist']).astype(Float)1097 point_atts['pointlist'] = num.array(point_atts['pointlist']).astype(num.Float) 1099 1098 1100 1099 for key in point_atts['attributelist'].keys(): 1101 1100 point_atts['attributelist'][key] = \ 1102 array(point_atts['attributelist'][key]).astype(Float)1101 num.array(point_atts['attributelist'][key]).astype(num.Float) 1103 1102 1104 1103 return point_atts … … 1128 1127 """ 1129 1128 1130 point_attributes = array([]).astype(Float)1129 point_attributes = num.array([]).astype(num.Float) 1131 1130 keys = dic.keys() 1132 1131 key = keys.pop(0) 1133 point_attributes = reshape(dic[key],(dic[key].shape[0],1))1132 point_attributes = num.reshape(dic[key],(dic[key].shape[0],1)) 1134 1133 for key in keys: 1135 1134 #point_attributes = concatenate([point_attributes, dic[key]], axis=1) 1136 reshaped = reshape(dic[key],(dic[key].shape[0],1))1137 point_attributes = concatenate([point_attributes, reshaped], axis=1)1135 reshaped = num.reshape(dic[key],(dic[key].shape[0],1)) 1136 point_attributes = num.concatenate([point_attributes, reshaped], axis=1) 1138 1137 1139 1138 return dic.keys(), point_attributes … … 1149 1148 dict = point_atts2array(dict) 1150 1149 #FIXME maybe the points data structure should become a class? 1151 dict['pointlist'] = take(dict['pointlist'],indices_to_keep)1150 dict['pointlist'] = num.take(dict['pointlist'],indices_to_keep) 1152 1151 1153 1152 for key in dict['attributelist'].keys(): 1154 dict['attributelist'][key]= take(dict['attributelist'][key],1155 indices_to_keep)1153 dict['attributelist'][key]= num.take(dict['attributelist'][key], 1154 indices_to_keep) 1156 1155 1157 1156 return dict … … 1170 1169 1171 1170 combined = {} 1172 combined['pointlist'] = concatenate((dict2['pointlist'],1173 dict1['pointlist']),axis=0)1171 combined['pointlist'] = num.concatenate((dict2['pointlist'], 1172 dict1['pointlist']),axis=0) 1174 1173 1175 1174 atts = {} 1176 1175 for key in dict2['attributelist'].keys(): 1177 atts[key]= concatenate((dict2['attributelist'][key],1178 dict1['attributelist'][key]), axis=0)1176 atts[key]= num.concatenate((dict2['attributelist'][key], 1177 dict1['attributelist'][key]), axis=0) 1179 1178 combined['attributelist']=atts 1180 1179 combined['geo_reference'] = dict1['geo_reference'] -
anuga_core/source/anuga/load_mesh/test_loadASCII.py
r6074 r6154 10 10 from os.path import splitext 11 11 12 from Numeric import array, allclose, alltrue 12 import Numeric as num 13 13 14 14 from anuga.load_mesh.loadASCII import * … … 179 179 #print "*(*(" 180 180 181 self.failUnless( alltrue(array(meshDict['vertices']) ==182 array(loadedDict['vertices'])),183 184 self.failUnless( alltrue(array(meshDict['triangles']) ==185 array(loadedDict['triangles'])),186 187 self.failUnless( alltrue(array(meshDict['segments']) ==188 array(loadedDict['segments'])),189 190 self.failUnless( alltrue(array(meshDict['triangle_tags']) ==191 array(loadedDict['triangle_tags'])),192 181 self.failUnless(num.alltrue(num.array(meshDict['vertices']) == 182 num.array(loadedDict['vertices'])), 183 'test_export_mesh_file failed. Test 1') 184 self.failUnless(num.alltrue(num.array(meshDict['triangles']) == 185 num.array(loadedDict['triangles'])), 186 'test_export_mesh_file failed. Test 2') 187 self.failUnless(num.alltrue(num.array(meshDict['segments']) == 188 num.array(loadedDict['segments'])), 189 'test_export_mesh_file failed. Test 3') 190 self.failUnless(num.alltrue(num.array(meshDict['triangle_tags']) == 191 num.array(loadedDict['triangle_tags'])), 192 'test_export_mesh_file failed. Test 4') 193 193 194 194 self.failUnless(meshDict['vertex_attributes'] == 195 195 loadedDict['vertex_attributes'], 196 197 self.failUnless( alltrue(array(meshDict['triangle_neighbors']) ==198 array(loadedDict['triangle_neighbors'])),199 200 self.failUnless( alltrue(array(meshDict['segment_tags']) ==201 array(loadedDict['segment_tags'])),202 203 self.failUnless( alltrue(array(meshDict['vertex_attribute_titles']) ==204 array(loadedDict['vertex_attribute_titles'])),205 206 self.failUnless( alltrue(array(meshDict['geo_reference']) ==207 array(loadedDict['geo_reference'])),208 196 'test_export_mesh_file failed. Test 5') 197 self.failUnless(num.alltrue(num.array(meshDict['triangle_neighbors']) == 198 num.array(loadedDict['triangle_neighbors'])), 199 'test_export_mesh_file failed. Test 6') 200 self.failUnless(num.alltrue(num.array(meshDict['segment_tags']) == 201 num.array(loadedDict['segment_tags'])), 202 'test_export_mesh_file failed. Test 7') 203 self.failUnless(num.alltrue(num.array(meshDict['vertex_attribute_titles']) == 204 num.array(loadedDict['vertex_attribute_titles'])), 205 'test_export_mesh_file failed. Test 8') 206 self.failUnless(num.alltrue(num.array(meshDict['geo_reference']) == 207 num.array(loadedDict['geo_reference'])), 208 'test_export_mesh_file failed. Test 9') 209 209 210 210 os.remove(fileName) … … 439 439 440 440 def check_mesh_dicts(self, loaded_dict, dict, fail_string ): 441 assert allclose(array(loaded_dict['points']),442 array(dict['points']))441 assert num.allclose(num.array(loaded_dict['points']), 442 num.array(dict['points'])) 443 443 444 assert allclose(array(loaded_dict['point_attributes']),445 array(dict['point_attributes']))446 assert allclose(array(loaded_dict['outline_segments']),447 array(dict['outline_segments']))444 assert num.allclose(num.array(loaded_dict['point_attributes']), 445 num.array(dict['point_attributes'])) 446 assert num.allclose(num.array(loaded_dict['outline_segments']), 447 num.array(dict['outline_segments'])) 448 448 449 449 self.failUnless(loaded_dict['outline_segment_tags'] == … … 452 452 453 453 454 assert allclose(array(loaded_dict['regions']),455 array(dict['regions']))454 assert num.allclose(num.array(loaded_dict['regions']), 455 num.array(dict['regions'])) 456 456 457 457 self.failUnless(loaded_dict['region_tags'] == … … 459 459 fail_string + ' failed!! Test 5') 460 460 461 assert allclose(array(loaded_dict['region_max_areas']),462 array(dict['region_max_areas']))461 assert num.allclose(num.array(loaded_dict['region_max_areas']), 462 num.array(dict['region_max_areas'])) 463 463 464 assert allclose(array(loaded_dict['holes']),465 array(dict['holes']))464 assert num.allclose(num.array(loaded_dict['holes']), 465 num.array(dict['holes'])) 466 466 467 assert allclose(array(dict['vertices']),468 array(loaded_dict['vertices']))467 assert num.allclose(num.array(dict['vertices']), 468 num.array(loaded_dict['vertices'])) 469 469 470 assert allclose(array(dict['triangles']),471 array(loaded_dict['triangles']))470 assert num.allclose(num.array(dict['triangles']), 471 num.array(loaded_dict['triangles'])) 472 472 473 assert allclose(array(dict['segments']),474 array(loaded_dict['segments']))473 assert num.allclose(num.array(dict['segments']), 474 num.array(loaded_dict['segments'])) 475 475 for ob, ldob in map(None,dict['triangle_tags'], 476 476 loaded_dict['triangle_tags']): … … 484 484 fail_string + ' failed!! Test vertex_attributes') 485 485 486 assert allclose(array(dict['triangle_neighbors']),487 array(loaded_dict['triangle_neighbors']))486 assert num.allclose(num.array(dict['triangle_neighbors']), 487 num.array(loaded_dict['triangle_neighbors'])) 488 488 489 489 for seg, ldseg in map(None,dict['segment_tags'], … … 492 492 fail_string + ' failed!! Test 8') 493 493 try: 494 assert allclose(array(dict['vertex_attribute_titles']),495 array(loaded_dict['vertex_attribute_titles']))494 assert num.allclose(num.array(dict['vertex_attribute_titles']), 495 num.array(loaded_dict['vertex_attribute_titles'])) 496 496 except TypeError: 497 self.failUnless( alltrue(array(loaded_dict['vertex_attribute_titles']) ==array(dict['vertex_attribute_titles'])),498 fail_string + ' failed!! Test 8')497 self.failUnless(num.alltrue(num.array(loaded_dict['vertex_attribute_titles']) == num.array(dict['vertex_attribute_titles'])), 498 fail_string + ' failed!! Test 8') 499 499 try: 500 500 self.failUnless(loaded_dict['geo_reference'] ==
Note: See TracChangeset
for help on using the changeset viewer.