Changeset 6153
- Timestamp:
- Jan 13, 2009, 2:49:15 PM (16 years ago)
- Location:
- anuga_core/source/anuga/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geospatial_data/geospatial_data.py
r6086 r6153 9 9 from warnings import warn 10 10 from string import lower 11 from Numeric import concatenate, array, Float, shape, reshape, ravel, take, \12 size, shape13 11 from RandomArray import randint, seed, get_seed 14 12 from copy import deepcopy 15 13 from Scientific.IO.NetCDF import NetCDFFile 14 15 import Numeric as num 16 16 17 from anuga.coordinate_transforms.lat_long_UTM_conversion import UTMtoLL 17 18 from anuga.utilities.numerical_tools import ensure_numeric … … 486 487 zone2 = geo_ref2.get_zone() 487 488 geo_ref1.reconcile_zones(geo_ref2) 488 new_points = concatenate((self.get_data_points(absolute=True),489 other.get_data_points(absolute=True)),490 axis = 0)489 new_points = num.concatenate((self.get_data_points(absolute=True), 490 other.get_data_points(absolute=True)), 491 axis = 0) 491 492 492 493 # Concatenate attributes if any … … 504 505 attrib1 = self.attributes[x] 505 506 attrib2 = other.attributes[x] 506 new_attributes[x] = concatenate((attrib1, attrib2))507 new_attributes[x] = num.concatenate((attrib1, attrib2)) 507 508 else: 508 509 msg = 'Geospatial data must have the same \n' … … 660 661 #FIXME: add the geo_reference to this 661 662 points = self.get_data_points() 662 sampled_points = take(points, indices)663 sampled_points = num.take(points, indices) 663 664 664 665 attributes = self.get_all_attributes() … … 667 668 if attributes is not None: 668 669 for key, att in attributes.items(): 669 sampled_attributes[key] = take(att, indices)670 sampled_attributes[key] = num.take(att, indices) 670 671 671 672 return Geospatial_data(sampled_points, sampled_attributes) … … 706 707 if verbose: print "make unique random number list and get indices" 707 708 708 total= array(range(self_size))709 total=num.array(range(self_size)) 709 710 total_list = total.tolist() 710 711 … … 959 960 raise ValueError, msg 960 961 lats_longs = ensure_numeric(data_points) 961 latitudes = ravel(lats_longs[:,0:1])962 longitudes = ravel(lats_longs[:,1:])962 latitudes = num.ravel(lats_longs[:,0:1]) 963 longitudes = num.ravel(lats_longs[:,1:]) 963 964 964 965 if latitudes is None and longitudes is None: … … 1004 1005 fid = NetCDFFile(file_name, netcdf_mode_r) 1005 1006 1006 pointlist = array(fid.variables['points'])1007 pointlist = num.array(fid.variables['points']) 1007 1008 keys = fid.variables.keys() 1008 1009 … … 1020 1021 if verbose: print "reading attribute '%s'" % key 1021 1022 1022 attributes[key] = array(fid.variables[key])1023 attributes[key] = num.array(fid.variables[key]) 1023 1024 1024 1025 try: … … 1138 1139 "There might be a problem with the file header." 1139 1140 raise SyntaxError, msg 1140 for i,n umin enumerate(numbers):1141 n um.strip()1142 if n um != '\n' and num!= '':1143 #attributes.append(float(n um))1144 att_dict.setdefault(header[i],[]).append(float(n um))1141 for i,n in enumerate(numbers): 1142 n.strip() 1143 if n != '\n' and n != '': 1144 #attributes.append(float(n)) 1145 att_dict.setdefault(header[i],[]).append(float(n)) 1145 1146 except ValueError: 1146 1147 raise SyntaxError … … 1149 1150 raise StopIteration 1150 1151 1151 pointlist = array(points).astype(Float)1152 pointlist = num.array(points).astype(num.Float) 1152 1153 for key in att_dict.keys(): 1153 att_dict[key] = array(att_dict[key]).astype(Float)1154 att_dict[key] = num.array(att_dict[key]).astype(num.Float) 1154 1155 1155 1156 # Do stuff here so the info is in lat's and longs … … 1160 1161 and (y_header == 'lon' or y_header == 'lat'): 1161 1162 if x_header == 'lon': 1162 longitudes = ravel(pointlist[:,0:1])1163 latitudes = ravel(pointlist[:,1:])1163 longitudes = num.ravel(pointlist[:,0:1]) 1164 latitudes = num.ravel(pointlist[:,1:]) 1164 1165 else: 1165 latitudes = ravel(pointlist[:,0:1])1166 longitudes = ravel(pointlist[:,1:])1166 latitudes = num.ravel(pointlist[:,0:1]) 1167 longitudes = num.ravel(pointlist[:,1:]) 1167 1168 1168 1169 pointlist, geo_ref = _set_using_lat_long(latitudes, … … 1214 1215 """ 1215 1216 1216 pointlist = array(fid.variables['points'][start_row:fin_row])1217 pointlist = num.array(fid.variables['points'][start_row:fin_row]) 1217 1218 1218 1219 attributes = {} 1219 1220 for key in keys: 1220 attributes[key] = array(fid.variables[key][start_row:fin_row])1221 attributes[key] = num.array(fid.variables[key][start_row:fin_row]) 1221 1222 1222 1223 return pointlist, attributes … … 1266 1267 1267 1268 # Variable definition 1268 outfile.createVariable('points', Float, ('number_of_points',1269 'number_of_dimensions'))1269 outfile.createVariable('points', num.Float, ('number_of_points', 1270 'number_of_dimensions')) 1270 1271 1271 1272 #create variables … … 1274 1275 if write_attributes is not None: 1275 1276 for key in write_attributes.keys(): 1276 outfile.createVariable(key, Float, ('number_of_points',))1277 outfile.createVariable(key, num.Float, ('number_of_points',)) 1277 1278 outfile.variables[key][:] = write_attributes[key] #.astype(Float32) 1278 1279 … … 1360 1361 # @return ?? 1361 1362 def _point_atts2array(point_atts): 1362 point_atts['pointlist'] = array(point_atts['pointlist']).astype(Float)1363 point_atts['pointlist'] = num.array(point_atts['pointlist']).astype(num.Float) 1363 1364 1364 1365 for key in point_atts['attributelist'].keys(): 1365 1366 point_atts['attributelist'][key] = \ 1366 array(point_atts['attributelist'][key]).astype(Float)1367 num.array(point_atts['attributelist'][key]).astype(num.Float) 1367 1368 1368 1369 return point_atts … … 1469 1470 assert geo_reference == None, msg 1470 1471 else: 1471 points = ensure_numeric(points, Float)1472 points = ensure_numeric(points, num.Float) 1472 1473 1473 1474 # Sort of geo_reference and convert points … … 1513 1514 else: 1514 1515 # List or numeric array of absolute points 1515 points = ensure_numeric(points, Float)1516 points = ensure_numeric(points, num.Float) 1516 1517 1517 1518 # Sort out geo reference … … 1609 1610 from anuga.pmesh.mesh_interface import create_mesh_from_regions 1610 1611 from anuga.utilities.numerical_tools import cov 1611 from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin1612 1612 from anuga.utilities.polygon import is_inside_polygon 1613 1613 from anuga.fit_interpolate.benchmark_least_squares import mem_usage … … 1671 1671 #4 onwards is the elevation_predicted using the alpha, which will 1672 1672 #be compared later against the real removed data 1673 data = array([], typecode=Float)1674 1675 data= resize(data, (len(points), 3+len(alphas)))1673 data = num.array([], typecode=num.Float) 1674 1675 data=num.resize(data, (len(points), 3+len(alphas))) 1676 1676 1677 1677 #gets relative point from sample … … 1681 1681 data[:,2] = elevation_sample 1682 1682 1683 normal_cov= array(zeros([len(alphas), 2]), typecode=Float)1683 normal_cov=num.array(num.zeros([len(alphas), 2]), typecode=num.Float) 1684 1684 1685 1685 if verbose: print 'Setup computational domains with different alphas' … … 1720 1720 1721 1721 normal_cov0 = normal_cov[:,0] 1722 normal_cov_new = take(normal_cov,argsort(normal_cov0))1722 normal_cov_new = num.take(normal_cov, num.argsort(normal_cov0)) 1723 1723 1724 1724 if plot_name is not None: … … 1738 1738 % (normal_cov[i][0], normal_cov[i][1]) 1739 1739 print '\n Optimal alpha is: %s ' \ 1740 % normal_cov_new[( argmin(normal_cov_new, axis=0))[1], 0]1740 % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0] 1741 1741 1742 1742 # covariance and optimal alpha 1743 1743 return (min(normal_cov_new[:,1]), 1744 normal_cov_new[( argmin(normal_cov_new,axis=0))[1],0])1744 normal_cov_new[(num.argmin(normal_cov_new,axis=0))[1],0]) 1745 1745 1746 1746 … … 1817 1817 from anuga.pmesh.mesh_interface import create_mesh_from_regions 1818 1818 from anuga.utilities.numerical_tools import cov 1819 from Numeric import array, resize,shape,Float,zeros,take,argsort,argmin1820 1819 from anuga.utilities.polygon import is_inside_polygon 1821 1820 from anuga.fit_interpolate.benchmark_least_squares import mem_usage … … 1906 1905 #4 onwards is the elevation_predicted using the alpha, which will 1907 1906 #be compared later against the real removed data 1908 data = array([], typecode=Float)1909 1910 data = resize(data, (len(points), 3+len(alphas)))1907 data = num.array([], typecode=num.Float) 1908 1909 data = num.resize(data, (len(points), 3+len(alphas))) 1911 1910 1912 1911 #gets relative point from sample … … 1916 1915 data[:,2] = elevation_sample 1917 1916 1918 normal_cov = array(zeros([len(alphas), 2]), typecode=Float)1917 normal_cov = num.array(num.zeros([len(alphas), 2]), typecode=num.Float) 1919 1918 1920 1919 if verbose: … … 1940 1939 1941 1940 normal_cov0 = normal_cov[:,0] 1942 normal_cov_new = take(normal_cov,argsort(normal_cov0))1941 normal_cov_new = num.take(normal_cov, num.argsort(normal_cov0)) 1943 1942 1944 1943 if plot_name is not None: … … 1952 1951 1953 1952 return (min(normal_cov_new[:,1]), 1954 normal_cov_new[( argmin(normal_cov_new, axis=0))[1],0])1953 normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1],0]) 1955 1954 1956 1955 -
anuga_core/source/anuga/geospatial_data/test_geospatial_data.py
r6086 r6153 4 4 import unittest 5 5 import os 6 from Numeric import zeros, array, allclose, concatenate,sort7 6 from math import sqrt, pi 8 7 import tempfile 9 8 from sets import ImmutableSet 9 10 import Numeric as num 10 11 11 12 from anuga.geospatial_data.geospatial_data import * … … 31 32 G = Geospatial_data(points) 32 33 33 assert allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]])34 assert num.allclose(G.data_points, [[1.0, 2.1], [3.0, 5.3]]) 34 35 35 36 # Check __repr__ … … 42 43 43 44 #Check getter 44 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]])45 assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3]]) 45 46 46 47 #Check defaults … … 57 58 G = Geospatial_data(points, attributes) 58 59 assert G.attributes.keys()[0] == DEFAULT_ATTRIBUTE 59 assert allclose(G.attributes.values()[0], [2, 4])60 assert num.allclose(G.attributes.values()[0], [2, 4]) 60 61 61 62 … … 81 82 82 83 P = G.get_data_points(absolute=False) 83 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])84 assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 84 85 85 86 P = G.get_data_points(absolute=True) 86 assert allclose(P, [[101.0, 202.1], [103.0, 205.3]])87 assert num.allclose(P, [[101.0, 202.1], [103.0, 205.3]]) 87 88 88 89 V = G.get_attributes() #Simply get them 89 assert allclose(V, [2, 4])90 assert num.allclose(V, [2, 4]) 90 91 91 92 V = G.get_attributes(DEFAULT_ATTRIBUTE) #Get by name 92 assert allclose(V, [2, 4])93 assert num.allclose(V, [2, 4]) 93 94 94 95 def test_get_attributes_2(self): … … 105 106 106 107 P = G.get_data_points(absolute=False) 107 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])108 assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 108 109 109 110 V = G.get_attributes() #Get default attribute 110 assert allclose(V, [2, 4])111 assert num.allclose(V, [2, 4]) 111 112 112 113 V = G.get_attributes('a0') #Get by name 113 assert allclose(V, [0, 0])114 assert num.allclose(V, [0, 0]) 114 115 115 116 V = G.get_attributes('a1') #Get by name 116 assert allclose(V, [2, 4])117 assert num.allclose(V, [2, 4]) 117 118 118 119 V = G.get_attributes('a2') #Get by name 119 assert allclose(V, [79.4, -7])120 assert num.allclose(V, [79.4, -7]) 120 121 121 122 try: … … 137 138 results = spatial.get_data_points(absolute=False) 138 139 139 assert allclose(results, points_rel)140 assert num.allclose(results, points_rel) 140 141 141 142 x_p = -1770 … … 146 147 ( geo_reference=geo_ref) 147 148 148 assert allclose(results, points_rel)149 assert num.allclose(results, points_rel) 149 150 150 151 … … 165 166 #print "test_get_data_points_lat_long - results", results 166 167 #print "points_Lat_long",points_Lat_long 167 assert allclose(results, points_Lat_long)168 assert num.allclose(results, points_Lat_long) 168 169 169 170 def test_get_data_points_lat_longII(self): … … 179 180 #print "seg_lat_long", seg_lat_long [0][0] 180 181 #print "lat_result",lat_result 181 assert allclose(seg_lat_long[0][0], lat_result)#lat182 assert allclose(seg_lat_long[0][1], long_result)#long182 assert num.allclose(seg_lat_long[0][0], lat_result)#lat 183 assert num.allclose(seg_lat_long[0][1], long_result)#long 183 184 184 185 … … 200 201 #print "seg_lat_long", seg_lat_long [0] 201 202 #print "lat_result",lat_result 202 assert allclose(seg_lat_long[0][0], lat_result)#lat203 assert allclose(seg_lat_long[0][1], long_result)#long203 assert num.allclose(seg_lat_long[0][0], lat_result)#lat 204 assert num.allclose(seg_lat_long[0][1], long_result)#long 204 205 205 206 … … 220 221 # Create without geo_ref properly set 221 222 G = Geospatial_data(points_rel) 222 assert not allclose(points_ab, G.get_data_points(absolute=True))223 assert not num.allclose(points_ab, G.get_data_points(absolute=True)) 223 224 224 225 # Create the way it should be 225 226 G = Geospatial_data(points_rel, geo_reference=geo_ref) 226 assert allclose(points_ab, G.get_data_points(absolute=True))227 assert num.allclose(points_ab, G.get_data_points(absolute=True)) 227 228 228 229 # Change georeference and check that absolute values are unchanged. … … 231 232 new_geo_ref = Geo_reference(56, x_p, y_p) 232 233 G.set_geo_reference(new_geo_ref) 233 assert allclose(points_ab, G.get_data_points(absolute=True))234 assert num.allclose(points_ab, G.get_data_points(absolute=True)) 234 235 235 236 … … 254 255 assert points_dict.has_key('geo_reference') 255 256 256 assert allclose( points_dict['pointlist'], points )257 assert num.allclose( points_dict['pointlist'], points ) 257 258 258 259 A = points_dict['attributelist'] … … 261 262 assert A.has_key('a2') 262 263 263 assert allclose( A['a0'], [0, 0] )264 assert allclose( A['a1'], [2, 4] )265 assert allclose( A['a2'], [79.4, -7] )264 assert num.allclose( A['a0'], [0, 0] ) 265 assert num.allclose( A['a1'], [2, 4] ) 266 assert num.allclose( A['a2'], [79.4, -7] ) 266 267 267 268 … … 288 289 289 290 P = G.get_data_points(absolute=False) 290 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])291 assert num.allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 291 292 292 293 #V = G.get_attribute_values() #Get default attribute … … 294 295 295 296 V = G.get_attributes('a0') #Get by name 296 assert allclose(V, [0, 0])297 assert num.allclose(V, [0, 0]) 297 298 298 299 V = G.get_attributes('a1') #Get by name 299 assert allclose(V, [2, 4])300 assert num.allclose(V, [2, 4]) 300 301 301 302 V = G.get_attributes('a2') #Get by name 302 assert allclose(V, [79.4, -7])303 assert num.allclose(V, [79.4, -7]) 303 304 304 305 def test_add(self): … … 319 320 assert G.attributes.has_key('depth') 320 321 assert G.attributes.has_key('elevation') 321 assert allclose(G.attributes['depth'], [2, 4, 2, 4])322 assert allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1])323 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],324 [1.0, 2.1], [3.0, 5.3]])325 322 assert num.allclose(G.attributes['depth'], [2, 4, 2, 4]) 323 assert num.allclose(G.attributes['elevation'], [6.1, 5, 2.5, 1]) 324 assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3], 325 [1.0, 2.1], [3.0, 5.3]]) 326 326 327 def test_addII(self): 327 328 """ test the addition of two geospatical objects … … 343 344 assert G.attributes.has_key('depth') 344 345 assert G.attributes.keys(), ['depth'] 345 assert allclose(G.attributes['depth'], [2, 4, 200, 400])346 assert allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3],347 [5.0, 2.1], [3.0, 50.3]])346 assert num.allclose(G.attributes['depth'], [2, 4, 200, 400]) 347 assert num.allclose(G.get_data_points(), [[1.0, 2.1], [3.0, 5.3], 348 [5.0, 2.1], [3.0, 50.3]]) 348 349 def test_add_with_geo (self): 349 350 """ … … 367 368 #Check that absolute values are as expected 368 369 P1 = G1.get_data_points(absolute=True) 369 assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]])370 assert num.allclose(P1, [[2.0, 4.1], [4.0, 7.3]]) 370 371 371 372 P2 = G2.get_data_points(absolute=True) 372 assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]])373 assert num.allclose(P2, [[5.1, 9.1], [6.1, 6.3]]) 373 374 374 375 G = G1 + G2 375 376 376 377 # Check absoluteness 377 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)378 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)378 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 379 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 379 380 380 381 P = G.get_data_points(absolute=True) … … 384 385 #assert allclose(P_relative, P - [0.1, 2.0]) 385 386 386 assert allclose(P,concatenate( (P1,P2) ))387 assert allclose(P, [[2.0, 4.1], [4.0, 7.3],388 [5.1, 9.1], [6.1, 6.3]])387 assert num.allclose(P, num.concatenate( (P1,P2) )) 388 assert num.allclose(P, [[2.0, 4.1], [4.0, 7.3], 389 [5.1, 9.1], [6.1, 6.3]]) 389 390 390 391 … … 396 397 Difference in Geo_reference resolved 397 398 """ 398 points1 = array([[2.0, 4.1], [4.0, 7.3]])399 points2 = array([[5.1, 9.1], [6.1, 6.3]])399 points1 = num.array([[2.0, 4.1], [4.0, 7.3]]) 400 points2 = num.array([[5.1, 9.1], [6.1, 6.3]]) 400 401 attributes1 = [2, 4] 401 402 attributes2 = [5, 76] … … 413 414 #Check that absolute values are as expected 414 415 P1 = G1.get_data_points(absolute=True) 415 assert allclose(P1, points1)416 assert num.allclose(P1, points1) 416 417 417 418 P1 = G1.get_data_points(absolute=False) 418 assert allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()])419 assert num.allclose(P1, points1 - [geo_ref1.get_xllcorner(), geo_ref1.get_yllcorner()]) 419 420 420 421 P2 = G2.get_data_points(absolute=True) 421 assert allclose(P2, points2)422 assert num.allclose(P2, points2) 422 423 423 424 P2 = G2.get_data_points(absolute=False) 424 assert allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()])425 assert num.allclose(P2, points2 - [geo_ref2.get_xllcorner(), geo_ref2.get_yllcorner()]) 425 426 426 427 G = G1 + G2 … … 435 436 #assert allclose(P_relative, [[1.0, 2.1], [3.0, 5.3], [4.1, 7.1], [5.1, 4.3]]) 436 437 437 assert allclose(P,concatenate( (points1,points2) ))438 assert num.allclose(P, num.concatenate( (points1,points2) )) 438 439 439 440 … … 442 443 """ 443 444 444 points1 = array([[2.0, 4.1], [4.0, 7.3]])445 points2 = array([[5.1, 9.1], [6.1, 6.3]])445 points1 = num.array([[2.0, 4.1], [4.0, 7.3]]) 446 points2 = num.array([[5.1, 9.1], [6.1, 6.3]]) 446 447 447 448 geo_ref1= Geo_reference(55, 1.0, 2.0) … … 459 460 460 461 G1 = Geospatial_data(points1, attributes1, geo_ref1) 461 assert allclose(G1.get_geo_reference().get_xllcorner(), 1.0)462 assert allclose(G1.get_geo_reference().get_yllcorner(), 2.0)462 assert num.allclose(G1.get_geo_reference().get_xllcorner(), 1.0) 463 assert num.allclose(G1.get_geo_reference().get_yllcorner(), 2.0) 463 464 assert G1.attributes.has_key('depth') 464 465 assert G1.attributes.has_key('elevation') 465 assert allclose(G1.attributes['depth'], [2, 4.7])466 assert allclose(G1.attributes['elevation'], [6.1, 5])466 assert num.allclose(G1.attributes['depth'], [2, 4.7]) 467 assert num.allclose(G1.attributes['elevation'], [6.1, 5]) 467 468 468 469 G2 = Geospatial_data(points2, attributes2, geo_ref2) 469 assert allclose(G2.get_geo_reference().get_xllcorner(), 0.1)470 assert allclose(G2.get_geo_reference().get_yllcorner(), 3.0)470 assert num.allclose(G2.get_geo_reference().get_xllcorner(), 0.1) 471 assert num.allclose(G2.get_geo_reference().get_yllcorner(), 3.0) 471 472 assert G2.attributes.has_key('depth') 472 473 assert G2.attributes.has_key('elevation') 473 assert allclose(G2.attributes['depth'], [-2.3, 4])474 assert allclose(G2.attributes['elevation'], [2.5, 1])474 assert num.allclose(G2.attributes['depth'], [-2.3, 4]) 475 assert num.allclose(G2.attributes['elevation'], [2.5, 1]) 475 476 476 477 #Check that absolute values are as expected 477 478 P1 = G1.get_data_points(absolute=True) 478 assert allclose(P1, [[3.0, 6.1], [5.0, 9.3]])479 assert num.allclose(P1, [[3.0, 6.1], [5.0, 9.3]]) 479 480 480 481 P2 = G2.get_data_points(absolute=True) 481 assert allclose(P2, [[5.2, 12.1], [6.2, 9.3]])482 assert num.allclose(P2, [[5.2, 12.1], [6.2, 9.3]]) 482 483 483 484 # Normal add … … 486 487 assert G.attributes.has_key('depth') 487 488 assert G.attributes.has_key('elevation') 488 assert allclose(G.attributes['depth'], [2, 4.7])489 assert allclose(G.attributes['elevation'], [6.1, 5])489 assert num.allclose(G.attributes['depth'], [2, 4.7]) 490 assert num.allclose(G.attributes['elevation'], [6.1, 5]) 490 491 491 492 # Points are now absolute. 492 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)493 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)493 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 494 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 494 495 P = G.get_data_points(absolute=True) 495 assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])496 assert num.allclose(P, [[3.0, 6.1], [5.0, 9.3]]) 496 497 497 498 … … 499 500 assert G.attributes.has_key('depth') 500 501 assert G.attributes.has_key('elevation') 501 assert allclose(G.attributes['depth'], [-2.3, 4])502 assert allclose(G.attributes['elevation'], [2.5, 1])503 504 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)505 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)502 assert num.allclose(G.attributes['depth'], [-2.3, 4]) 503 assert num.allclose(G.attributes['elevation'], [2.5, 1]) 504 505 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 506 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 506 507 P = G.get_data_points(absolute=True) 507 assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])508 assert num.allclose(P, [[5.2, 12.1], [6.2, 9.3]]) 508 509 509 510 … … 514 515 assert G.attributes.has_key('depth') 515 516 assert G.attributes.has_key('elevation') 516 assert allclose(G.attributes['depth'], [2, 4.7])517 assert allclose(G.attributes['elevation'], [6.1, 5])517 assert num.allclose(G.attributes['depth'], [2, 4.7]) 518 assert num.allclose(G.attributes['elevation'], [6.1, 5]) 518 519 519 520 # Points are now absolute. 520 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)521 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)521 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 522 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 522 523 P = G.get_data_points(absolute=True) 523 assert allclose(P, [[3.0, 6.1], [5.0, 9.3]])524 assert num.allclose(P, [[3.0, 6.1], [5.0, 9.3]]) 524 525 525 526 … … 527 528 assert G.attributes.has_key('depth') 528 529 assert G.attributes.has_key('elevation') 529 assert allclose(G.attributes['depth'], [-2.3, 4])530 assert allclose(G.attributes['elevation'], [2.5, 1])531 532 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)533 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)530 assert num.allclose(G.attributes['depth'], [-2.3, 4]) 531 assert num.allclose(G.attributes['elevation'], [2.5, 1]) 532 533 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 534 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 534 535 P = G.get_data_points(absolute=True) 535 assert allclose(P, [[5.2, 12.1], [6.2, 9.3]])536 assert num.allclose(P, [[5.2, 12.1], [6.2, 9.3]]) 536 537 537 538 … … 554 555 # First try the unit square 555 556 U = [[0,0], [1,0], [1,1], [0,1]] 556 assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])557 assert num.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 557 558 558 559 # Then a more complex polygon … … 561 562 G = Geospatial_data(points) 562 563 563 assert allclose(G.clip(polygon).get_data_points(),564 assert num.allclose(G.clip(polygon).get_data_points(), 564 565 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 565 566 … … 577 578 attributes = [2, -4, 5, 76, -2, 0.1, 3] 578 579 att_dict = {'att1': attributes, 579 'att2': array(attributes)+1}580 'att2': num.array(attributes)+1} 580 581 581 582 G = Geospatial_data(points, att_dict) … … 583 584 # First try the unit square 584 585 U = [[0,0], [1,0], [1,1], [0,1]] 585 assert allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]])586 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])587 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])586 assert num.allclose(G.clip(U).get_data_points(), [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 587 assert num.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 588 assert num.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 588 589 589 590 # Then a more complex polygon … … 595 596 G = Geospatial_data(points, attributes) 596 597 597 assert allclose(G.clip(polygon).get_data_points(),598 assert num.allclose(G.clip(polygon).get_data_points(), 598 599 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 599 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])600 assert num.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 600 601 601 602 … … 613 614 attributes = [2, -4, 5, 76, -2, 0.1, 3] 614 615 att_dict = {'att1': attributes, 615 'att2': array(attributes)+1}616 'att2': num.array(attributes)+1} 616 617 G = Geospatial_data(points, att_dict) 617 618 618 619 # First try the unit square 619 620 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 620 assert allclose(G.clip(U).get_data_points(),621 assert num.allclose(G.clip(U).get_data_points(), 621 622 [[0.2, 0.5], [0.4, 0.3], [0, 0]]) 622 623 623 assert allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1])624 assert allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1])624 assert num.allclose(G.clip(U).get_attributes('att1'), [-4, 76, 0.1]) 625 assert num.allclose(G.clip(U).get_attributes('att2'), [-3, 77, 1.1]) 625 626 626 627 # Then a more complex polygon … … 631 632 632 633 633 assert allclose(G.clip(polygon).get_data_points(),634 [[0.5, 0.5], [1, -0.5], [1.5, 0]])635 assert allclose(G.clip(polygon).get_attributes(), [-4, 5, 76])634 assert num.allclose(G.clip(polygon).get_data_points(), 635 [[0.5, 0.5], [1, -0.5], [1.5, 0]]) 636 assert num.allclose(G.clip(polygon).get_attributes(), [-4, 5, 76]) 636 637 637 638 … … 651 652 # First try the unit square 652 653 U = [[0,0], [1,0], [1,1], [0,1]] 653 assert allclose(G.clip_outside(U).get_data_points(),654 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])654 assert num.allclose(G.clip_outside(U).get_data_points(), 655 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 655 656 #print G.clip_outside(U).get_attributes() 656 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])657 assert num.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 657 658 658 659 … … 663 664 G = Geospatial_data(points, attributes) 664 665 665 assert allclose(G.clip_outside(polygon).get_data_points(),666 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])667 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])666 assert num.allclose(G.clip_outside(polygon).get_data_points(), 667 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 668 assert num.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 668 669 669 670 … … 684 685 # First try the unit square 685 686 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 686 assert allclose(G.clip_outside(U).get_data_points(),687 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]])688 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])687 assert num.allclose(G.clip_outside(U).get_data_points(), 688 [[-1, 4], [1.0, 2.1], [3.0, 5.3], [2.4, 3.3]]) 689 assert num.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 689 690 690 691 # Then a more complex polygon … … 696 697 697 698 698 assert allclose(G.clip_outside(polygon).get_data_points(),699 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]])700 assert allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1])699 assert num.allclose(G.clip_outside(polygon).get_data_points(), 700 [[0.5, 1.4], [0.5, 1.5], [0.5, -0.5]]) 701 assert num.allclose(G.clip_outside(polygon).get_attributes(), [2, -2, 0.1]) 701 702 702 703 … … 719 720 U = Geospatial_data([[0,0], [1,0], [1,1], [0,1]]) 720 721 G1 = G.clip(U) 721 assert allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]])722 assert allclose(G.clip(U).get_attributes(), [-4, 76, 0.1])722 assert num.allclose(G1.get_data_points(),[[0.2, 0.5], [0.4, 0.3], [0, 0]]) 723 assert num.allclose(G.clip(U).get_attributes(), [-4, 76, 0.1]) 723 724 724 725 G2 = G.clip_outside(U) 725 assert allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1],726 [3.0, 5.3], [2.4, 3.3]])727 assert allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3])726 assert num.allclose(G2.get_data_points(),[[-1, 4], [1.0, 2.1], 727 [3.0, 5.3], [2.4, 3.3]]) 728 assert num.allclose(G.clip_outside(U).get_attributes(), [2, 5, -2, 3]) 728 729 729 730 … … 734 735 new_attributes = [-4, 76, 0.1, 2, 5, -2, 3] 735 736 736 assert allclose((G1+G2).get_data_points(), new_points)737 assert allclose((G1+G2).get_attributes(), new_attributes)737 assert num.allclose((G1+G2).get_data_points(), new_points) 738 assert num.allclose((G1+G2).get_attributes(), new_attributes) 738 739 739 740 G = G1+G2 … … 747 748 748 749 # Check result 749 assert allclose(G3.get_data_points(), new_points)750 assert allclose(G3.get_attributes(), new_attributes)750 assert num.allclose(G3.get_data_points(), new_points) 751 assert num.allclose(G3.get_attributes(), new_attributes) 751 752 752 753 os.remove(FN) … … 769 770 os.remove(fileName) 770 771 # print 'data', results.get_data_points() 771 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],772 [1.0, 0.0]])773 assert allclose(results.get_attributes(attribute_name='elevation'),774 [10.0, 0.0, 10.4])775 assert allclose(results.get_attributes(attribute_name='speed'),776 [0.0, 10.0, 40.0])772 assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0], 773 [1.0, 0.0]]) 774 assert num.allclose(results.get_attributes(attribute_name='elevation'), 775 [10.0, 0.0, 10.4]) 776 assert num.allclose(results.get_attributes(attribute_name='speed'), 777 [0.0, 10.0, 40.0]) 777 778 778 779 … … 820 821 821 822 822 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])823 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])824 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])823 assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 824 assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 825 assert num.allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 825 826 826 827 # Blocking … … 829 830 geo_list.append(i) 830 831 831 assert allclose(geo_list[0].get_data_points(),832 [[1.0, 0.0],[0.0, 1.0]])833 834 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),835 [10.0, 0.0])836 assert allclose(geo_list[1].get_data_points(),837 [[1.0, 0.0]])838 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),839 [10.4])832 assert num.allclose(geo_list[0].get_data_points(), 833 [[1.0, 0.0],[0.0, 1.0]]) 834 835 assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 836 [10.0, 0.0]) 837 assert num.allclose(geo_list[1].get_data_points(), 838 [[1.0, 0.0]]) 839 assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 840 [10.4]) 840 841 841 842 os.remove(fileName) … … 980 981 results = Geospatial_data(pts_file, max_read_lines=2) 981 982 982 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],983 [1.0, 0.0]])984 assert allclose(results.get_attributes(attribute_name='elevation'),985 [10.0, 0.0, 10.4])986 assert allclose(results.get_attributes(attribute_name='speed'),987 [0.0, 10.0, 40.0])983 assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0], 984 [1.0, 0.0]]) 985 assert num.allclose(results.get_attributes(attribute_name='elevation'), 986 [10.0, 0.0, 10.4]) 987 assert num.allclose(results.get_attributes(attribute_name='speed'), 988 [0.0, 10.0, 40.0]) 988 989 989 990 # Blocking … … 991 992 for i in results: 992 993 geo_list.append(i) 993 assert allclose(geo_list[0].get_data_points(),994 [[1.0, 0.0],[0.0, 1.0]])995 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),996 [10.0, 0.0])997 assert allclose(geo_list[1].get_data_points(),998 [[1.0, 0.0]])999 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),1000 [10.4])994 assert num.allclose(geo_list[0].get_data_points(), 995 [[1.0, 0.0],[0.0, 1.0]]) 996 assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 997 [10.0, 0.0]) 998 assert num.allclose(geo_list[1].get_data_points(), 999 [[1.0, 0.0]]) 1000 assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 1001 [10.4]) 1001 1002 1002 1003 os.remove(fileName) … … 1069 1070 for i in results: 1070 1071 geo_list.append(i) 1071 assert allclose(geo_list[0].get_data_points(),1072 [[1.0, 0.0],[0.0, 1.0]])1073 assert allclose(geo_list[0].get_attributes(attribute_name='elevation'),1074 [10.0, 0.0])1075 assert allclose(geo_list[1].get_data_points(),1076 [[1.0, 0.0],[0.0, 1.0] ])1077 assert allclose(geo_list[1].get_attributes(attribute_name='elevation'),1078 [10.0, 0.0])1072 assert num.allclose(geo_list[0].get_data_points(), 1073 [[1.0, 0.0],[0.0, 1.0]]) 1074 assert num.allclose(geo_list[0].get_attributes(attribute_name='elevation'), 1075 [10.0, 0.0]) 1076 assert num.allclose(geo_list[1].get_data_points(), 1077 [[1.0, 0.0],[0.0, 1.0] ]) 1078 assert num.allclose(geo_list[1].get_attributes(attribute_name='elevation'), 1079 [10.0, 0.0]) 1079 1080 1080 1081 os.remove(fileName) … … 1085 1086 def test_new_export_pts_file(self): 1086 1087 att_dict = {} 1087 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1088 att_dict['elevation'] = array([10.1, 0.0, 10.4])1089 att_dict['brightness'] = array([10.0, 1.0, 10.4])1088 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1089 att_dict['elevation'] = num.array([10.1, 0.0, 10.4]) 1090 att_dict['brightness'] = num.array([10.0, 1.0, 10.4]) 1090 1091 1091 1092 fileName = tempfile.mktemp(".pts") … … 1099 1100 os.remove(fileName) 1100 1101 1101 assert allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1102 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])1102 assert num.allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1103 assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 1103 1104 answer = [10.0, 1.0, 10.4] 1104 assert allclose(results.get_attributes(attribute_name='brightness'), answer)1105 assert num.allclose(results.get_attributes(attribute_name='brightness'), answer) 1105 1106 1106 1107 def test_new_export_absolute_pts_file(self): 1107 1108 att_dict = {} 1108 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1109 att_dict['elevation'] = array([10.1, 0.0, 10.4])1110 att_dict['brightness'] = array([10.0, 1.0, 10.4])1109 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1110 att_dict['elevation'] = num.array([10.1, 0.0, 10.4]) 1111 att_dict['brightness'] = num.array([10.0, 1.0, 10.4]) 1111 1112 geo_ref = Geo_reference(50, 25, 55) 1112 1113 … … 1121 1122 os.remove(fileName) 1122 1123 1123 assert allclose(results.get_data_points(), G.get_data_points(True))1124 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4])1124 assert num.allclose(results.get_data_points(), G.get_data_points(True)) 1125 assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 1125 1126 answer = [10.0, 1.0, 10.4] 1126 assert allclose(results.get_attributes(attribute_name='brightness'), answer)1127 assert num.allclose(results.get_attributes(attribute_name='brightness'), answer) 1127 1128 1128 1129 def test_loadpts(self): … … 1139 1140 1140 1141 # variable definitions 1141 outfile.createVariable('points', Float, ('number_of_points',1142 'number_of_dimensions'))1143 outfile.createVariable('elevation', Float, ('number_of_points',))1142 outfile.createVariable('points', num.Float, ('number_of_points', 1143 'number_of_dimensions')) 1144 outfile.createVariable('elevation', num.Float, ('number_of_points',)) 1144 1145 1145 1146 # Get handles to the variables … … 1159 1160 os.remove(fileName) 1160 1161 answer = [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]] 1161 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1162 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])1162 assert num.allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1163 assert num.allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 1163 1164 1164 1165 def test_writepts(self): … … 1166 1167 1167 1168 att_dict = {} 1168 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1169 att_dict['elevation'] = array([10.0, 0.0, 10.4])1170 att_dict['brightness'] = array([10.0, 0.0, 10.4])1169 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1170 att_dict['elevation'] = num.array([10.0, 0.0, 10.4]) 1171 att_dict['brightness'] = num.array([10.0, 0.0, 10.4]) 1171 1172 geo_reference=Geo_reference(56,1.9,1.9) 1172 1173 … … 1178 1179 os.remove(fileName) 1179 1180 1180 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1181 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1181 assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1182 assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1182 1183 answer = [10.0, 0.0, 10.4] 1183 assert allclose(results.get_attributes('brightness'), answer)1184 assert num.allclose(results.get_attributes('brightness'), answer) 1184 1185 self.failUnless(geo_reference == geo_reference, 1185 1186 'test_writepts failed. Test geo_reference') … … 1189 1190 1190 1191 att_dict = {} 1191 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1192 att_dict['elevation'] = array([10.0, 0.0, 10.4])1193 att_dict['brightness'] = array([10.0, 0.0, 10.4])1192 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1193 att_dict['elevation'] = num.array([10.0, 0.0, 10.4]) 1194 att_dict['brightness'] = num.array([10.0, 0.0, 10.4]) 1194 1195 geo_reference=Geo_reference(56,0,0) 1195 1196 # Test txt format … … 1200 1201 results = Geospatial_data(file_name=fileName) 1201 1202 os.remove(fileName) 1202 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1203 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1203 assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1204 assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1204 1205 answer = [10.0, 0.0, 10.4] 1205 assert allclose(results.get_attributes('brightness'), answer)1206 assert num.allclose(results.get_attributes('brightness'), answer) 1206 1207 1207 1208 … … 1210 1211 1211 1212 att_dict = {} 1212 pointlist = array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]])1213 att_dict['elevation'] = array([10.0, 0.0, 10.4])1214 att_dict['brightness'] = array([10.0, 0.0, 10.4])1213 pointlist = num.array([[-21.5,114.5],[-21.6,114.5],[-21.7,114.5]]) 1214 att_dict['elevation'] = num.array([10.0, 0.0, 10.4]) 1215 att_dict['brightness'] = num.array([10.0, 0.0, 10.4]) 1215 1216 # Test txt format 1216 1217 fileName = tempfile.mktemp(".txt") … … 1220 1221 results = Geospatial_data(file_name=fileName) 1221 1222 os.remove(fileName) 1222 assert allclose(results.get_data_points(False, as_lat_long=True),1223 assert num.allclose(results.get_data_points(False, as_lat_long=True), 1223 1224 pointlist) 1224 assert allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4])1225 assert num.allclose(results.get_attributes('elevation'), [10.0, 0.0, 10.4]) 1225 1226 answer = [10.0, 0.0, 10.4] 1226 assert allclose(results.get_attributes('brightness'), answer)1227 assert num.allclose(results.get_attributes('brightness'), answer) 1227 1228 1228 1229 def test_writepts_no_attributes(self): … … 1231 1232 1232 1233 att_dict = {} 1233 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1234 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1234 1235 geo_reference=Geo_reference(56,1.9,1.9) 1235 1236 … … 1241 1242 os.remove(fileName) 1242 1243 1243 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1244 assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1244 1245 self.failUnless(geo_reference == geo_reference, 1245 1246 'test_writepts failed. Test geo_reference') … … 1250 1251 1251 1252 att_dict = {} 1252 pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1253 pointlist = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1253 1254 geo_reference=Geo_reference(56,0,0) 1254 1255 # Test format … … 1258 1259 results = Geospatial_data(file_name=fileName) 1259 1260 os.remove(fileName) 1260 assert allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1261 assert num.allclose(results.get_data_points(False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1261 1262 1262 1263 … … 1296 1297 1297 1298 # variable definitions 1298 outfile.createVariable('points', Float, ('number_of_points',1299 'number_of_dimensions'))1300 outfile.createVariable('elevation', Float, ('number_of_points',))1299 outfile.createVariable('points', num.Float, ('number_of_points', 1300 'number_of_dimensions')) 1301 outfile.createVariable('elevation', num.Float, ('number_of_points',)) 1301 1302 1302 1303 # Get handles to the variables … … 1315 1316 G = Geospatial_data(file_name = FN) 1316 1317 1317 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)1318 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)1319 1320 assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1321 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])1318 assert num.allclose(G.get_geo_reference().get_xllcorner(), 0.0) 1319 assert num.allclose(G.get_geo_reference().get_yllcorner(), 0.0) 1320 1321 assert num.allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1322 assert num.allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 1322 1323 os.remove(FN) 1323 1324 … … 1343 1344 1344 1345 # variable definitions 1345 outfile.createVariable('points', Float, ('number_of_points',1346 'number_of_dimensions'))1347 outfile.createVariable('elevation', Float, ('number_of_points',))1346 outfile.createVariable('points', num.Float, ('number_of_points', 1347 'number_of_dimensions')) 1348 outfile.createVariable('elevation', num.Float, ('number_of_points',)) 1348 1349 1349 1350 # Get handles to the variables … … 1362 1363 G = Geospatial_data(file_name = FN) 1363 1364 1364 assert allclose(G.get_geo_reference().get_xllcorner(), xll)1365 assert allclose(G.get_geo_reference().get_yllcorner(), yll)1366 1367 assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],1368 [0.0+xll, 1.0+yll],1369 [1.0+xll, 0.0+yll]])1370 1371 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])1365 assert num.allclose(G.get_geo_reference().get_xllcorner(), xll) 1366 assert num.allclose(G.get_geo_reference().get_yllcorner(), yll) 1367 1368 assert num.allclose(G.get_data_points(), [[1.0+xll, 0.0+yll], 1369 [0.0+xll, 1.0+yll], 1370 [1.0+xll, 0.0+yll]]) 1371 1372 assert num.allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 1372 1373 os.remove(FN) 1373 1374 … … 1380 1381 # create files 1381 1382 att_dict1 = {} 1382 pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1383 att_dict1['elevation'] = array([-10.0, 0.0, 10.4])1384 att_dict1['brightness'] = array([10.0, 0.0, 10.4])1383 pointlist1 = num.array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1384 att_dict1['elevation'] = num.array([-10.0, 0.0, 10.4]) 1385 att_dict1['brightness'] = num.array([10.0, 0.0, 10.4]) 1385 1386 geo_reference1 = Geo_reference(56, 2.0, 1.0) 1386 1387 1387 1388 att_dict2 = {} 1388 pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])1389 att_dict2['elevation'] = array([1.0, 15.0, 1.4])1390 att_dict2['brightness'] = array([14.0, 1.0, -12.4])1389 pointlist2 = num.array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]]) 1390 att_dict2['elevation'] = num.array([1.0, 15.0, 1.4]) 1391 att_dict2['brightness'] = num.array([14.0, 1.0, -12.4]) 1391 1392 geo_reference2 = Geo_reference(56, 1.0, 2.0) 1392 1393 … … 1412 1413 # print'res', G.get_data_points() 1413 1414 # print'res1', G.get_data_points(False) 1414 assert allclose(G.get_data_points(),1415 [[ 3.0, 1.0], [ 2.0, 2.0],1416 [ 3.0, 1.0], [ 3.0, 3.0],1417 [ 2.0, 4.0], [ 3.0, 3.0]])1415 assert num.allclose(G.get_data_points(), 1416 [[ 3.0, 1.0], [ 2.0, 2.0], 1417 [ 3.0, 1.0], [ 3.0, 3.0], 1418 [ 2.0, 4.0], [ 3.0, 3.0]]) 1418 1419 1419 assert allclose(G.get_attributes(attribute_name='elevation'),1420 [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4])1420 assert num.allclose(G.get_attributes(attribute_name='elevation'), 1421 [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4]) 1421 1422 1422 1423 answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4] 1423 assert allclose(G.get_attributes(attribute_name='brightness'), answer)1424 assert num.allclose(G.get_attributes(attribute_name='brightness'), answer) 1424 1425 1425 1426 self.failUnless(G.get_geo_reference() == geo_reference1, … … 1435 1436 new_points = ensure_absolute(points) 1436 1437 1437 assert allclose(new_points, points)1438 1439 points = array([[2.0, 0.0],[1.0, 1.0],1440 [2.0, 0.0],[2.0, 2.0],1441 [1.0, 3.0],[2.0, 2.0]])1438 assert num.allclose(new_points, points) 1439 1440 points = num.array([[2.0, 0.0],[1.0, 1.0], 1441 [2.0, 0.0],[2.0, 2.0], 1442 [1.0, 3.0],[2.0, 2.0]]) 1442 1443 new_points = ensure_absolute(points) 1443 1444 1444 assert allclose(new_points, points)1445 1446 ab_points = array([[2.0, 0.0],[1.0, 1.0],1447 [2.0, 0.0],[2.0, 2.0],1448 [1.0, 3.0],[2.0, 2.0]])1445 assert num.allclose(new_points, points) 1446 1447 ab_points = num.array([[2.0, 0.0],[1.0, 1.0], 1448 [2.0, 0.0],[2.0, 2.0], 1449 [1.0, 3.0],[2.0, 2.0]]) 1449 1450 1450 1451 mesh_origin = (56, 290000, 618000) #zone, easting, northing 1451 1452 1452 data_points = zeros((ab_points.shape),Float)1453 data_points = num.zeros((ab_points.shape), num.Float) 1453 1454 #Shift datapoints according to new origins 1454 1455 for k in range(len(ab_points)): … … 1461 1462 #print "ab_points",ab_points 1462 1463 1463 assert allclose(new_points, ab_points)1464 assert num.allclose(new_points, ab_points) 1464 1465 1465 1466 geo = Geo_reference(56,67,-56) … … 1471 1472 #print "ab_points",ab_points 1472 1473 1473 assert allclose(new_points, ab_points)1474 assert num.allclose(new_points, ab_points) 1474 1475 1475 1476 … … 1486 1487 #print "ab_points",ab_points 1487 1488 1488 assert allclose(new_points, ab_points)1489 assert num.allclose(new_points, ab_points) 1489 1490 1490 1491 … … 1496 1497 new_points = ensure_geospatial(points) 1497 1498 1498 assert allclose(new_points.get_data_points(absolute = True), points)1499 1500 points = array([[2.0, 0.0],[1.0, 1.0],1501 [2.0, 0.0],[2.0, 2.0],1502 [1.0, 3.0],[2.0, 2.0]])1499 assert num.allclose(new_points.get_data_points(absolute = True), points) 1500 1501 points = num.array([[2.0, 0.0],[1.0, 1.0], 1502 [2.0, 0.0],[2.0, 2.0], 1503 [1.0, 3.0],[2.0, 2.0]]) 1503 1504 new_points = ensure_geospatial(points) 1504 1505 1505 assert allclose(new_points.get_data_points(absolute = True), points)1506 1507 ab_points = array([[2.0, 0.0],[1.0, 1.0],1508 [2.0, 0.0],[2.0, 2.0],1509 [1.0, 3.0],[2.0, 2.0]])1506 assert num.allclose(new_points.get_data_points(absolute = True), points) 1507 1508 ab_points = num.array([[2.0, 0.0],[1.0, 1.0], 1509 [2.0, 0.0],[2.0, 2.0], 1510 [1.0, 3.0],[2.0, 2.0]]) 1510 1511 1511 1512 mesh_origin = (56, 290000, 618000) #zone, easting, northing 1512 1513 1513 data_points = zeros((ab_points.shape),Float)1514 data_points = num.zeros((ab_points.shape), num.Float) 1514 1515 #Shift datapoints according to new origins 1515 1516 for k in range(len(ab_points)): … … 1523 1524 #print "ab_points",ab_points 1524 1525 1525 assert allclose(new_points, ab_points)1526 assert num.allclose(new_points, ab_points) 1526 1527 1527 1528 geo = Geo_reference(56,67,-56) … … 1534 1535 #print "ab_points",ab_points 1535 1536 1536 assert allclose(new_points, ab_points)1537 assert num.allclose(new_points, ab_points) 1537 1538 1538 1539 … … 1550 1551 #print "ab_points",ab_points 1551 1552 1552 assert allclose(new_points, ab_points)1553 assert num.allclose(new_points, ab_points) 1553 1554 1554 1555 def test_isinstance(self): … … 1565 1566 1566 1567 results = Geospatial_data(fileName) 1567 assert allclose(results.get_data_points(absolute=True), \1568 [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1569 assert allclose(results.get_attributes(attribute_name='elevation'), \1570 [10.0, 0.0, 10.4])1571 assert allclose(results.get_attributes(attribute_name='speed'), \1572 [0.0, 10.0, 40.0])1568 assert num.allclose(results.get_data_points(absolute=True), 1569 [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1570 assert num.allclose(results.get_attributes(attribute_name='elevation'), 1571 [10.0, 0.0, 10.4]) 1572 assert num.allclose(results.get_attributes(attribute_name='speed'), 1573 [0.0, 10.0, 40.0]) 1573 1574 1574 1575 os.remove(fileName) … … 1602 1603 points = results.get_data_points() 1603 1604 1604 assert allclose(points[0][0], 308728.009)1605 assert allclose(points[0][1], 6180432.601)1606 assert allclose(points[1][0], 222908.705)1607 assert allclose(points[1][1], 6233785.284)1605 assert num.allclose(points[0][0], 308728.009) 1606 assert num.allclose(points[0][1], 6180432.601) 1607 assert num.allclose(points[1][0], 222908.705) 1608 assert num.allclose(points[1][1], 6233785.284) 1608 1609 1609 1610 … … 1623 1624 points = results.get_data_points() 1624 1625 1625 assert allclose(points[0][0], 308728.009)1626 assert allclose(points[0][1], 6180432.601)1627 assert allclose(points[1][0], 222908.705)1628 assert allclose(points[1][1], 6233785.284)1626 assert num.allclose(points[0][0], 308728.009) 1627 assert num.allclose(points[0][1], 6180432.601) 1628 assert num.allclose(points[1][0], 222908.705) 1629 assert num.allclose(points[1][1], 6233785.284) 1629 1630 1630 1631 … … 1663 1664 points = gsd.get_data_points(absolute=True) 1664 1665 1665 assert allclose(points[0][0], 308728.009)1666 assert allclose(points[0][1], 6180432.601)1667 assert allclose(points[1][0], 222908.705)1668 assert allclose(points[1][1], 6233785.284)1666 assert num.allclose(points[0][0], 308728.009) 1667 assert num.allclose(points[0][1], 6180432.601) 1668 assert num.allclose(points[1][0], 222908.705) 1669 assert num.allclose(points[1][1], 6233785.284) 1669 1670 self.failUnless(gsd.get_geo_reference().get_zone() == 56, 1670 1671 'Bad zone error!') … … 1716 1717 points = gsd.get_data_points(absolute=True) 1717 1718 1718 assert allclose(points[0][0], 308728.009)1719 assert allclose(points[0][1], 6180432.601)1720 assert allclose(points[1][0], 222908.705)1721 assert allclose(points[1][1], 6233785.284)1719 assert num.allclose(points[0][0], 308728.009) 1720 assert num.allclose(points[0][1], 6180432.601) 1721 assert num.allclose(points[1][0], 222908.705) 1722 assert num.allclose(points[1][1], 6233785.284) 1722 1723 self.failUnless(gsd.get_geo_reference().get_zone() == 56, 1723 1724 'Bad zone error!') … … 1771 1772 # and it changes from windows to linux 1772 1773 try: 1773 assert allclose(points[1][0], 308728.009)1774 assert allclose(points[1][1], 6180432.601)1775 assert allclose(points[0][0], 222908.705)1776 assert allclose(points[0][1], 6233785.284)1774 assert num.allclose(points[1][0], 308728.009) 1775 assert num.allclose(points[1][1], 6180432.601) 1776 assert num.allclose(points[0][0], 222908.705) 1777 assert num.allclose(points[0][1], 6233785.284) 1777 1778 except AssertionError: 1778 assert allclose(points[0][0], 308728.009)1779 assert allclose(points[0][1], 6180432.601)1780 assert allclose(points[1][0], 222908.705)1781 assert allclose(points[1][1], 6233785.284)1779 assert num.allclose(points[0][0], 308728.009) 1780 assert num.allclose(points[0][1], 6180432.601) 1781 assert num.allclose(points[1][0], 222908.705) 1782 assert num.allclose(points[1][1], 6233785.284) 1782 1783 1783 1784 self.failUnless(gsd.get_geo_reference().get_zone() == 56, … … 1786 1787 #print "test_lat_long_set points", points 1787 1788 try: 1788 assert allclose(points[0][0], -34)1789 assert allclose(points[0][1], 150)1789 assert num.allclose(points[0][0], -34) 1790 assert num.allclose(points[0][1], 150) 1790 1791 except AssertionError: 1791 assert allclose(points[1][0], -34)1792 assert allclose(points[1][1], 150)1792 assert num.allclose(points[1][0], -34) 1793 assert num.allclose(points[1][1], 150) 1793 1794 1794 1795 def test_len(self): … … 1829 1830 G1, G2 = G.split(factor,100) 1830 1831 1831 assert allclose(len(G), len(G1)+len(G2))1832 assert allclose(round(len(G)*factor), len(G1))1832 assert num.allclose(len(G), len(G1)+len(G2)) 1833 assert num.allclose(round(len(G)*factor), len(G1)) 1833 1834 1834 1835 P = G1.get_data_points(absolute=False) 1835 assert allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]])1836 assert num.allclose(P, [[5.0,4.0],[4.0,3.0],[4.0,2.0],[3.0,1.0],[2.0,3.0]]) 1836 1837 1837 1838 A = G1.get_attributes() 1838 assert allclose(A,[24, 18, 17, 11, 8])1839 assert num.allclose(A,[24, 18, 17, 11, 8]) 1839 1840 1840 1841 def test_split1(self): … … 1857 1858 1858 1859 # print 'G1',G1 1859 assert allclose(len(G), len(G1)+len(G2))1860 assert allclose(round(len(G)*factor), len(G1))1860 assert num.allclose(len(G), len(G1)+len(G2)) 1861 assert num.allclose(round(len(G)*factor), len(G1)) 1861 1862 1862 1863 P = G1.get_data_points(absolute=False) 1863 assert allclose(P, [[982420.,28233.]])1864 assert num.allclose(P, [[982420.,28233.]]) 1864 1865 1865 1866
Note: See TracChangeset
for help on using the changeset viewer.