Changeset 5915
- Timestamp:
- Nov 6, 2008, 5:04:54 PM (16 years ago)
- Location:
- anuga_core/source_numpy_conversion/anuga/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source_numpy_conversion/anuga/geospatial_data/geospatial_data.py
r5739 r5915 8 8 from warnings import warn 9 9 from string import lower 10 from Numeric import concatenate, array, Float, shape, reshape, ravel, take, \ 11 size, shape 10 import numpy 11 import numpy.random 12 12 #from Array import tolist 13 from RandomArray import randint, seed, get_seed14 13 from copy import deepcopy 15 14 16 #from MA import tolist17 15 18 16 from Scientific.IO.NetCDF import NetCDFFile … … 460 458 461 459 462 new_points = concatenate((self.get_data_points(absolute=True),460 new_points = numpy.concatenate((self.get_data_points(absolute=True), 463 461 other.get_data_points(absolute=True)), 464 462 axis = 0) … … 481 479 attrib1 = self.attributes[x] 482 480 attrib2 = other.attributes[x] 483 new_attributes[x] = concatenate((attrib1, attrib2))481 new_attributes[x] = numpy.concatenate((attrib1, attrib2)) 484 482 485 483 else: … … 641 639 if attributes is not None: 642 640 for key, att in attributes.items(): 643 sampled_attributes[key] = take(att, indices)641 sampled_attributes[key] = numpy.take(att, indices) 644 642 645 643 # print 'goodbye from get_sample' … … 677 675 if verbose: print "make unique random number list and get indices" 678 676 679 total= array(range(self_size))677 total=numpy.array(range(self_size)) 680 678 total_list = total.tolist() 681 679 if verbose: print "total list len",len(total_list) … … 691 689 # plus recalcule seed when no seed provided. 692 690 if seed_num != None: 693 seed(seed_num,seed_num)691 numpy.random.seed(seed_num,seed_num) 694 692 else: 695 seed()696 if verbose: print "seed:", get_seed()693 numpy.random.seed() 694 if verbose: print "seed:", numpy.random.get_seed() 697 695 698 696 #print 'size',self_size, new_size 699 random_num = randint(0,self_size-1,(int(new_size),))697 random_num = numpy.randint(0,self_size-1,(int(new_size),)) 700 698 #print 'random num',random_num 701 699 random_num = random_num.tolist() … … 925 923 raise ValueError, msg 926 924 lats_longs = ensure_numeric(data_points) 927 latitudes = ravel(lats_longs[:,0:1])928 longitudes = ravel(lats_longs[:,1:])925 latitudes = numpy.ravel(lats_longs[:,0:1]) 926 longitudes = numpy.ravel(lats_longs[:,1:]) 929 927 930 928 if latitudes is None and longitudes is None: … … 966 964 fid = NetCDFFile(file_name, 'r') 967 965 968 pointlist = array(fid.variables['points'])966 pointlist = numpy.array(fid.variables['points']) 969 967 keys = fid.variables.keys() 970 968 if verbose: print 'Got %d variables: %s' %(len(keys), keys) … … 980 978 if verbose: print "reading attribute '%s'" %key 981 979 982 attributes[key] = array(fid.variables[key])980 attributes[key] = numpy.array(fid.variables[key]) 983 981 984 982 … … 1086 1084 1087 1085 1088 pointlist = array(points).astype(Float)1086 pointlist = numpy.array(points).astype(numpy.float) 1089 1087 for key in att_dict.keys(): 1090 att_dict[key] = array(att_dict[key]).astype(Float)1088 att_dict[key] = numpy.array(att_dict[key]).astype(numpy.float) 1091 1089 1092 1090 # Do stuff here so the info is in lat's and longs … … 1097 1095 (y_header == 'lon' or y_header == 'lat'): 1098 1096 if x_header == 'lon': 1099 longitudes = ravel(pointlist[:,0:1])1100 latitudes = ravel(pointlist[:,1:])1097 longitudes = numpy.ravel(pointlist[:,0:1]) 1098 latitudes = numpy.ravel(pointlist[:,1:]) 1101 1099 else: 1102 latitudes = ravel(pointlist[:,0:1])1103 longitudes = ravel(pointlist[:,1:])1100 latitudes = numpy.ravel(pointlist[:,0:1]) 1101 longitudes = numpy.ravel(pointlist[:,1:]) 1104 1102 1105 1103 pointlist, geo_ref = _set_using_lat_long(latitudes, … … 1140 1138 """ 1141 1139 1142 pointlist = array(fid.variables['points'][start_row:fin_row])1140 pointlist = numpy.array(fid.variables['points'][start_row:fin_row]) 1143 1141 1144 1142 attributes = {} 1145 1143 for key in keys: 1146 attributes[key] = array(fid.variables[key][start_row:fin_row])1144 attributes[key] = numpy.array(fid.variables[key][start_row:fin_row]) 1147 1145 1148 1146 return pointlist, attributes … … 1184 1182 1185 1183 # Variable definition 1186 outfile.createVariable('points', Float, ('number_of_points',1184 outfile.createVariable('points', numpy.float, ('number_of_points', 1187 1185 'number_of_dimensions')) 1188 1186 … … 1192 1190 if write_attributes is not None: 1193 1191 for key in write_attributes.keys(): 1194 outfile.createVariable(key, Float, ('number_of_points',))1192 outfile.createVariable(key, numpy.float, ('number_of_points',)) 1195 1193 outfile.variables[key][:] = write_attributes[key] #.astype(Float32) 1196 1194 … … 1258 1256 1259 1257 def _point_atts2array(point_atts): 1260 point_atts['pointlist'] = array(point_atts['pointlist']).astype(Float)1258 point_atts['pointlist'] = numpy.array(point_atts['pointlist']).astype(numpy.float) 1261 1259 1262 1260 for key in point_atts['attributelist'].keys(): 1263 1261 point_atts['attributelist'][key]=\ 1264 array(point_atts['attributelist'][key]).astype(Float)1262 numpy.array(point_atts['attributelist'][key]).astype(numpy.float) 1265 1263 return point_atts 1266 1264 … … 1350 1348 assert geo_reference == None, msg 1351 1349 else: 1352 points = ensure_numeric(points, Float)1350 points = ensure_numeric(points, numpy.float) 1353 1351 1354 1352 # Sort of geo_reference and convert points … … 1390 1388 else: 1391 1389 # List or numeric array of absolute points 1392 points = ensure_numeric(points, Float)1390 points = ensure_numeric(points, numpy.float) 1393 1391 1394 1392 # Sort out geo reference … … 1474 1472 1475 1473 from anuga.utilities.numerical_tools import cov 1476 from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin1474 ## from numpy.oldnumeric import array, resize,shape,Float,zeros,take,argsort,argmin 1477 1475 from anuga.utilities.polygon import is_inside_polygon 1478 1476 from anuga.fit_interpolate.benchmark_least_squares import mem_usage … … 1537 1535 #4 onwards is the elevation_predicted using the alpha, which will 1538 1536 #be compared later against the real removed data 1539 data= array([],typecode=Float)1540 1541 data= resize(data,(len(points),3+len(alphas)))1537 data=numpy.array([],typecode=numpy.float) 1538 1539 data=numpy.resize(data,(len(points),3+len(alphas))) 1542 1540 1543 1541 #gets relative point from sample … … 1547 1545 data[:,2]=elevation_sample 1548 1546 1549 normal_cov= array(zeros([len(alphas),2]),typecode=Float)1547 normal_cov=numpy.array(numpy.zeros([len(alphas),2]),typecode=numpy.float) 1550 1548 1551 1549 if verbose: print 'Setup computational domains with different alphas' … … 1587 1585 1588 1586 normal_cov0=normal_cov[:,0] 1589 normal_cov_new= take(normal_cov,argsort(normal_cov0))1587 normal_cov_new=numpy.take(normal_cov,numpy.argsort(normal_cov0)) 1590 1588 1591 1589 if plot_name is not None: … … 1601 1599 for i,alpha in enumerate(alphas): 1602 1600 print'covariance for alpha %s = %s ' %(normal_cov[i][0],normal_cov[i][1]) 1603 print '\n Optimal alpha is: %s ' % normal_cov_new[( argmin(normal_cov_new,axis=0))[1],0]1601 print '\n Optimal alpha is: %s ' % normal_cov_new[(numpy.argmin(normal_cov_new,axis=0))[1],0] 1604 1602 1605 1603 # covariance and optimal alpha 1606 return min(normal_cov_new[:,1]) , normal_cov_new[( argmin(normal_cov_new,axis=0))[1],0]1604 return min(normal_cov_new[:,1]) , normal_cov_new[(numpy.argmin(normal_cov_new,axis=0))[1],0] 1607 1605 1608 1606 def old_find_optimal_smoothing_parameter(data_file, … … 1666 1664 1667 1665 from anuga.utilities.numerical_tools import cov 1668 from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin1666 ## from numpy.oldnumeric import array, resize,shape,Float,zeros,take,argsort,argmin 1669 1667 from anuga.utilities.polygon import is_inside_polygon 1670 1668 from anuga.fit_interpolate.benchmark_least_squares import mem_usage … … 1759 1757 #4 onwards is the elevation_predicted using the alpha, which will 1760 1758 #be compared later against the real removed data 1761 data= array([],typecode=Float)1762 1763 data= resize(data,(len(points),3+len(alphas)))1759 data=numpy.array([],typecode=numpy.float) 1760 1761 data=numpy.resize(data,(len(points),3+len(alphas))) 1764 1762 1765 1763 #gets relative point from sample … … 1769 1767 data[:,2]=elevation_sample 1770 1768 1771 normal_cov= array(zeros([len(alphas),2]),typecode=Float)1769 normal_cov=numpy.array(numpy.zeros([len(alphas),2]),typecode=numpy.float) 1772 1770 1773 1771 if verbose: print 'Determine difference between predicted results and actual data' … … 1794 1792 1795 1793 normal_cov0=normal_cov[:,0] 1796 normal_cov_new= take(normal_cov,argsort(normal_cov0))1794 normal_cov_new=numpy.take(normal_cov,numpy.argsort(normal_cov0)) 1797 1795 1798 1796 if plot_name is not None: … … 1804 1802 remove(mesh_file) 1805 1803 1806 return min(normal_cov_new[:,1]) , normal_cov_new[( argmin(normal_cov_new,axis=0))[1],0]1804 return min(normal_cov_new[:,1]) , normal_cov_new[(numpy.argmin(normal_cov_new,axis=0))[1],0] 1807 1805 1808 1806 -
anuga_core/source_numpy_conversion/anuga/geospatial_data/test_geospatial_data.py
r5730 r5915 4 4 import unittest 5 5 import os 6 from Numeric import zeros, array, allclose, concatenate,sort 6 import numpy 7 import numpy.random 7 8 from math import sqrt, pi 8 9 import tempfile … … 30 31 G = Geospatial_data(points) 31 32 32 assert allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]])33 assert numpy.allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]]) 33 34 34 35 # Check __repr__ … … 41 42 42 43 #Check getter 43 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]])44 assert numpy.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]]) 44 45 45 46 #Check defaults … … 56 57 G = Geospatial_data(points, attributes) 57 58 assert G.attributes.keys()[0] == DEFAULT_ATTRIBUTE 58 assert allclose(G.attributes.values()[0], [2, 4])59 assert numpy.allclose(G.attributes.values()[0], [2, 4]) 59 60 60 61 … … 80 81 81 82 P = G.get_data_points(absolute=False) 82 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])83 assert numpy.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 83 84 84 85 P = G.get_data_points(absolute=True) 85 assert allclose(P, [[101.0, 202.1], [103.0, 205.3]])86 assert numpy.allclose(P, [[101.0, 202.1], [103.0, 205.3]]) 86 87 87 88 V = G.get_attributes() #Simply get them 88 assert allclose(V, [2, 4])89 assert numpy.allclose(V, [2, 4]) 89 90 90 91 V = G.get_attributes(DEFAULT_ATTRIBUTE) #Get by name 91 assert allclose(V, [2, 4])92 assert numpy.allclose(V, [2, 4]) 92 93 93 94 def test_get_attributes_2(self): … … 104 105 105 106 P = G.get_data_points(absolute=False) 106 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])107 assert numpy.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 107 108 108 109 V = G.get_attributes() #Get default attribute 109 assert allclose(V, [2, 4])110 assert numpy.allclose(V, [2, 4]) 110 111 111 112 V = G.get_attributes('a0') #Get by name 112 assert allclose(V, [0, 0])113 assert numpy.allclose(V, [0, 0]) 113 114 114 115 V = G.get_attributes('a1') #Get by name 115 assert allclose(V, [2, 4])116 assert numpy.allclose(V, [2, 4]) 116 117 117 118 V = G.get_attributes('a2') #Get by name 118 assert allclose(V, [79.4, -7])119 assert numpy.allclose(V, [79.4, -7]) 119 120 120 121 try: … … 136 137 results = spatial.get_data_points(absolute=False) 137 138 138 assert allclose(results, points_rel)139 assert numpy.allclose(results, points_rel) 139 140 140 141 x_p = -1770 … … 145 146 ( geo_reference=geo_ref) 146 147 147 assert allclose(results, points_rel)148 assert numpy.allclose(results, points_rel) 148 149 149 150 … … 164 165 #print "test_get_data_points_lat_long - results", results 165 166 #print "points_Lat_long",points_Lat_long 166 assert allclose(results, points_Lat_long)167 assert numpy.allclose(results, points_Lat_long) 167 168 168 169 def test_get_data_points_lat_longII(self): … … 178 179 #print "seg_lat_long", seg_lat_long [0][0] 179 180 #print "lat_result",lat_result 180 assert allclose(seg_lat_long[0][0], lat_result)#lat181 assert allclose(seg_lat_long[0][1], long_result)#long181 assert numpy.allclose(seg_lat_long[0][0], lat_result)#lat 182 assert numpy.allclose(seg_lat_long[0][1], long_result)#long 182 183 183 184 … … 199 200 #print "seg_lat_long", seg_lat_long [0] 200 201 #print "lat_result",lat_result 201 assert allclose(seg_lat_long[0][0], lat_result)#lat202 assert allclose(seg_lat_long[0][1], long_result)#long202 assert numpy.allclose(seg_lat_long[0][0], lat_result)#lat 203 assert numpy.allclose(seg_lat_long[0][1], long_result)#long 203 204 204 205 … … 219 220 # Create without geo_ref properly set 220 221 G = Geospatial_data(points_rel) 221 assert not allclose(points_ab, G.get_data_points(absolute=True))222 assert not numpy.allclose(points_ab, G.get_data_points(absolute=True)) 222 223 223 224 # Create the way it should be 224 225 G = Geospatial_data(points_rel, geo_reference=geo_ref) 225 assert allclose(points_ab, G.get_data_points(absolute=True))226 assert numpy.allclose(points_ab, G.get_data_points(absolute=True)) 226 227 227 228 # Change georeference and check that absolute values are unchanged. … … 230 231 new_geo_ref = Geo_reference(56, x_p, y_p) 231 232 G.set_geo_reference(new_geo_ref) 232 assert allclose(points_ab, G.get_data_points(absolute=True))233 assert numpy.allclose(points_ab, G.get_data_points(absolute=True)) 233 234 234 235 … … 253 254 assert points_dict.has_key('geo_reference') 254 255 255 assert allclose( points_dict['pointlist'], points )256 assert numpy.allclose( points_dict['pointlist'], points ) 256 257 257 258 A = points_dict['attributelist'] … … 260 261 assert A.has_key('a2') 261 262 262 assert allclose( A['a0'], [0, 0] )263 assert allclose( A['a1'], [2, 4] )264 assert allclose( A['a2'], [79.4, -7] )263 assert numpy.allclose( A['a0'], [0, 0] ) 264 assert numpy.allclose( A['a1'], [2, 4] ) 265 assert numpy.allclose( A['a2'], [79.4, -7] ) 265 266 266 267 … … 287 288 288 289 P = G.get_data_points(absolute=False) 289 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])290 assert numpy.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 290 291 291 292 #V = G.get_attribute_values() #Get default attribute … … 293 294 294 295 V = G.get_attributes('a0') #Get by name 295 assert allclose(V, [0, 0])296 assert numpy.allclose(V, [0, 0]) 296 297 297 298 V = G.get_attributes('a1') #Get by name 298 assert allclose(V, [2, 4])299 assert numpy.allclose(V, [2, 4]) 299 300 300 301 V = G.get_attributes('a2') #Get by name 301 assert allclose(V, [79.4, -7])302 assert numpy.allclose(V, [79.4, -7]) 302 303 303 304 def test_add(self): … … 318 319 assert G.attributes.has_key('depth') 319 320 assert G.attributes.has_key('elevation') 320 assert allclose(G.attributes['depth'], [2, 4, 2, 4])321 assert allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1])322 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],321 assert numpy.allclose(G.attributes['depth'], [2, 4, 2, 4]) 322 assert numpy.allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1]) 323 assert numpy.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3], 323 324 [1.0, 2.1], [3.0, 5.3]]) 324 325 … … 342 343 assert G.attributes.has_key('depth') 343 344 assert G.attributes.keys(), ['depth'] 344 assert allclose(G.attributes['depth'], [2, 4, 200, 400])345 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],345 assert numpy.allclose(G.attributes['depth'], [2, 4, 200, 400]) 346 assert numpy.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3], 346 347 [5.0, 2.1], [3.0, 50.3]]) 347 348 def test_add_with_geo (self): … … 366 367 #Check that absolute values are as expected 367 368 P1 = G1.get_data_points(absolute=True) 368 assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]])369 assert numpy.allclose(P1, [[2.0, 4.1], [4.0, 7.3]]) 369 370 370 371 P2 = G2.get_data_points(absolute=True) 371 assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]])372 assert numpy.allclose(P2, [[5.1, 9.1], [6.1, 6.3]]) 372 373 373 374 G = G1 + G2 374 375 375 376 # Check absoluteness 376 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)377 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)377 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 378 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 378 379 379 380 P = G.get_data_points(absolute=True) … … 383 384 #assert allclose(P_relative, P - [0.1, 2.0]) 384 385 385 assert allclose(P,concatenate( (P1,P2) ))386 assert allclose(P, [[2.0, 4.1], [4.0, 7.3],386 assert numpy.allclose(P, numpy.concatenate( (P1,P2) )) 387 assert numpy.allclose(P, [[2.0, 4.1], [4.0, 7.3], 387 388 [5.1, 9.1], [6.1, 6.3]]) 388 389 … … 395 396 Difference in Geo_reference resolved 396 397 """ 397 points1 = array([[2.0, 4.1], [4.0, 7.3]])398 points2 = array([[5.1, 9.1], [6.1, 6.3]])398 points1 = numpy.array([[2.0, 4.1], [4.0, 7.3]]) 399 points2 = numpy.array([[5.1, 9.1], [6.1, 6.3]]) 399 400 attributes1 = [2, 4] 400 401 attributes2 = [5, 76] … … 412 413 #Check that absolute values are as expected 413 414 P1 = G1.get_data_points(absolute=True) 414 assert allclose(P1, points1)415 assert numpy.allclose(P1, points1) 415 416 416 417 P1 = G1.get_data_points(absolute=False) 417 assert allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()])418 assert numpy.allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()]) 418 419 419 420 P2 = G2.get_data_points(absolute=True) 420 assert allclose(P2, points2)421 assert numpy.allclose(P2, points2) 421 422 422 423 P2 = G2.get_data_points(absolute=False) 423 assert allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()])424 assert numpy.allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()]) 424 425 425 426 G = G1 + G2 … … 434 435 #assert allclose(P_relative, [[1.0, 2.1], [3.0, 5.3], [4.1, 7.1], [5.1, 4.3]]) 435 436 436 assert allclose(P,concatenate( (points1,points2) ))437 assert numpy.allclose(P, numpy.concatenate( (points1,points2) )) 437 438 438 439 … … 441 442 """ 442 443 443 points1 = array([[2.0, 4.1], [4.0, 7.3]])444 points2 = array([[5.1, 9.1], [6.1, 6.3]])444 points1 = numpy.array([[2.0, 4.1], [4.0, 7.3]]) 445 points2 = numpy.array([[5.1, 9.1], [6.1, 6.3]]) 445 446 446 447 geo_ref1= Geo_reference(55, 1.0, 2.0) … … 458 459 459 460 G1 = Geospatial_data(points1, attributes1, geo_ref1) 460 assert allclose(G1.get_geo_reference().get_xllcorner(), 1.0)461 assert allclose(G1.get_geo_reference().get_yllcorner(), 2.0)461 assert numpy.allclose(G1.get_geo_reference().get_xllcorner(), 1.0) 462 assert numpy.allclose(G1.get_geo_reference().get_yllcorner(), 2.0) 462 463 assert G1.attributes.has_key('depth') 463 464 assert G1.attributes.has_key('elevation') 464 assert allclose(G1.attributes['depth'], [2, 4.7])465 assert allclose(G1.attributes['elevation'], [6.1, 5])465 assert numpy.allclose(G1.attributes['depth'], [2, 4.7]) 466 assert numpy.allclose(G1.attributes['elevation'], [6.1, 5]) 466 467 467 468 G2 = Geospatial_data(points2, attributes2, geo_ref2) 468 assert allclose(G2.get_geo_reference().get_xllcorner(), 0.1)469 assert allclose(G2.get_geo_reference().get_yllcorner(), 3.0)469 assert numpy.allclose(G2.get_geo_reference().get_xllcorner(), 0.1) 470 assert numpy.allclose(G2.get_geo_reference().get_yllcorner(), 3.0) 470 471 assert G2.attributes.has_key('depth') 471 472 assert G2.attributes.has_key('elevation') 472 assert allclose(G2.attributes['depth'], [-2.3, 4])473 assert allclose(G2.attributes['elevation'], [2.5, 1])473 assert numpy.allclose(G2.attributes['depth'], [-2.3, 4]) 474 assert numpy.allclose(G2.attributes['elevation'], [2.5, 1]) 474 475 475 476 #Check that absolute values are as expected 476 477 P1 = G1.get_data_points(absolute=True) 477 assert allclose(P1, [[3.0, 6.1], [5.0, 9.3]])478 assert numpy.allclose(P1, [[3.0, 6.1], [5.0, 9.3]]) 478 479 479 480 P2 = G2.get_data_points(absolute=True) 480 assert allclose(P2, [[5.2, 12.1], [6.2, 9.3]])481 assert numpy.allclose(P2, [[5.2, 12.1], [6.2, 9.3]]) 481 482 482 483 # Normal add … … 485 486 assert G.attributes.has_key('depth') 486 487 assert G.attributes.has_key('elevation') 487 assert allclose(G.attributes['depth'], [2, 4.7])488 assert allclose(G.attributes['elevation'], [6.1, 5])488 assert numpy.allclose(G.attributes['depth'], [2, 4.7]) 489 assert numpy.allclose(G.attributes['elevation'], [6.1, 5]) 489 490 490 491 # Points are now absolute. 491 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)492 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)492 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 493 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 493 494 P = G.get_data_points(absolute=True) 494 assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])495 assert numpy.allclose(P, [[3.0, 6.1], [5.0, 9.3]]) 495 496 496 497 … … 498 499 assert G.attributes.has_key('depth') 499 500 assert G.attributes.has_key('elevation') 500 assert allclose(G.attributes['depth'], [-2.3, 4])501 assert allclose(G.attributes['elevation'], [2.5, 1])502 503 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)504 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)501 assert numpy.allclose(G.attributes['depth'], [-2.3, 4]) 502 assert numpy.allclose(G.attributes['elevation'], [2.5, 1]) 503 504 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 505 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 505 506 P = G.get_data_points(absolute=True) 506 assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])507 assert numpy.allclose(P, [[5.2, 12.1], [6.2, 9.3]]) 507 508 508 509 … … 513 514 assert G.attributes.has_key('depth') 514 515 assert G.attributes.has_key('elevation') 515 assert allclose(G.attributes['depth'], [2, 4.7])516 assert allclose(G.attributes['elevation'], [6.1, 5])516 assert numpy.allclose(G.attributes['depth'], [2, 4.7]) 517 assert numpy.allclose(G.attributes['elevation'], [6.1, 5]) 517 518 518 519 # Points are now absolute. 519 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)520 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)520 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 521 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 521 522 P = G.get_data_points(absolute=True) 522 assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])523 assert numpy.allclose(P, [[3.0, 6.1], [5.0, 9.3]]) 523 524 524 525 … … 526 527 assert G.attributes.has_key('depth') 527 528 assert G.attributes.has_key('elevation') 528 assert allclose(G.attributes['depth'], [-2.3, 4])529 assert allclose(G.attributes['elevation'], [2.5, 1])530 531 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)532 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)529 assert numpy.allclose(G.attributes['depth'], [-2.3, 4]) 530 assert numpy.allclose(G.attributes['elevation'], [2.5, 1]) 531 532 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 533 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 533 534 P = G.get_data_points(absolute=True) 534 assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])535 assert numpy.allclose(P, [[5.2, 12.1], [6.2, 9.3]]) 535 536 536 537 … … 553 554 # First try the unit square 554 555 U = [[0,0], [1,0], [1,1], [0,1]] 555 assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])556 assert numpy.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 556 557 557 558 # Then a more complex polygon … … 560 561 G = Geospatial_data(points) 561 562 562 assert allclose(G.clip(polygon).get_data_points(),563 assert numpy.allclose(G.clip(polygon).get_data_points(), 563 564 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 564 565 … … 576 577 attributes = [2, -4, 5, 76, -2, 0.1, 3] 577 578 att_dict = {'att1': attributes, 578 'att2': array(attributes)+1}579 'att2': numpy.array(attributes)+1} 579 580 580 581 G = Geospatial_data(points, att_dict) … … 582 583 # First try the unit square 583 584 U = [[0,0], [1,0], [1,1], [0,1]] 584 assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])585 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])586 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])585 assert numpy.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 586 assert numpy.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 587 assert numpy.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 587 588 588 589 # Then a more complex polygon … … 594 595 G = Geospatial_data(points, attributes) 595 596 596 assert allclose(G.clip(polygon).get_data_points(),597 assert numpy.allclose(G.clip(polygon).get_data_points(), 597 598 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 598 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])599 assert numpy.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 599 600 600 601 … … 612 613 attributes = [2, -4, 5, 76, -2, 0.1, 3] 613 614 att_dict = {'att1': attributes, 614 'att2': array(attributes)+1}615 'att2': numpy.array(attributes)+1} 615 616 G = Geospatial_data(points, att_dict) 616 617 617 618 # First try the unit square 618 619 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 619 assert allclose(G.clip(U).get_data_points(),620 assert numpy.allclose(G.clip(U).get_data_points(), 620 621 [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 621 622 622 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])623 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])623 assert numpy.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 624 assert numpy.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 624 625 625 626 # Then a more complex polygon … … 630 631 631 632 632 assert allclose(G.clip(polygon).get_data_points(),633 assert numpy.allclose(G.clip(polygon).get_data_points(), 633 634 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 634 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])635 assert numpy.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 635 636 636 637 … … 650 651 # First try the unit square 651 652 U = [[0,0], [1,0], [1,1], [0,1]] 652 assert allclose(G.clip_outside(U).get_data_points(),653 assert numpy.allclose(G.clip_outside(U).get_data_points(), 653 654 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 654 655 #print G.clip_outside(U).get_attributes() 655 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])656 assert numpy.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 656 657 657 658 … … 662 663 G = Geospatial_data(points, attributes) 663 664 664 assert allclose(G.clip_outside(polygon).get_data_points(),665 assert numpy.allclose(G.clip_outside(polygon).get_data_points(), 665 666 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 666 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])667 assert numpy.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 667 668 668 669 … … 683 684 # First try the unit square 684 685 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 685 assert allclose(G.clip_outside(U).get_data_points(),686 assert numpy.allclose(G.clip_outside(U).get_data_points(), 686 687 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 687 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])688 assert numpy.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 688 689 689 690 # Then a more complex polygon … … 695 696 696 697 697 assert allclose(G.clip_outside(polygon).get_data_points(),698 assert numpy.allclose(G.clip_outside(polygon).get_data_points(), 698 699 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 699 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])700 assert numpy.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 700 701 701 702 … … 718 719 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 719 720 G1 = G.clip(U) 720 assert allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]])721 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])721 assert numpy.allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]]) 722 assert numpy.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 722 723 723 724 G2 = G.clip_outside(U) 724 assert allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1],725 assert numpy.allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1], 725 726 [3.0, 5.3], [2.4, 3.3]]) 726 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])727 assert numpy.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 727 728 728 729 … … 733 734 new_attributes = [-4, 76, 0.1, 2, 5, -2, 3] 734 735 735 assert allclose((G1+G2).get_data_points(), new_points)736 assert allclose((G1+G2).get_attributes(), new_attributes)736 assert numpy.allclose((G1+G2).get_data_points(), new_points) 737 assert numpy.allclose((G1+G2).get_attributes(), new_attributes) 737 738 738 739 G = G1+G2 … … 746 747 747 748 # Check result 748 assert allclose(G3.get_data_points(), new_points)749 assert allclose(G3.get_attributes(), new_attributes)749 assert numpy.allclose(G3.get_data_points(), new_points) 750 assert numpy.allclose(G3.get_attributes(), new_attributes) 750 751 751 752 os.remove(FN) … … 768 769 os.remove(fileName) 769 770 # print 'data', results.get_data_points() 770 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],771 assert numpy.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0], 771 772 [1.0, 0.0]]) 772 assert allclose(results.get_attributes(attribute_name='elevation'),773 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), 773 774 [10.0, 0.0, 10.4]) 774 assert allclose(results.get_attributes(attribute_name='speed'),775 assert numpy.allclose(results.get_attributes(attribute_name='speed'), 775 776 [0.0, 10.0, 40.0]) 776 777 … … 819 820 820 821 821 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])822 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])823 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])822 assert numpy.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 823 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 824 assert numpy.allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 824 825 825 826 # Blocking … … 828 829 geo_list.append(i) 829 830 830 assert allclose(geo_list[0].get_data_points(),831 assert numpy.allclose(geo_list[0].get_data_points(), 831 832 [[1.0, 0.0],[0.0, 1.0]]) 832 833 833 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),834 assert numpy.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 834 835 [10.0, 0.0]) 835 assert allclose(geo_list[1].get_data_points(),836 assert numpy.allclose(geo_list[1].get_data_points(), 836 837 [[1.0, 0.0]]) 837 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),838 assert numpy.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 838 839 [10.4]) 839 840 … … 979 980 results = Geospatial_data(pts_file, max_read_lines=2) 980 981 981 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],982 assert numpy.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0], 982 983 [1.0, 0.0]]) 983 assert allclose(results.get_attributes(attribute_name='elevation'),984 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), 984 985 [10.0, 0.0, 10.4]) 985 assert allclose(results.get_attributes(attribute_name='speed'),986 assert numpy.allclose(results.get_attributes(attribute_name='speed'), 986 987 [0.0, 10.0, 40.0]) 987 988 … … 990 991 for i in results: 991 992 geo_list.append(i) 992 assert allclose(geo_list[0].get_data_points(),993 assert numpy.allclose(geo_list[0].get_data_points(), 993 994 [[1.0, 0.0],[0.0, 1.0]]) 994 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),995 assert numpy.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 995 996 [10.0, 0.0]) 996 assert allclose(geo_list[1].get_data_points(),997 assert numpy.allclose(geo_list[1].get_data_points(), 997 998 [[1.0, 0.0]]) 998 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),999 assert numpy.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 999 1000 [10.4]) 1000 1001 … … 1068 1069 for i in results: 1069 1070 geo_list.append(i) 1070 assert allclose(geo_list[0].get_data_points(),1071 assert numpy.allclose(geo_list[0].get_data_points(), 1071 1072 [[1.0, 0.0],[0.0, 1.0]]) 1072 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),1073 assert numpy.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 1073 1074 [10.0, 0.0]) 1074 assert allclose(geo_list[1].get_data_points(),1075 assert numpy.allclose(geo_list[1].get_data_points(), 1075 1076 [[1.0, 0.0],[0.0, 1.0] ]) 1076 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),1077 assert numpy.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 1077 1078 [10.0, 0.0]) 1078 1079 … … 1084 1085 def test_new_export_pts_file(self): 1085 1086 att_dict = {} 1086 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1087 att_dict['elevation'] = array([10.1, 0.0, 10.4])1088 att_dict['brightness'] = array([10.0, 1.0, 10.4])1087 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1088 att_dict['elevation'] = numpy.array([10.1, 0.0, 10.4]) 1089 att_dict['brightness'] = numpy.array([10.0, 1.0, 10.4]) 1089 1090 1090 1091 fileName = tempfile.mktemp(".pts") … … 1098 1099 os.remove(fileName) 1099 1100 1100 assert allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1101 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])1101 assert numpy.allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1102 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 1102 1103 answer = [10.0, 1.0, 10.4] 1103 assert allclose(results.get_attributes(attribute_name='brightness'), answer)1104 assert numpy.allclose(results.get_attributes(attribute_name='brightness'), answer) 1104 1105 1105 1106 def test_new_export_absolute_pts_file(self): 1106 1107 att_dict = {} 1107 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1108 att_dict['elevation'] = array([10.1, 0.0, 10.4])1109 att_dict['brightness'] = array([10.0, 1.0, 10.4])1108 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1109 att_dict['elevation'] = numpy.array([10.1, 0.0, 10.4]) 1110 att_dict['brightness'] = numpy.array([10.0, 1.0, 10.4]) 1110 1111 geo_ref = Geo_reference(50, 25, 55) 1111 1112 … … 1120 1121 os.remove(fileName) 1121 1122 1122 assert allclose(results.get_data_points(), G.get_data_points(True))1123 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])1123 assert numpy.allclose(results.get_data_points(), G.get_data_points(True)) 1124 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 1124 1125 answer = [10.0, 1.0, 10.4] 1125 assert allclose(results.get_attributes(attribute_name='brightness'), answer)1126 assert numpy.allclose(results.get_attributes(attribute_name='brightness'), answer) 1126 1127 1127 1128 def test_loadpts(self): … … 1158 1159 os.remove(fileName) 1159 1160 answer = [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]] 1160 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1161 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])1161 assert numpy.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1162 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 1162 1163 1163 1164 def test_writepts(self): … … 1165 1166 1166 1167 att_dict = {} 1167 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1168 att_dict['elevation'] = array([10.0, 0.0, 10.4])1169 att_dict['brightness'] = array([10.0, 0.0, 10.4])1168 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1169 att_dict['elevation'] = numpy.array([10.0, 0.0, 10.4]) 1170 att_dict['brightness'] = numpy.array([10.0, 0.0, 10.4]) 1170 1171 geo_reference=Geo_reference(56,1.9,1.9) 1171 1172 … … 1177 1178 os.remove(fileName) 1178 1179 1179 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1180 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1180 assert numpy.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1181 assert numpy.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1181 1182 answer = [10.0, 0.0, 10.4] 1182 assert allclose(results.get_attributes('brightness'), answer)1183 assert numpy.allclose(results.get_attributes('brightness'), answer) 1183 1184 self.failUnless(geo_reference == geo_reference, 1184 1185 'test_writepts failed. Test geo_reference') … … 1188 1189 1189 1190 att_dict = {} 1190 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1191 att_dict['elevation'] = array([10.0, 0.0, 10.4])1192 att_dict['brightness'] = array([10.0, 0.0, 10.4])1191 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1192 att_dict['elevation'] = numpy.array([10.0, 0.0, 10.4]) 1193 att_dict['brightness'] = numpy.array([10.0, 0.0, 10.4]) 1193 1194 geo_reference=Geo_reference(56,0,0) 1194 1195 # Test txt format … … 1199 1200 results = Geospatial_data(file_name=fileName) 1200 1201 os.remove(fileName) 1201 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1202 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1202 assert numpy.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1203 assert numpy.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1203 1204 answer = [10.0, 0.0, 10.4] 1204 assert allclose(results.get_attributes('brightness'), answer)1205 assert numpy.allclose(results.get_attributes('brightness'), answer) 1205 1206 1206 1207 … … 1209 1210 1210 1211 att_dict = {} 1211 pointlist = array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]])1212 att_dict['elevation'] = array([10.0, 0.0, 10.4])1213 att_dict['brightness'] = array([10.0, 0.0, 10.4])1212 pointlist = numpy.array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]]) 1213 att_dict['elevation'] = numpy.array([10.0, 0.0, 10.4]) 1214 att_dict['brightness'] = numpy.array([10.0, 0.0, 10.4]) 1214 1215 # Test txt format 1215 1216 fileName = tempfile.mktemp(".txt") … … 1219 1220 results = Geospatial_data(file_name=fileName) 1220 1221 os.remove(fileName) 1221 assert allclose(results.get_data_points(False, as_lat_long=True),1222 assert numpy.allclose(results.get_data_points(False, as_lat_long=True), 1222 1223 pointlist) 1223 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1224 assert numpy.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1224 1225 answer = [10.0, 0.0, 10.4] 1225 assert allclose(results.get_attributes('brightness'), answer)1226 assert numpy.allclose(results.get_attributes('brightness'), answer) 1226 1227 1227 1228 def test_writepts_no_attributes(self): … … 1230 1231 1231 1232 att_dict = {} 1232 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1233 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1233 1234 geo_reference=Geo_reference(56,1.9,1.9) 1234 1235 … … 1240 1241 os.remove(fileName) 1241 1242 1242 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1243 assert numpy.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1243 1244 self.failUnless(geo_reference == geo_reference, 1244 1245 'test_writepts failed. Test geo_reference') … … 1249 1250 1250 1251 att_dict = {} 1251 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1252 pointlist = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1252 1253 geo_reference=Geo_reference(56,0,0) 1253 1254 # Test format … … 1257 1258 results = Geospatial_data(file_name=fileName) 1258 1259 os.remove(fileName) 1259 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1260 assert numpy.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1260 1261 1261 1262 … … 1314 1315 G = Geospatial_data(file_name = FN) 1315 1316 1316 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)1317 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)1318 1319 assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1320 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])1317 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 1318 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 1319 1320 assert numpy.allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1321 assert numpy.allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 1321 1322 os.remove(FN) 1322 1323 … … 1361 1362 G = Geospatial_data(file_name = FN) 1362 1363 1363 assert allclose(G.get_geo_reference().get_xllcorner(), xll)1364 assert allclose(G.get_geo_reference().get_yllcorner(), yll)1365 1366 assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],1364 assert numpy.allclose(G.get_geo_reference().get_xllcorner(), xll) 1365 assert numpy.allclose(G.get_geo_reference().get_yllcorner(), yll) 1366 1367 assert numpy.allclose(G.get_data_points(), [[1.0+xll, 0.0+yll], 1367 1368 [0.0+xll, 1.0+yll], 1368 1369 [1.0+xll, 0.0+yll]]) 1369 1370 1370 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])1371 assert numpy.allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 1371 1372 os.remove(FN) 1372 1373 … … 1379 1380 # create files 1380 1381 att_dict1 = {} 1381 pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1382 att_dict1['elevation'] = array([-10.0, 0.0, 10.4])1383 att_dict1['brightness'] = array([10.0, 0.0, 10.4])1382 pointlist1 = numpy.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1383 att_dict1['elevation'] = numpy.array([-10.0, 0.0, 10.4]) 1384 att_dict1['brightness'] = numpy.array([10.0, 0.0, 10.4]) 1384 1385 geo_reference1 = Geo_reference(56, 2.0, 1.0) 1385 1386 1386 1387 att_dict2 = {} 1387 pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])1388 att_dict2['elevation'] = array([1.0, 15.0, 1.4])1389 att_dict2['brightness'] = array([14.0, 1.0, -12.4])1388 pointlist2 = numpy.array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]]) 1389 att_dict2['elevation'] = numpy.array([1.0, 15.0, 1.4]) 1390 att_dict2['brightness'] = numpy.array([14.0, 1.0, -12.4]) 1390 1391 geo_reference2 = Geo_reference(56, 1.0, 2.0) 1391 1392 … … 1411 1412 # print'res', G.get_data_points() 1412 1413 # print'res1', G.get_data_points(False) 1413 assert allclose(G.get_data_points(),1414 assert numpy.allclose(G.get_data_points(), 1414 1415 [[ 3.0, 1.0], [ 2.0, 2.0], 1415 1416 [ 3.0, 1.0], [ 3.0, 3.0], 1416 1417 [ 2.0, 4.0], [ 3.0, 3.0]]) 1417 1418 1418 assert allclose(G.get_attributes(attribute_name='elevation'),1419 assert numpy.allclose(G.get_attributes(attribute_name='elevation'), 1419 1420 [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4]) 1420 1421 1421 1422 answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4] 1422 assert allclose(G.get_attributes(attribute_name='brightness'), answer)1423 assert numpy.allclose(G.get_attributes(attribute_name='brightness'), answer) 1423 1424 1424 1425 self.failUnless(G.get_geo_reference() == geo_reference1, … … 1434 1435 new_points = ensure_absolute(points) 1435 1436 1436 assert allclose(new_points, points)1437 1438 points = array([[2.0, 0.0],[1.0, 1.0],1437 assert numpy.allclose(new_points, points) 1438 1439 points = numpy.array([[2.0, 0.0],[1.0, 1.0], 1439 1440 [2.0, 0.0],[2.0, 2.0], 1440 1441 [1.0, 3.0],[2.0, 2.0]]) 1441 1442 new_points = ensure_absolute(points) 1442 1443 1443 assert allclose(new_points, points)1444 1445 ab_points = array([[2.0, 0.0],[1.0, 1.0],1444 assert numpy.allclose(new_points, points) 1445 1446 ab_points = numpy.array([[2.0, 0.0],[1.0, 1.0], 1446 1447 [2.0, 0.0],[2.0, 2.0], 1447 1448 [1.0, 3.0],[2.0, 2.0]]) … … 1449 1450 mesh_origin = (56, 290000, 618000) #zone, easting, northing 1450 1451 1451 data_points = zeros((ab_points.shape), Float)1452 data_points = numpy.zeros((ab_points.shape), Float) 1452 1453 #Shift datapoints according to new origins 1453 1454 for k in range(len(ab_points)): … … 1460 1461 #print "ab_points",ab_points 1461 1462 1462 assert allclose(new_points, ab_points)1463 assert numpy.allclose(new_points, ab_points) 1463 1464 1464 1465 geo = Geo_reference(56,67,-56) … … 1470 1471 #print "ab_points",ab_points 1471 1472 1472 assert allclose(new_points, ab_points)1473 assert numpy.allclose(new_points, ab_points) 1473 1474 1474 1475 … … 1485 1486 #print "ab_points",ab_points 1486 1487 1487 assert allclose(new_points, ab_points)1488 assert numpy.allclose(new_points, ab_points) 1488 1489 1489 1490 … … 1495 1496 new_points = ensure_geospatial(points) 1496 1497 1497 assert allclose(new_points.get_data_points(absolute = True), points)1498 1499 points = array([[2.0, 0.0],[1.0, 1.0],1498 assert numpy.allclose(new_points.get_data_points(absolute = True), points) 1499 1500 points = numpy.array([[2.0, 0.0],[1.0, 1.0], 1500 1501 [2.0, 0.0],[2.0, 2.0], 1501 1502 [1.0, 3.0],[2.0, 2.0]]) 1502 1503 new_points = ensure_geospatial(points) 1503 1504 1504 assert allclose(new_points.get_data_points(absolute = True), points)1505 1506 ab_points = array([[2.0, 0.0],[1.0, 1.0],1505 assert numpy.allclose(new_points.get_data_points(absolute = True), points) 1506 1507 ab_points = numpy.array([[2.0, 0.0],[1.0, 1.0], 1507 1508 [2.0, 0.0],[2.0, 2.0], 1508 1509 [1.0, 3.0],[2.0, 2.0]]) … … 1510 1511 mesh_origin = (56, 290000, 618000) #zone, easting, northing 1511 1512 1512 data_points = zeros((ab_points.shape), Float)1513 data_points = numpy.zeros((ab_points.shape), Float) 1513 1514 #Shift datapoints according to new origins 1514 1515 for k in range(len(ab_points)): … … 1522 1523 #print "ab_points",ab_points 1523 1524 1524 assert allclose(new_points, ab_points)1525 assert numpy.allclose(new_points, ab_points) 1525 1526 1526 1527 geo = Geo_reference(56,67,-56) … … 1533 1534 #print "ab_points",ab_points 1534 1535 1535 assert allclose(new_points, ab_points)1536 assert numpy.allclose(new_points, ab_points) 1536 1537 1537 1538 … … 1549 1550 #print "ab_points",ab_points 1550 1551 1551 assert allclose(new_points, ab_points)1552 assert numpy.allclose(new_points, ab_points) 1552 1553 1553 1554 def test_isinstance(self): … … 1564 1565 1565 1566 results = Geospatial_data(fileName) 1566 assert allclose(results.get_data_points(absolute=True), \1567 assert numpy.allclose(results.get_data_points(absolute=True), \ 1567 1568 [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1568 assert allclose(results.get_attributes(attribute_name='elevation'), \1569 assert numpy.allclose(results.get_attributes(attribute_name='elevation'), \ 1569 1570 [10.0, 0.0, 10.4]) 1570 assert allclose(results.get_attributes(attribute_name='speed'), \1571 assert numpy.allclose(results.get_attributes(attribute_name='speed'), \ 1571 1572 [0.0, 10.0, 40.0]) 1572 1573 … … 1601 1602 points = results.get_data_points() 1602 1603 1603 assert allclose(points[0][0], 308728.009)1604 assert allclose(points[0][1], 6180432.601)1605 assert allclose(points[1][0], 222908.705)1606 assert allclose(points[1][1], 6233785.284)1604 assert numpy.allclose(points[0][0], 308728.009) 1605 assert numpy.allclose(points[0][1], 6180432.601) 1606 assert numpy.allclose(points[1][0], 222908.705) 1607 assert numpy.allclose(points[1][1], 6233785.284) 1607 1608 1608 1609 … … 1622 1623 points = results.get_data_points() 1623 1624 1624 assert allclose(points[0][0], 308728.009)1625 assert allclose(points[0][1], 6180432.601)1626 assert allclose(points[1][0], 222908.705)1627 assert allclose(points[1][1], 6233785.284)1625 assert numpy.allclose(points[0][0], 308728.009) 1626 assert numpy.allclose(points[0][1], 6180432.601) 1627 assert numpy.allclose(points[1][0], 222908.705) 1628 assert numpy.allclose(points[1][1], 6233785.284) 1628 1629 1629 1630 … … 1662 1663 points = gsd.get_data_points(absolute=True) 1663 1664 1664 assert allclose(points[0][0], 308728.009)1665 assert allclose(points[0][1], 6180432.601)1666 assert allclose(points[1][0], 222908.705)1667 assert allclose(points[1][1], 6233785.284)1665 assert numpy.allclose(points[0][0], 308728.009) 1666 assert numpy.allclose(points[0][1], 6180432.601) 1667 assert numpy.allclose(points[1][0], 222908.705) 1668 assert numpy.allclose(points[1][1], 6233785.284) 1668 1669 self.failUnless(gsd.get_geo_reference().get_zone() == 56, 1669 1670 'Bad zone error!') … … 1715 1716 points = gsd.get_data_points(absolute=True) 1716 1717 1717 assert allclose(points[0][0], 308728.009)1718 assert allclose(points[0][1], 6180432.601)1719 assert allclose(points[1][0], 222908.705)1720 assert allclose(points[1][1], 6233785.284)1718 assert numpy.allclose(points[0][0], 308728.009) 1719 assert numpy.allclose(points[0][1], 6180432.601) 1720 assert numpy.allclose(points[1][0], 222908.705) 1721 assert numpy.allclose(points[1][1], 6233785.284) 1721 1722 self.failUnless(gsd.get_geo_reference().get_zone() == 56, 1722 1723 'Bad zone error!') … … 1770 1771 # and it changes from windows to linux 1771 1772 try: 1772 assert allclose(points[1][0], 308728.009)1773 assert allclose(points[1][1], 6180432.601)1774 assert allclose(points[0][0], 222908.705)1775 assert allclose(points[0][1], 6233785.284)1773 assert numpy.allclose(points[1][0], 308728.009) 1774 assert numpy.allclose(points[1][1], 6180432.601) 1775 assert numpy.allclose(points[0][0], 222908.705) 1776 assert numpy.allclose(points[0][1], 6233785.284) 1776 1777 except AssertionError: 1777 assert allclose(points[0][0], 308728.009)1778 assert allclose(points[0][1], 6180432.601)1779 assert allclose(points[1][0], 222908.705)1780 assert allclose(points[1][1], 6233785.284)1778 assert numpy.allclose(points[0][0], 308728.009) 1779 assert numpy.allclose(points[0][1], 6180432.601) 1780 assert numpy.allclose(points[1][0], 222908.705) 1781 assert numpy.allclose(points[1][1], 6233785.284) 1781 1782 1782 1783 self.failUnless(gsd.get_geo_reference().get_zone() == 56, … … 1785 1786 #print "test_lat_long_set points", points 1786 1787 try: 1787 assert allclose(points[0][0], -34)1788 assert allclose(points[0][1], 150)1788 assert numpy.allclose(points[0][0], -34) 1789 assert numpy.allclose(points[0][1], 150) 1789 1790 except AssertionError: 1790 assert allclose(points[1][0], -34)1791 assert allclose(points[1][1], 150)1791 assert numpy.allclose(points[1][0], -34) 1792 assert numpy.allclose(points[1][1], 150) 1792 1793 1793 1794 def test_len(self): … … 1828 1829 G1, G2 = G.split(factor,100) 1829 1830 1830 assert allclose(len(G), len(G1)+len(G2))1831 assert allclose(round(len(G)*factor), len(G1))1831 assert numpy.allclose(len(G), len(G1)+len(G2)) 1832 assert numpy.allclose(round(len(G)*factor), len(G1)) 1832 1833 1833 1834 P = G1.get_data_points(absolute=False) 1834 assert allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]])1835 assert numpy.allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]]) 1835 1836 1836 1837 A = G1.get_attributes() 1837 assert allclose(A,[24, 18, 17, 11, 8])1838 assert numpy.allclose(A,[24, 18, 17, 11, 8]) 1838 1839 1839 1840 def test_split1(self): … … 1842 1843 if get_host_name()[8:9]!='0': 1843 1844 1844 from RandomArray import randint,seed1845 seed(100,100)1846 a_points = randint(0,999999,(10,2))1845 ## from numpy.oldnumeric.random_array import randint,seed 1846 numpy.random.seed(100,100) 1847 a_points = numpy.random.randint(0,999999,(10,2)) 1847 1848 points = a_points.tolist() 1848 1849 # print points … … 1856 1857 1857 1858 # print 'G1',G1 1858 assert allclose(len(G), len(G1)+len(G2))1859 assert allclose(round(len(G)*factor), len(G1))1859 assert numpy.allclose(len(G), len(G1)+len(G2)) 1860 assert numpy.allclose(round(len(G)*factor), len(G1)) 1860 1861 1861 1862 P = G1.get_data_points(absolute=False) 1862 assert allclose(P, [[982420.,28233.]])1863 assert numpy.allclose(P, [[982420.,28233.]]) 1863 1864 1864 1865
Note: See TracChangeset
for help on using the changeset viewer.