1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | |
---|
4 | import tempfile |
---|
5 | import unittest |
---|
6 | |
---|
7 | import os |
---|
8 | import tempfile |
---|
9 | |
---|
10 | from os.path import splitext |
---|
11 | |
---|
12 | from Numeric import array, allclose |
---|
13 | |
---|
14 | from loadASCII import * |
---|
15 | from coordinate_transforms.geo_reference import Geo_reference |
---|
16 | import loadASCII |
---|
17 | |
---|
18 | class loadASCIITestCase(unittest.TestCase): |
---|
19 | def setUp(self): |
---|
20 | self.dict ={} |
---|
21 | self.dict['outline_segments'] = [(0, 1), (1, 2), (0, 2), (0, 3)] |
---|
22 | self.dict['outline_segment_tags'] = ['50', '40', '30', '20'] |
---|
23 | self.dict['holes'] = [(0.2, 0.6)] |
---|
24 | self.dict['point_attributes'] = [[5, 2], [4, 2], [3, 2], [2,2]] |
---|
25 | self.dict['regions'] = [(0.3, 0.3),(0.3, 0.4)] |
---|
26 | self.dict['region_tags'] = ['1.3', 'yeah'] |
---|
27 | self.dict['region_max_areas'] = [36.0,-7.1] |
---|
28 | self.dict['points'] = [(0.0, 0.0), (0.0, 4.0), (4.0, 0.0), (1.0, 1.0)] |
---|
29 | self.dict['vertices'] = [(0.0, 0.0), (0.0, 4.0), |
---|
30 | (4.0, 0.0), (1.0, 1.0), (2.0, 2.0)] |
---|
31 | self.dict['triangles'] = [(3, 2, 4), (1, 0, 3), |
---|
32 | (3, 4,1), (2, 3, 0)] |
---|
33 | self.dict['segments'] = [(0, 1), (1, 4), (2, 0), |
---|
34 | (0, 3), (4, 2)] |
---|
35 | self.dict['triangle_tags'] = ['1.3', '1.3', |
---|
36 | '1.3', '1.3'] |
---|
37 | self.dict['vertex_attributes'] = [[1.2,2.], [1.2,2.], |
---|
38 | [1.2,2.], [1.2,2.], [1.2,3.]] |
---|
39 | self.dict['triangle_neighbors'] = [[-1, 2, 3], [3, 2, -1], |
---|
40 | [-1, 1, 0], [1, -1, 0]] |
---|
41 | self.dict['segment_tags'] = ['50', '40', '30', '20', '40'] |
---|
42 | self.dict['vertex_attribute_titles'] = ['bed elevation', 'height'] |
---|
43 | self.dict['geo_reference'] = Geo_reference(56,1.9,1.9) |
---|
44 | |
---|
45 | self.sparse_dict ={} |
---|
46 | self.sparse_dict['outline_segments'] = [] |
---|
47 | self.sparse_dict['outline_segment_tags'] = [] |
---|
48 | self.sparse_dict['holes'] = [] |
---|
49 | self.sparse_dict['points'] = [(0.0, 0.0),(9,8)] |
---|
50 | self.sparse_dict['point_attributes'] = [[],[]] # points don't have to have |
---|
51 | # attributes |
---|
52 | self.sparse_dict['regions'] = [] |
---|
53 | self.sparse_dict['region_tags'] = [] |
---|
54 | self.sparse_dict['region_max_areas'] = [] |
---|
55 | |
---|
56 | self.sparse_dict['vertices'] = [] |
---|
57 | self.sparse_dict['triangles'] = [] |
---|
58 | self.sparse_dict['segments'] = [] |
---|
59 | self.sparse_dict['triangle_tags'] = [] |
---|
60 | self.sparse_dict['vertex_attributes'] = [] |
---|
61 | self.sparse_dict['triangle_neighbors'] = [] |
---|
62 | self.sparse_dict['segment_tags'] = [] |
---|
63 | self.sparse_dict['vertex_attribute_titles'] = [] |
---|
64 | |
---|
65 | self.blank_dict ={} |
---|
66 | self.blank_dict['outline_segments'] = [] |
---|
67 | self.blank_dict['outline_segment_tags'] = [] |
---|
68 | self.blank_dict['holes'] = [] |
---|
69 | self.blank_dict['points'] = [] |
---|
70 | self.blank_dict['point_attributes'] = [] |
---|
71 | self.blank_dict['regions'] = [] |
---|
72 | self.blank_dict['region_tags'] = [] |
---|
73 | self.blank_dict['region_max_areas'] = [] |
---|
74 | self.blank_dict['vertices'] = [] |
---|
75 | self.blank_dict['triangles'] = [] |
---|
76 | self.blank_dict['segments'] = [] |
---|
77 | self.blank_dict['triangle_tags'] = [] |
---|
78 | self.blank_dict['vertex_attributes'] = [] |
---|
79 | self.blank_dict['triangle_neighbors'] = [] |
---|
80 | self.blank_dict['segment_tags'] = [] |
---|
81 | self.blank_dict['vertex_attribute_titles'] = [] |
---|
82 | |
---|
83 | self.tri_dict ={} |
---|
84 | self.tri_dict['outline_segments'] = [[0,1]] |
---|
85 | self.tri_dict['outline_segment_tags'] = [''] |
---|
86 | self.tri_dict['holes'] = [] |
---|
87 | self.tri_dict['points'] = [(9,8),(7,8)] |
---|
88 | self.tri_dict['point_attributes'] = [[],[]] |
---|
89 | self.tri_dict['regions'] = [] |
---|
90 | self.tri_dict['region_tags'] = [] |
---|
91 | self.tri_dict['region_max_areas'] = [] |
---|
92 | self.tri_dict['vertices'] = [[9,8],[7,8], [4,5]] |
---|
93 | self.tri_dict['triangles'] = [[0,1,2]] |
---|
94 | self.tri_dict['segments'] = [[0,1]] |
---|
95 | self.tri_dict['triangle_tags'] = [''] |
---|
96 | self.tri_dict['vertex_attributes'] = [[],[],[]] |
---|
97 | self.tri_dict['triangle_neighbors'] = [[0,0,0]] |
---|
98 | self.tri_dict['segment_tags'] = [''] |
---|
99 | self.tri_dict['vertex_attribute_titles'] = [] |
---|
100 | |
---|
101 | self.seg_dict ={} |
---|
102 | self.seg_dict['outline_segments'] = [[0,1]] |
---|
103 | self.seg_dict['outline_segment_tags'] = [''] |
---|
104 | self.seg_dict['holes'] = [] |
---|
105 | self.seg_dict['points'] = [(9,8),(7,8)] |
---|
106 | self.seg_dict['point_attributes'] = [[],[]] |
---|
107 | self.seg_dict['regions'] = [(5,4)] |
---|
108 | self.seg_dict['region_tags'] = [''] |
---|
109 | self.seg_dict['region_max_areas'] = [-999] |
---|
110 | self.seg_dict['vertices'] = [(9,8),(7,8)] |
---|
111 | self.seg_dict['triangles'] = [] |
---|
112 | self.seg_dict['segments'] = [[0,1]] |
---|
113 | self.seg_dict['triangle_tags'] = [] |
---|
114 | self.seg_dict['vertex_attributes'] = [[],[]] |
---|
115 | self.seg_dict['triangle_neighbors'] = [] |
---|
116 | self.seg_dict['segment_tags'] = [''] |
---|
117 | self.seg_dict['vertex_attribute_titles'] = [] |
---|
118 | |
---|
119 | self.reg_dict ={} |
---|
120 | self.reg_dict['outline_segments'] = [[0,1]] |
---|
121 | self.reg_dict['outline_segment_tags'] = [''] |
---|
122 | self.reg_dict['holes'] = [] |
---|
123 | self.reg_dict['points'] = [(9,8),(7,8)] |
---|
124 | self.reg_dict['point_attributes'] = [[],[]] |
---|
125 | self.reg_dict['regions'] = [(5,4)] |
---|
126 | self.reg_dict['region_tags'] = [''] |
---|
127 | self.reg_dict['region_max_areas'] = [] |
---|
128 | self.reg_dict['vertices'] = [(9,8),(7,8)] |
---|
129 | self.reg_dict['triangles'] = [] |
---|
130 | self.reg_dict['segments'] = [[0,1]] |
---|
131 | self.reg_dict['triangle_tags'] = [] |
---|
132 | self.reg_dict['vertex_attributes'] = [[],[]] |
---|
133 | self.reg_dict['triangle_neighbors'] = [] |
---|
134 | self.reg_dict['segment_tags'] = [''] |
---|
135 | self.reg_dict['vertex_attribute_titles'] = [] |
---|
136 | |
---|
137 | self.triangle_tags_dict ={} |
---|
138 | self.triangle_tags_dict['outline_segments'] = [(0, 1), (1, 2), (0, 2), (0, 3)] |
---|
139 | self.triangle_tags_dict['outline_segment_tags'] = ['50', '40', '30', '20'] |
---|
140 | self.triangle_tags_dict['holes'] = [(0.2, 0.6)] |
---|
141 | self.triangle_tags_dict['point_attributes'] = [[5, 2], [4, 2], [3, 2], [2,2]] |
---|
142 | self.triangle_tags_dict['regions'] = [(0.3, 0.3),(0.3, 0.4)] |
---|
143 | self.triangle_tags_dict['region_tags'] = ['1.3', 'yeah'] |
---|
144 | self.triangle_tags_dict['region_max_areas'] = [36.0,-7.1] |
---|
145 | self.triangle_tags_dict['points'] = [(0.0, 0.0), (0.0, 4.0), (4.0, 0.0), (1.0, 1.0)] |
---|
146 | self.triangle_tags_dict['vertices'] = [(0.0, 0.0), (0.0, 4.0), |
---|
147 | (4.0, 0.0), (1.0, 1.0), (2.0, 2.0)] |
---|
148 | self.triangle_tags_dict['triangles'] = [(3, 2, 4), (1, 0, 3), |
---|
149 | (3, 4,1), (2, 3, 0)] |
---|
150 | self.triangle_tags_dict['segments'] = [(0, 1), (1, 4), (2, 0), |
---|
151 | (0, 3), (4, 2)] |
---|
152 | self.triangle_tags_dict['triangle_tags'] = ['yeah', '1.3', |
---|
153 | '1.3', ''] |
---|
154 | self.triangle_tags_dict['vertex_attributes'] = [[1.2,2.], [1.2,2.], |
---|
155 | [1.2,2.], [1.2,2.], [1.2,3.]] |
---|
156 | self.triangle_tags_dict['triangle_neighbors'] = [[-1, 2, 3], [3, 2, -1], |
---|
157 | [-1, 1, 0], [1, -1, 0]] |
---|
158 | self.triangle_tags_dict['segment_tags'] = ['50', '40', '30', '20', '40'] |
---|
159 | self.triangle_tags_dict['vertex_attribute_titles'] = ['bed elevation', 'height'] |
---|
160 | self.triangle_tags_dict['geo_reference'] = Geo_reference(56,1.9,1.9) |
---|
161 | |
---|
162 | def tearDown(self): |
---|
163 | pass |
---|
164 | |
---|
165 | ############### .TSH ########## |
---|
166 | def test_export_mesh_file(self): |
---|
167 | import os |
---|
168 | import tempfile |
---|
169 | |
---|
170 | meshDict = self.dict |
---|
171 | fileName = tempfile.mktemp(".tsh") |
---|
172 | export_mesh_file(fileName, meshDict) |
---|
173 | loadedDict = import_mesh_file(fileName) |
---|
174 | |
---|
175 | #print "*(*( meshDict" |
---|
176 | #print meshDict |
---|
177 | #print "*(*( loadedDcit" |
---|
178 | #print loadedDict |
---|
179 | #print "*(*(" |
---|
180 | |
---|
181 | self.failUnless(array(meshDict['vertices']) == |
---|
182 | array(loadedDict['vertices']), |
---|
183 | 'test_export_mesh_file failed. Test 1') |
---|
184 | self.failUnless(array(meshDict['triangles']) == |
---|
185 | array(loadedDict['triangles']), |
---|
186 | 'test_export_mesh_file failed. Test 2') |
---|
187 | self.failUnless(array(meshDict['segments']) == |
---|
188 | array(loadedDict['segments']), |
---|
189 | 'test_export_mesh_file failed. Test 3') |
---|
190 | self.failUnless(array(meshDict['triangle_tags']) == |
---|
191 | array(loadedDict['triangle_tags']), |
---|
192 | 'test_export_mesh_file failed. Test 4') |
---|
193 | |
---|
194 | self.failUnless(meshDict['vertex_attributes'] == |
---|
195 | loadedDict['vertex_attributes'], |
---|
196 | 'test_export_mesh_file failed. Test 5') |
---|
197 | self.failUnless(array(meshDict['triangle_neighbors']) == |
---|
198 | array(loadedDict['triangle_neighbors']), |
---|
199 | 'test_export_mesh_file failed. Test 6') |
---|
200 | self.failUnless(array(meshDict['segment_tags']) == |
---|
201 | array(loadedDict['segment_tags']), |
---|
202 | 'test_export_mesh_file failed. Test 7') |
---|
203 | self.failUnless(array(meshDict['vertex_attribute_titles']) == |
---|
204 | array(loadedDict['vertex_attribute_titles']), |
---|
205 | 'test_export_mesh_file failed. Test 8') |
---|
206 | self.failUnless(array(meshDict['geo_reference']) == |
---|
207 | array(loadedDict['geo_reference']), |
---|
208 | 'test_export_mesh_file failed. Test 9') |
---|
209 | |
---|
210 | os.remove(fileName) |
---|
211 | |
---|
212 | def test_read_write_tsh_file(self): |
---|
213 | dict = self.dict.copy() |
---|
214 | fileName = tempfile.mktemp(".tsh") |
---|
215 | export_mesh_file(fileName,dict) |
---|
216 | loaded_dict = import_mesh_file(fileName) |
---|
217 | os.remove(fileName) |
---|
218 | dict = self.dict |
---|
219 | #print "*********************" |
---|
220 | #print dict |
---|
221 | #print "**loaded_dict*******************" |
---|
222 | #print loaded_dict |
---|
223 | #print "*********************" |
---|
224 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file') |
---|
225 | |
---|
226 | def test_read_write_tsh_fileII(self): |
---|
227 | dict = self.sparse_dict.copy() |
---|
228 | fileName = tempfile.mktemp(".tsh") |
---|
229 | export_mesh_file(fileName,dict) |
---|
230 | loaded_dict = import_mesh_file(fileName) |
---|
231 | dict = self.sparse_dict |
---|
232 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file') |
---|
233 | os.remove(fileName) |
---|
234 | |
---|
235 | def test_read_write_tsh_fileIII(self): |
---|
236 | dict = self.blank_dict.copy() |
---|
237 | fileName = tempfile.mktemp(".tsh") |
---|
238 | export_mesh_file(fileName,dict) |
---|
239 | loaded_dict = import_mesh_file(fileName) |
---|
240 | os.remove(fileName) |
---|
241 | dict = self.blank_dict |
---|
242 | #print "*********************" |
---|
243 | #print dict |
---|
244 | #print "**loaded_dict*******************" |
---|
245 | #print loaded_dict |
---|
246 | #print "*********************" |
---|
247 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileIII') |
---|
248 | |
---|
249 | def test_read_write_tsh_file4(self): |
---|
250 | dict = self.seg_dict.copy() |
---|
251 | fileName = tempfile.mktemp(".tsh") |
---|
252 | export_mesh_file(fileName,dict) |
---|
253 | loaded_dict = import_mesh_file(fileName) |
---|
254 | os.remove(fileName) |
---|
255 | dict = self.seg_dict |
---|
256 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file4') |
---|
257 | |
---|
258 | def test_read_write_tsh_file5(self): |
---|
259 | dict = self.triangle_tags_dict.copy() |
---|
260 | fileName = tempfile.mktemp(".tsh") |
---|
261 | export_mesh_file(fileName,dict) |
---|
262 | loaded_dict = import_mesh_file(fileName) |
---|
263 | dict = self.triangle_tags_dict |
---|
264 | #print "*********************" |
---|
265 | #print dict |
---|
266 | #print "**loaded_dict*******************" |
---|
267 | #print loaded_dict |
---|
268 | #print "*********************" |
---|
269 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file5') |
---|
270 | os.remove(fileName) |
---|
271 | |
---|
272 | def test_read_write_tsh_file6(self): |
---|
273 | dict = self.tri_dict.copy() |
---|
274 | fileName = tempfile.mktemp(".tsh") |
---|
275 | export_mesh_file(fileName,dict) |
---|
276 | loaded_dict = import_mesh_file(fileName) |
---|
277 | dict = self.tri_dict |
---|
278 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file6') |
---|
279 | os.remove(fileName) |
---|
280 | |
---|
281 | ########################## BAD .TSH ########################## |
---|
282 | |
---|
283 | def test_load_bad_no_file_tsh(self): |
---|
284 | import os |
---|
285 | import tempfile |
---|
286 | |
---|
287 | fileName = tempfile.mktemp(".tsh") |
---|
288 | #print fileName |
---|
289 | try: |
---|
290 | dict = import_mesh_file(fileName) |
---|
291 | except IOError: |
---|
292 | pass |
---|
293 | else: |
---|
294 | self.failUnless(0 ==1, |
---|
295 | 'imaginary file did not raise error!') |
---|
296 | |
---|
297 | def test_read_write_tsh_file_bad(self): |
---|
298 | dict = self.tri_dict.copy() |
---|
299 | fileName = tempfile.mktemp(".xxx") |
---|
300 | try: |
---|
301 | export_mesh_file(fileName,dict) |
---|
302 | except IOError: |
---|
303 | pass |
---|
304 | else: |
---|
305 | self.failUnless(0 ==1, |
---|
306 | 'bad tsh file did not raise error!') |
---|
307 | |
---|
308 | def test_import_tsh_bad(self): |
---|
309 | import os |
---|
310 | import tempfile |
---|
311 | |
---|
312 | fileName = tempfile.mktemp(".tsh") |
---|
313 | file = open(fileName,"w") |
---|
314 | # this is a bad tsh file |
---|
315 | file.write("elevn\n\ |
---|
316 | 1.0 what \n\ |
---|
317 | 0.0 the \n\ |
---|
318 | 1.0 !!! \n") |
---|
319 | file.close() |
---|
320 | #print fileName |
---|
321 | try: |
---|
322 | dict = import_points_file(fileName,delimiter = ' ') |
---|
323 | except IOError: |
---|
324 | pass |
---|
325 | else: |
---|
326 | self.failUnless(0 ==1, |
---|
327 | 'bad tsh file did not raise error!') |
---|
328 | os.remove(fileName) |
---|
329 | |
---|
330 | def test_import_tsh3(self): |
---|
331 | import os |
---|
332 | import tempfile |
---|
333 | |
---|
334 | fileName = tempfile.mktemp(".tsh") |
---|
335 | file = open(fileName,"w") |
---|
336 | file.write("1.0 \n\ |
---|
337 | showme1.0 0.0 10.0 \n\ |
---|
338 | 0.0 1.0\n\ |
---|
339 | 13.0 \n") |
---|
340 | file.close() |
---|
341 | #print fileName |
---|
342 | try: |
---|
343 | dict = import_points_file(fileName,delimiter = ' ') |
---|
344 | except IOError: |
---|
345 | pass |
---|
346 | else: |
---|
347 | self.failUnless(0 ==1, |
---|
348 | 'bad tsh file did not raise error!') |
---|
349 | |
---|
350 | os.remove(fileName) |
---|
351 | |
---|
352 | |
---|
353 | ############### .MSH ########## |
---|
354 | |
---|
355 | def test_read_write_msh_file(self): |
---|
356 | dict = self.dict.copy() |
---|
357 | fileName = tempfile.mktemp(".msh") |
---|
358 | export_mesh_file(fileName,dict) |
---|
359 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
360 | os.remove(fileName) |
---|
361 | dict = self.dict |
---|
362 | #print "*********************" |
---|
363 | #print dict |
---|
364 | #print "**loaded_dict*******************" |
---|
365 | #print loaded_dict |
---|
366 | #print "*********************" |
---|
367 | self.check_mesh_dicts(loaded_dict,dict,'test_read_write_msh_file') |
---|
368 | |
---|
369 | def test_read_write_msh_fileII(self): |
---|
370 | dict = self.sparse_dict.copy() |
---|
371 | fileName = tempfile.mktemp(".msh") |
---|
372 | export_mesh_file(fileName,dict) |
---|
373 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
374 | os.remove(fileName) |
---|
375 | dict = self.sparse_dict |
---|
376 | #print "*********************" |
---|
377 | #print dict |
---|
378 | #print "**loaded_dict*******************" |
---|
379 | #print loaded_dict |
---|
380 | #print "*********************" |
---|
381 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileII') |
---|
382 | |
---|
383 | def test_read_write_msh_fileIII(self): |
---|
384 | dict = self.blank_dict.copy() |
---|
385 | fileName = tempfile.mktemp(".msh") |
---|
386 | export_mesh_file(fileName,dict) |
---|
387 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
388 | os.remove(fileName) |
---|
389 | dict = self.blank_dict |
---|
390 | #print "*********************" |
---|
391 | #print dict |
---|
392 | #print "**loaded_dict*******************" |
---|
393 | #print loaded_dict |
---|
394 | #print "*********************" |
---|
395 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileIII') |
---|
396 | |
---|
397 | def test_read_write_msh_file4(self): |
---|
398 | dict = self.seg_dict.copy() |
---|
399 | fileName = tempfile.mktemp(".msh") |
---|
400 | export_mesh_file(fileName,dict) |
---|
401 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
402 | os.remove(fileName) |
---|
403 | dict = self.seg_dict |
---|
404 | #print "*********************" |
---|
405 | #print dict |
---|
406 | #print "**loaded_dict*******************" |
---|
407 | #print loaded_dict |
---|
408 | #print "*********************" |
---|
409 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileIII') |
---|
410 | |
---|
411 | def test_read_write_msh_file5(self): |
---|
412 | dict = self.triangle_tags_dict.copy() |
---|
413 | fileName = tempfile.mktemp(".msh") |
---|
414 | export_mesh_file(fileName,dict) |
---|
415 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
416 | os.remove(fileName) |
---|
417 | dict = self.triangle_tags_dict |
---|
418 | #print "msh_file5*********************" |
---|
419 | #print dict |
---|
420 | #print "**loaded_dict*******************" |
---|
421 | #print loaded_dict |
---|
422 | #print "*********************" |
---|
423 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileIII') |
---|
424 | |
---|
425 | |
---|
426 | def test_read_write_msh_file6(self): |
---|
427 | dict = self.tri_dict.copy() |
---|
428 | fileName = tempfile.mktemp(".msh") |
---|
429 | export_mesh_file(fileName,dict) |
---|
430 | loaded_dict = loadASCII._read_msh_file(fileName) |
---|
431 | os.remove(fileName) |
---|
432 | dict = self.tri_dict |
---|
433 | #print "*********************" |
---|
434 | #print dict |
---|
435 | #print "**loaded_dict*******************" |
---|
436 | #print loaded_dict |
---|
437 | #print "*********************" |
---|
438 | self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_fileIII') |
---|
439 | |
---|
440 | def check_mesh_dicts(self, loaded_dict, dict, fail_string ): |
---|
441 | assert allclose(array(loaded_dict['points']), |
---|
442 | array(dict['points'])) |
---|
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'])) |
---|
448 | |
---|
449 | self.failUnless(loaded_dict['outline_segment_tags'] == |
---|
450 | dict['outline_segment_tags'], |
---|
451 | fail_string + ' failed!! Test 4') |
---|
452 | |
---|
453 | |
---|
454 | assert allclose(array(loaded_dict['regions']), |
---|
455 | array(dict['regions'])) |
---|
456 | self.failUnless(loaded_dict['region_tags'] == |
---|
457 | dict['region_tags'], |
---|
458 | fail_string + ' failed!! Test 5') |
---|
459 | |
---|
460 | assert allclose(array(loaded_dict['region_max_areas']), |
---|
461 | array(dict['region_max_areas'])) |
---|
462 | |
---|
463 | assert allclose(array(loaded_dict['holes']), |
---|
464 | array(dict['holes'])) |
---|
465 | |
---|
466 | assert allclose(array(dict['vertices']), |
---|
467 | array(loaded_dict['vertices'])) |
---|
468 | |
---|
469 | assert allclose(array(dict['triangles']), |
---|
470 | array(loaded_dict['triangles'])) |
---|
471 | |
---|
472 | assert allclose(array(dict['segments']), |
---|
473 | array(loaded_dict['segments'])) |
---|
474 | for ob, ldob in map(None,dict['triangle_tags'], |
---|
475 | loaded_dict['triangle_tags']): |
---|
476 | self.failUnless(ob == ldob, |
---|
477 | fail_string + ' failed!! Test triangle_tags') |
---|
478 | self.failUnless(loaded_dict['vertex_attributes'] == |
---|
479 | dict['vertex_attributes'], |
---|
480 | fail_string + ' failed!! Test vertex_attributes') |
---|
481 | |
---|
482 | assert allclose(array(dict['triangle_neighbors']), |
---|
483 | array(loaded_dict['triangle_neighbors'])) |
---|
484 | |
---|
485 | for seg, ldseg in map(None,dict['segment_tags'], |
---|
486 | loaded_dict['segment_tags']): |
---|
487 | self.failUnless(seg == ldseg, |
---|
488 | fail_string + ' failed!! Test 8') |
---|
489 | try: |
---|
490 | assert allclose(array(dict['vertex_attribute_titles']), |
---|
491 | array(loaded_dict['vertex_attribute_titles'])) |
---|
492 | except TypeError: |
---|
493 | self.failUnless(array(loaded_dict['vertex_attribute_titles']) == |
---|
494 | array(dict['vertex_attribute_titles']), |
---|
495 | fail_string + ' failed!! Test 8') |
---|
496 | try: |
---|
497 | self.failUnless(loaded_dict['geo_reference'] == |
---|
498 | dict['geo_reference'] , |
---|
499 | fail_string + ' failed!! Test geo_reference') |
---|
500 | except KeyError: |
---|
501 | self.failUnless(not dict.has_key('geo_reference' and |
---|
502 | loaded_dict['geo_reference'] == None) , |
---|
503 | fail_string + ' failed!! Test geo_reference') |
---|
504 | |
---|
505 | ########################## BAD .MSH ########################## |
---|
506 | |
---|
507 | def test_load_bad_no_file_msh(self): |
---|
508 | import os |
---|
509 | import tempfile |
---|
510 | |
---|
511 | fileName = tempfile.mktemp(".msh") |
---|
512 | #print fileName |
---|
513 | try: |
---|
514 | dict = import_mesh_file(fileName) |
---|
515 | except IOError: |
---|
516 | pass |
---|
517 | else: |
---|
518 | self.failUnless(0 ==1, |
---|
519 | 'imaginary file did not raise error!') |
---|
520 | |
---|
521 | def test_import_msh_bad(self): |
---|
522 | import os |
---|
523 | import tempfile |
---|
524 | |
---|
525 | fileName = tempfile.mktemp(".msh") |
---|
526 | file = open(fileName,"w") |
---|
527 | # this is a bad tsh file |
---|
528 | file.write("elevn\n\ |
---|
529 | 1.0 what \n\ |
---|
530 | 0.0 the \n\ |
---|
531 | 1.0 !!! \n") |
---|
532 | file.close() |
---|
533 | #print fileName |
---|
534 | try: |
---|
535 | dict = import_points_file(fileName,delimiter = ' ') |
---|
536 | except IOError: |
---|
537 | pass |
---|
538 | else: |
---|
539 | self.failUnless(0 ==1, |
---|
540 | 'bad msh file did not raise error!') |
---|
541 | os.remove(fileName) |
---|
542 | |
---|
543 | ###################### .XYA ############################## |
---|
544 | |
---|
545 | def test_export_xya_file(self): |
---|
546 | dict = {} |
---|
547 | att_dict = {} |
---|
548 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
549 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
550 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
551 | dict['attributelist'] = att_dict |
---|
552 | dict['geo_reference'] = Geo_reference(56,1.9,1.9) |
---|
553 | |
---|
554 | |
---|
555 | fileName = tempfile.mktemp(".xya") |
---|
556 | export_points_file(fileName, dict) |
---|
557 | dict2 = import_points_file(fileName) |
---|
558 | #print "fileName",fileName |
---|
559 | os.remove(fileName) |
---|
560 | #print "dict2",dict2 |
---|
561 | |
---|
562 | assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
563 | assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
564 | answer = [10.0, 0.0, 10.4] |
---|
565 | assert allclose(dict2['attributelist']['brightness'], answer) |
---|
566 | #print "dict2['geo_reference']",dict2['geo_reference'] |
---|
567 | self.failUnless(dict['geo_reference'] == dict2['geo_reference'], |
---|
568 | 'test_writepts failed. Test geo_reference') |
---|
569 | |
---|
570 | def test_export_xya_file2(self): |
---|
571 | dict = {} |
---|
572 | att_dict = {} |
---|
573 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
574 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
575 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
576 | dict['attributelist'] = att_dict |
---|
577 | |
---|
578 | |
---|
579 | fileName = tempfile.mktemp(".xya") |
---|
580 | export_points_file(fileName, dict) |
---|
581 | dict2 = import_points_file(fileName) |
---|
582 | #print "fileName",fileName |
---|
583 | os.remove(fileName) |
---|
584 | #print "dict2",dict2 |
---|
585 | |
---|
586 | assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
587 | assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
588 | answer = [10.0, 0.0, 10.4] |
---|
589 | assert allclose(dict2['attributelist']['brightness'], answer) |
---|
590 | |
---|
591 | |
---|
592 | def test_loadxya(self): |
---|
593 | """ |
---|
594 | comma delimited |
---|
595 | """ |
---|
596 | |
---|
597 | fileName = tempfile.mktemp(".xya") |
---|
598 | file = open(fileName,"w") |
---|
599 | file.write("elevation , speed \n\ |
---|
600 | 1.0, 0.0, 10.0, 0.0\n\ |
---|
601 | 0.0, 1.0, 0.0, 10.0\n\ |
---|
602 | 1.0, 0.0, 10.4, 40.0\n") |
---|
603 | file.close() |
---|
604 | #print fileName |
---|
605 | dict = import_points_file(fileName,delimiter = ',') |
---|
606 | os.remove(fileName) |
---|
607 | assert allclose(dict['pointlist'], [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
608 | assert allclose(dict['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
609 | assert allclose(dict['attributelist']['speed'], [0.0, 10.0, 40.0]) |
---|
610 | |
---|
611 | #FIXME - redundant test? |
---|
612 | def test_loadxy(self): |
---|
613 | """ |
---|
614 | To test the mesh side of loading xya files. |
---|
615 | Not the loading of xya files |
---|
616 | """ |
---|
617 | import os |
---|
618 | import tempfile |
---|
619 | |
---|
620 | fileName = tempfile.mktemp(".xya") |
---|
621 | file = open(fileName,"w") |
---|
622 | file.write("elevation speed \n\ |
---|
623 | 1.0 0.0 10.0 0.0\n\ |
---|
624 | 0.0 1.0 0.0 10.0\n\ |
---|
625 | 1.0 0.0 10.4 40.0\n") |
---|
626 | file.close() |
---|
627 | #print fileName |
---|
628 | dict = import_points_file(fileName) |
---|
629 | os.remove(fileName) |
---|
630 | assert allclose(dict['pointlist'], [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
631 | assert allclose(dict['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
632 | assert allclose(dict['attributelist']['speed'], [0.0, 10.0, 40.0]) |
---|
633 | |
---|
634 | |
---|
635 | def test_loadxya2(self): |
---|
636 | """ |
---|
637 | space delimited |
---|
638 | """ |
---|
639 | import os |
---|
640 | import tempfile |
---|
641 | |
---|
642 | fileName = tempfile.mktemp(".xya") |
---|
643 | file = open(fileName,"w") |
---|
644 | file.write(" elevation speed \n\ |
---|
645 | 1.0 0.0 10.0 0.0\n\ |
---|
646 | 0.0 1.0 0.0 10.0\n\ |
---|
647 | 1.0 0.0 10.4 40.0\n") |
---|
648 | file.close() |
---|
649 | #print fileName |
---|
650 | dict = import_points_file(fileName,delimiter = ' ') |
---|
651 | os.remove(fileName) |
---|
652 | assert allclose(dict['pointlist'], [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
653 | assert allclose(dict['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
654 | assert allclose(dict['attributelist']['speed'], [0.0, 10.0, 40.0]) |
---|
655 | |
---|
656 | def test_loadxya3(self): |
---|
657 | """ |
---|
658 | space delimited |
---|
659 | """ |
---|
660 | import os |
---|
661 | import tempfile |
---|
662 | |
---|
663 | fileName = tempfile.mktemp(".xya") |
---|
664 | file = open(fileName,"w") |
---|
665 | file.write(" elevation speed \n\ |
---|
666 | 1.0 0.0 10.0 0.0\n\ |
---|
667 | 0.0 1.0 0.0 10.0\n\ |
---|
668 | 1.0 0.0 10.4 40.0\n\ |
---|
669 | #geocrap\n\ |
---|
670 | 56\n\ |
---|
671 | 56.6\n\ |
---|
672 | 3\n") |
---|
673 | file.close() |
---|
674 | #print fileName |
---|
675 | dict = import_points_file(fileName,delimiter = ' ') |
---|
676 | os.remove(fileName) |
---|
677 | assert allclose(dict['pointlist'], [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
678 | assert allclose(dict['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
679 | assert allclose(dict['attributelist']['speed'], [0.0, 10.0, 40.0]) |
---|
680 | |
---|
681 | geo_reference = Geo_reference(56, 56.6, 3.0) |
---|
682 | |
---|
683 | self.failUnless(geo_reference == dict['geo_reference'], |
---|
684 | 'test_writepts failed. Test geo_reference') |
---|
685 | |
---|
686 | ########################## BAD .XYA ########################## |
---|
687 | |
---|
688 | def test_loadxy_bad_no_file_xya(self): |
---|
689 | import os |
---|
690 | import tempfile |
---|
691 | |
---|
692 | fileName = tempfile.mktemp(".xya") |
---|
693 | #print fileName |
---|
694 | try: |
---|
695 | dict = import_points_file(fileName,delimiter = ' ') |
---|
696 | except IOError: |
---|
697 | pass |
---|
698 | else: |
---|
699 | self.failUnless(0 ==1, |
---|
700 | 'imaginary file did not raise error!') |
---|
701 | |
---|
702 | def test_read_write_points_file_bad(self): |
---|
703 | dict = self.tri_dict.copy() |
---|
704 | fileName = tempfile.mktemp(".xxx") |
---|
705 | try: |
---|
706 | export_points_file(fileName,dict) |
---|
707 | except IOError: |
---|
708 | pass |
---|
709 | else: |
---|
710 | self.failUnless(0 ==1, |
---|
711 | 'bad points file extension did not raise error!') |
---|
712 | |
---|
713 | def test_read_write_points_file_bad2(self): |
---|
714 | dict = {} |
---|
715 | att_dict = {} |
---|
716 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
717 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
718 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
719 | dict['attributelist'] = att_dict |
---|
720 | dict['geo_reference'] = Geo_reference(56,1.9,1.9) |
---|
721 | try: |
---|
722 | export_points_file("_???/yeah.xya",dict) |
---|
723 | except IOError: |
---|
724 | pass |
---|
725 | else: |
---|
726 | self.failUnless(0 ==1, |
---|
727 | 'bad points file extension did not raise error!') |
---|
728 | |
---|
729 | def test_loadxy_bad(self): |
---|
730 | import os |
---|
731 | import tempfile |
---|
732 | |
---|
733 | fileName = tempfile.mktemp(".xya") |
---|
734 | file = open(fileName,"w") |
---|
735 | file.write(" elevation \n\ |
---|
736 | 1.0 0.0 10.0 0.0\n\ |
---|
737 | 0.0 1.0 0.0 10.0\n\ |
---|
738 | 1.0 0.0 10.4 40.0\n") |
---|
739 | file.close() |
---|
740 | #print fileName |
---|
741 | try: |
---|
742 | dict = import_points_file(fileName,delimiter = ' ') |
---|
743 | except IOError: |
---|
744 | pass |
---|
745 | else: |
---|
746 | self.failUnless(0 ==1, |
---|
747 | 'bad xya file did not raise error!') |
---|
748 | os.remove(fileName) |
---|
749 | |
---|
750 | def test_loadxy_bad2(self): |
---|
751 | import os |
---|
752 | import tempfile |
---|
753 | |
---|
754 | fileName = tempfile.mktemp(".xya") |
---|
755 | file = open(fileName,"w") |
---|
756 | file.write("elevation\n\ |
---|
757 | 1.0 0.0 10.0 \n\ |
---|
758 | 0.0 1.0\n\ |
---|
759 | 1.0 \n") |
---|
760 | file.close() |
---|
761 | #print fileName |
---|
762 | try: |
---|
763 | dict = import_points_file(fileName,delimiter = ' ') |
---|
764 | except IOError: |
---|
765 | pass |
---|
766 | else: |
---|
767 | self.failUnless(0 ==1, |
---|
768 | 'bad xya file did not raise error!') |
---|
769 | os.remove(fileName) |
---|
770 | |
---|
771 | def test_loadxy_bad3(self): |
---|
772 | """ |
---|
773 | specifying wrong delimiter |
---|
774 | """ |
---|
775 | import os |
---|
776 | import tempfile |
---|
777 | |
---|
778 | fileName = tempfile.mktemp(".xya") |
---|
779 | file = open(fileName,"w") |
---|
780 | file.write(" elevation , speed \n\ |
---|
781 | 1.0, 0.0, 10.0, 0.0\n\ |
---|
782 | 0.0, 1.0, 0.0, 10.0\n\ |
---|
783 | 1.0, 0.0, 10.4, 40.0\n") |
---|
784 | file.close() |
---|
785 | try: |
---|
786 | dict = import_points_file(fileName,delimiter = ' ') |
---|
787 | except IOError: |
---|
788 | pass |
---|
789 | else: |
---|
790 | self.failUnless(0 ==1, |
---|
791 | 'bad xya file did not raise error!') |
---|
792 | os.remove(fileName) |
---|
793 | |
---|
794 | def test_loadxy_bad4(self): |
---|
795 | """ |
---|
796 | specifying wrong delimiter |
---|
797 | """ |
---|
798 | import os |
---|
799 | import tempfile |
---|
800 | |
---|
801 | fileName = tempfile.mktemp(".xya") |
---|
802 | file = open(fileName,"w") |
---|
803 | file.write(" elevation speed \n\ |
---|
804 | 1.0 0.0 10.0 0.0\n\ |
---|
805 | 0.0 1.0 0.0 10.0\n\ |
---|
806 | 1.0 0.0 10.4 40.0\n\ |
---|
807 | yeah") |
---|
808 | file.close() |
---|
809 | try: |
---|
810 | dict = import_points_file(fileName,delimiter = ' ') |
---|
811 | except IOError: |
---|
812 | pass |
---|
813 | else: |
---|
814 | self.failUnless(0 ==1, |
---|
815 | 'bad xya file did not raise error!') |
---|
816 | os.remove(fileName) |
---|
817 | |
---|
818 | def test_loadxy_bad4(self): |
---|
819 | """ |
---|
820 | specifying wrong delimiter |
---|
821 | """ |
---|
822 | import os |
---|
823 | import tempfile |
---|
824 | |
---|
825 | fileName = tempfile.mktemp(".xya") |
---|
826 | file = open(fileName,"w") |
---|
827 | file.write(" elevation speed \n\ |
---|
828 | 1.0 0.0 10.0 0.0\n\ |
---|
829 | 0.0 1.0 0.0 10.0\n\ |
---|
830 | 1.0 0.0 10.4 40.0\n\ |
---|
831 | #geocrap") |
---|
832 | file.close() |
---|
833 | try: |
---|
834 | dict = import_points_file(fileName,delimiter = ' ') |
---|
835 | except IOError: |
---|
836 | pass |
---|
837 | else: |
---|
838 | self.failUnless(0 ==1, |
---|
839 | 'bad xya file did not raise error!') |
---|
840 | os.remove(fileName) |
---|
841 | |
---|
842 | def test_loadxy_bad5(self): |
---|
843 | """ |
---|
844 | specifying wrong delimiter |
---|
845 | """ |
---|
846 | import os |
---|
847 | import tempfile |
---|
848 | |
---|
849 | fileName = tempfile.mktemp(".xya") |
---|
850 | file = open(fileName,"w") |
---|
851 | file.write(" elevation speed \n\ |
---|
852 | 1.0 0.0 10.0 0.0\n\ |
---|
853 | 0.0 1.0 0.0 10.0\n\ |
---|
854 | 1.0 0.0 10.4 40.0\n\ |
---|
855 | #geocrap\n\ |
---|
856 | crap") |
---|
857 | file.close() |
---|
858 | try: |
---|
859 | dict = import_points_file(fileName,delimiter = ' ') |
---|
860 | except IOError: |
---|
861 | pass |
---|
862 | else: |
---|
863 | self.failUnless(0 ==1, |
---|
864 | 'bad xya file did not raise error!') |
---|
865 | os.remove(fileName) |
---|
866 | ############### .PTS ########## |
---|
867 | |
---|
868 | def test_loadpts(self): |
---|
869 | |
---|
870 | from Scientific.IO.NetCDF import NetCDFFile |
---|
871 | |
---|
872 | fileName = tempfile.mktemp(".pts") |
---|
873 | # NetCDF file definition |
---|
874 | outfile = NetCDFFile(fileName, 'w') |
---|
875 | |
---|
876 | # dimension definitions |
---|
877 | outfile.createDimension('number_of_points', 3) |
---|
878 | outfile.createDimension('number_of_dimensions', 2) #This is 2d data |
---|
879 | |
---|
880 | # variable definitions |
---|
881 | outfile.createVariable('points', Float, ('number_of_points', |
---|
882 | 'number_of_dimensions')) |
---|
883 | outfile.createVariable('elevation', Float, ('number_of_points',)) |
---|
884 | |
---|
885 | # Get handles to the variables |
---|
886 | points = outfile.variables['points'] |
---|
887 | elevation = outfile.variables['elevation'] |
---|
888 | |
---|
889 | points[0, :] = [1.0,0.0] |
---|
890 | elevation[0] = 10.0 |
---|
891 | points[1, :] = [0.0,1.0] |
---|
892 | elevation[1] = 0.0 |
---|
893 | points[2, :] = [1.0,0.0] |
---|
894 | elevation[2] = 10.4 |
---|
895 | |
---|
896 | outfile.close() |
---|
897 | |
---|
898 | dict = import_points_file(fileName) |
---|
899 | os.remove(fileName) |
---|
900 | answer = [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]] |
---|
901 | #print "dict['pointlist']",dict['pointlist'] |
---|
902 | #print "answer",answer |
---|
903 | assert allclose(dict['pointlist'], [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
904 | assert allclose(dict['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
905 | |
---|
906 | def test_writepts(self): |
---|
907 | dict = {} |
---|
908 | att_dict = {} |
---|
909 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
910 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
911 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
912 | dict['attributelist'] = att_dict |
---|
913 | dict['geo_reference'] = Geo_reference(56,1.9,1.9) |
---|
914 | |
---|
915 | |
---|
916 | fileName = tempfile.mktemp(".pts") |
---|
917 | export_points_file(fileName, dict) |
---|
918 | dict2 = import_points_file(fileName) |
---|
919 | #print "fileName",fileName |
---|
920 | os.remove(fileName) |
---|
921 | #print "dict2",dict2 |
---|
922 | |
---|
923 | assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
924 | assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4]) |
---|
925 | answer = [10.0, 0.0, 10.4] |
---|
926 | assert allclose(dict2['attributelist']['brightness'], answer) |
---|
927 | |
---|
928 | #print "dict['geo_reference'] ",dict['geo_reference'] |
---|
929 | #print "dict2['geo_reference']",dict2['geo_reference'] |
---|
930 | |
---|
931 | self.failUnless(dict['geo_reference'] == dict2['geo_reference'], |
---|
932 | 'test_writepts failed. Test geo_reference') |
---|
933 | |
---|
934 | ########################## BAD .PTS ########################## |
---|
935 | |
---|
936 | def test_load_bad_no_file_pts(self): |
---|
937 | import os |
---|
938 | import tempfile |
---|
939 | |
---|
940 | fileName = tempfile.mktemp(".pts") |
---|
941 | #print fileName |
---|
942 | try: |
---|
943 | dict = import_points_file(fileName) |
---|
944 | except IOError: |
---|
945 | pass |
---|
946 | else: |
---|
947 | self.failUnless(0 ==1, |
---|
948 | 'imaginary file did not raise error!') |
---|
949 | |
---|
950 | ############### .PTS OTHER ########## |
---|
951 | |
---|
952 | def test_concatinate_attributelist(self): |
---|
953 | dic = {} |
---|
954 | dic['one'] = array([1,2]) |
---|
955 | dic['2'] = array([2,7]) |
---|
956 | dic['three'] = array([3,79]) |
---|
957 | dic['4'] = array([4,47]) |
---|
958 | dic['five'] = array([5,17]) |
---|
959 | titles, block = concatinate_attributelist(dic) |
---|
960 | #print "titles", titles |
---|
961 | #print "array", block |
---|
962 | self.failUnless(titles == ['4', '2', 'five', 'three', 'one'], |
---|
963 | 'test_concatinate_attributelist failed.') |
---|
964 | assert allclose(block, [[4,2,5,3,1],[47,7,17,79,2]]) |
---|
965 | |
---|
966 | def test_half_pts(self): |
---|
967 | dict = {} |
---|
968 | att_dict = {} |
---|
969 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
970 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
971 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
972 | dict['attributelist'] = att_dict |
---|
973 | out_dict = half_pts(dict) |
---|
974 | assert allclose(out_dict['pointlist'],[[1.0, 0.0],[1.0, 0.0]]) |
---|
975 | assert allclose(out_dict['attributelist']['elevation'], [10.0, 10.4]) |
---|
976 | assert allclose(out_dict['attributelist']['brightness'], [10.0, 10.4]) |
---|
977 | |
---|
978 | def test_extent_point_atts(self): |
---|
979 | |
---|
980 | dict = {} |
---|
981 | att_dict = {} |
---|
982 | dict['pointlist'] = array([[1.0, 10.0],[0.0, 1.0],[10.0, -10.0]]) |
---|
983 | att_dict['elevation'] = array([30.0, 0.0, 10.4]) |
---|
984 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
985 | dict['attributelist'] = att_dict |
---|
986 | out_dict = extent_point_atts(dict) |
---|
987 | |
---|
988 | #print "out_dict['pointlist']",out_dict #['pointlist'] |
---|
989 | assert allclose(out_dict['pointlist'],[[0.0, -10.0],[10.0, -10.0], |
---|
990 | [10.0,10.0],[0.0, 10.0]]) |
---|
991 | |
---|
992 | self.failUnless(dict['attributelist'] == {}, |
---|
993 | 'test_extent_point_atts failed. Test 1') |
---|
994 | |
---|
995 | def test_reduce_pts(self): |
---|
996 | dict = {} |
---|
997 | att_dict = {} |
---|
998 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
999 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
1000 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
1001 | dict['attributelist'] = att_dict |
---|
1002 | |
---|
1003 | inFileName = tempfile.mktemp(".pts") |
---|
1004 | export_points_file(inFileName, dict) |
---|
1005 | |
---|
1006 | outFileName = tempfile.mktemp(".pts") |
---|
1007 | |
---|
1008 | dict2 = reduce_pts(inFileName,outFileName, 1 ) |
---|
1009 | os.remove(inFileName) |
---|
1010 | |
---|
1011 | dict2 = import_points_file(outFileName) |
---|
1012 | os.remove(outFileName) |
---|
1013 | #print "dict2",dict2 |
---|
1014 | |
---|
1015 | assert allclose(dict2['pointlist'],[[1.0, 0.0]]) |
---|
1016 | assert allclose(dict2['attributelist']['elevation'], [10.0]) |
---|
1017 | assert allclose(dict2['attributelist']['brightness'], [10.0]) |
---|
1018 | |
---|
1019 | def test_produce_half_point_files(self): |
---|
1020 | dict = {} |
---|
1021 | att_dict = {} |
---|
1022 | dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) |
---|
1023 | att_dict['elevation'] = array([10.0, 0.0, 10.4]) |
---|
1024 | att_dict['brightness'] = array([10.0, 0.0, 10.4]) |
---|
1025 | dict['attributelist'] = att_dict |
---|
1026 | |
---|
1027 | inFileName = tempfile.mktemp(".pts") |
---|
1028 | export_points_file(inFileName, dict) |
---|
1029 | |
---|
1030 | outFileName = tempfile.mktemp(".pts") |
---|
1031 | delimiter = '_p' |
---|
1032 | outfiles = produce_half_point_files(inFileName, 1, |
---|
1033 | delimiter, verbose = False ) |
---|
1034 | os.remove(inFileName) |
---|
1035 | root, ext = splitext(inFileName) |
---|
1036 | outFileName = root + delimiter + ext |
---|
1037 | #print "outFileName",outfiles |
---|
1038 | dict2 = import_points_file(outfiles[1]) |
---|
1039 | for file in outfiles: |
---|
1040 | #print "del file",file |
---|
1041 | os.remove(file) |
---|
1042 | |
---|
1043 | assert allclose(dict2['pointlist'],[[1.0, 0.0]]) |
---|
1044 | assert allclose(dict2['attributelist']['elevation'], [10.0]) |
---|
1045 | assert allclose(dict2['attributelist']['brightness'], [10.0]) |
---|
1046 | |
---|
1047 | #------------------------------------------------------------- |
---|
1048 | if __name__ == "__main__": |
---|
1049 | |
---|
1050 | suite = unittest.makeSuite(loadASCIITestCase,'test') |
---|
1051 | #suite = unittest.makeSuite(loadASCIITestCase,'test_writepts') |
---|
1052 | runner = unittest.TextTestRunner(verbosity=0) |
---|
1053 | runner.run(suite) |
---|
1054 | |
---|