@@ -237,13 +237,14 @@ def gray_from_float_rgba():
237
237
def test_light_source_topo_surface ():
238
238
"""Shades a DEM using different v.e.'s and blend modes."""
239
239
fname = cbook .get_sample_data ('jacksboro_fault_dem.npz' , asfileobj = False )
240
- with np .load (fname ) as dem :
241
- elev = dem ['elevation' ]
242
- # Get the true cellsize in meters for accurate vertical exaggeration
243
- # Convert from decimal degrees to meters
244
- dx , dy = dem ['dx' ], dem ['dy' ]
245
- dx = 111320.0 * dx * np .cos (dem ['ymin' ])
246
- dy = 111320.0 * dy
240
+ dem = np .load (fname )
241
+ elev = dem ['elevation' ]
242
+ # Get the true cellsize in meters for accurate vertical exaggeration
243
+ # Convert from decimal degrees to meters
244
+ dx , dy = dem ['dx' ], dem ['dy' ]
245
+ dx = 111320.0 * dx * np .cos (dem ['ymin' ])
246
+ dy = 111320.0 * dy
247
+ dem .close ()
247
248
248
249
ls = mcolors .LightSource (315 , 45 )
249
250
cmap = cm .gist_earth
@@ -307,7 +308,8 @@ def test_light_source_shading_default():
307
308
assert_array_almost_equal (rgb , expect , decimal = 2 )
308
309
309
310
310
- @knownfailureif (V (np .__version__ ) >= V ('1.9.0' ))
311
+ @knownfailureif (V (np .__version__ ) >= V ('1.9.0' ) or
312
+ V (np .__version__ ) < V ('1.7.0' ))
311
313
def test_light_source_masked_shading ():
312
314
"""Array comparison test for a surface with a masked portion. Ensures that
313
315
we don't wind up with "fringes" of odd colors around masked regions."""
@@ -371,7 +373,14 @@ def alternative_hillshade(azimuth, elev, z):
371
373
dy = - dy
372
374
dz = np .ones_like (dy )
373
375
normals = np .dstack ([dx , dy , dz ])
374
- normals /= np .linalg .norm (normals , axis = 2 )[..., None ]
376
+ dividers = np .zeros_like (z )[..., None ]
377
+ for i , mat in enumerate (normals ):
378
+ for j , vec in enumerate (mat ):
379
+ dividers [i , j , 0 ] = np .linalg .norm (vec )
380
+ normals /= dividers
381
+ # once we drop support for numpy 1.7.x the above can be written as
382
+ # normals /= np.linalg.norm(normals, axis=2)[..., None]
383
+ # aviding the double loop.
375
384
376
385
intensity = np .tensordot (normals , illum , axes = (2 , 0 ))
377
386
intensity -= intensity .min ()
0 commit comments