Changeset 1003
- Timestamp:
- Mar 4, 2005, 2:55:47 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/least_squares.py
r997 r1003 31 31 32 32 from general_mesh import General_mesh 33 from mesh import Mesh 34 35 from Numeric import zeros, take, array, Float, Int, dot, transpose, concatenate 33 from Numeric import zeros, array, Float, Int, dot, transpose, concatenate, ArrayType 34 #from mesh import Mesh 35 36 from Numeric import zeros, take, array, Float, Int, dot, transpose, concatenate, ArrayType 36 37 from sparse import Sparse, Sparse_CSR 37 38 from cg_solve import conjugate_gradient, VectorShapeError … … 81 82 82 83 from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \ 83 load_points_file, export_ triangulation_file, \84 load_points_file, export_mesh_file, \ 84 85 concatinate_attributelist 85 86 … … 89 90 vertex_coordinates = mesh_dict['vertices'] 90 91 triangles = mesh_dict['triangles'] 91 92 old_point_attributes = mesh_dict['vertex_attributes'] 93 old_title_list = mesh_dict['vertex_attribute_titles'] 92 if type(mesh_dict['vertex_attributes']) == ArrayType: 93 old_point_attributes = mesh_dict['vertex_attributes'].tolist() 94 else: 95 old_point_attributes = mesh_dict['vertex_attributes'] 96 97 if type(mesh_dict['vertex_attribute_titles']) == ArrayType: 98 old_title_list = mesh_dict['vertex_attribute_titles'].tolist() 99 else: 100 old_title_list = mesh_dict['vertex_attribute_titles'] 101 94 102 if verbose:print "tsh file loaded" 95 103 … … 103 111 title_list,point_attributes = concatinate_attributelist(point_dict['attributelist']) 104 112 if verbose: print "points file loaded" 105 106 107 113 if verbose:print "fitting to mesh" 108 114 f = fit_to_mesh(vertex_coordinates, … … 134 140 135 141 #FIXME (Ole): Remember to output mesh_origin as well 136 export_ triangulation_file(mesh_output_file, mesh_dict)142 export_mesh_file(mesh_output_file, mesh_dict) 137 143 138 144 -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r997 r1003 1053 1053 1054 1054 1055 1056 1057 1055 def test_fit_to_mesh_file(self): 1058 1056 from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \ 1059 export_ triangulation_file1057 export_mesh_file 1060 1058 import tempfile 1061 1059 import os … … 1076 1074 'external'] 1077 1075 mesh_file = tempfile.mktemp(".tsh") 1078 export_ triangulation_file(mesh_file,mesh_dic)1076 export_mesh_file(mesh_file,mesh_dic) 1079 1077 1080 1078 # create an .xya file … … 1108 1106 def test_fit_to_mesh_fileII(self): 1109 1107 from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \ 1110 export_ triangulation_file1108 export_mesh_file 1111 1109 import tempfile 1112 1110 import os … … 1127 1125 'external'] 1128 1126 mesh_file = tempfile.mktemp(".tsh") 1129 export_ triangulation_file(mesh_file,mesh_dic)1127 export_mesh_file(mesh_file,mesh_dic) 1130 1128 1131 1129 # create an .xya file … … 1157 1155 os.remove(point_file) 1158 1156 1157 def test_fit_to_msh_netcdf_fileII(self): 1158 from load_mesh.loadASCII import mesh_file_to_mesh_dictionary,export_mesh_file 1159 import tempfile 1160 import os 1161 1162 # create a .tsh file, no user outline 1163 mesh_dic = {} 1164 mesh_dic['vertices'] = [[0.0, 0.0], 1165 [0.0, 5.0], 1166 [5.0, 0.0]] 1167 mesh_dic['triangles'] = [[0, 2, 1]] 1168 mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]] 1169 mesh_dic['triangle_tags'] = [['']] 1170 mesh_dic['vertex_attributes'] = [[1,2], [1,2], [1,2]] 1171 mesh_dic['vertex_attribute_titles'] = ['density', 'temp'] 1172 mesh_dic['triangle_neighbors'] = [[-1, -1, -1]] 1173 mesh_dic['segment_tags'] = ['external', 1174 'external', 1175 'external'] 1176 mesh_file = tempfile.mktemp(".msh") 1177 export_mesh_file(mesh_file,mesh_dic) 1178 1179 # create an .xya file 1180 point_file = tempfile.mktemp(".xya") 1181 fd = open(point_file,'w') 1182 fd.write("elevation, stage \n 1.0, 1.0,2.,4 \n 1.0, 3.0,4,8 \n 3.0,1.0,4.,8 \n") 1183 fd.close() 1184 1185 mesh_output_file = "new_triangle.msh" 1186 fit_to_mesh_file(mesh_file, 1187 point_file, 1188 mesh_output_file, 1189 alpha = 0.0) 1190 # load in the .tsh file we just wrote 1191 mesh_dic = mesh_file_to_mesh_dictionary(mesh_output_file) 1192 1193 assert allclose(mesh_dic['vertex_attributes'], 1194 [[1.0, 2.0,0.0, 0.0], 1195 [1.0, 2.0,5.0, 10.0], 1196 [1.0, 2.0,5.0,10.0]]) 1197 1198 self.failUnless(mesh_dic['vertex_attribute_titles'] == 1199 ['density', 'temp','elevation','stage'], 1200 'test_fit_to_mesh_file failed') 1201 1202 #clean up 1203 os.remove(mesh_file) 1204 os.remove(mesh_output_file) 1205 os.remove(point_file) 1206 1159 1207 #------------------------------------------------------------- 1160 1208 if __name__ == "__main__": 1161 1209 suite = unittest.makeSuite(TestCase,'test') 1162 1210 1163 #suite = unittest.makeSuite(TestCase,'test_arbitrary_datapoints') 1211 #suite = unittest.makeSuite(TestCase,'test_fit_to_msh_netcdf_fileII') 1212 #suite = unittest.makeSuite(TestCase,'test_fit_to_mesh_fileII') 1164 1213 runner = unittest.TextTestRunner(verbosity=1) 1165 1214 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.