Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbeed94

Browse files
committed
Merge pull request #3661 from jenshnielsen/numpy_16_fixes
TST : Numpy 1.6 fixes
2 parents 46a5603 + 244c1bb commit dbeed94

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/matplotlib/tests/test_colors.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ def gray_from_float_rgba():
237237
def test_light_source_topo_surface():
238238
"""Shades a DEM using different v.e.'s and blend modes."""
239239
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()
247248

248249
ls = mcolors.LightSource(315, 45)
249250
cmap = cm.gist_earth
@@ -307,7 +308,8 @@ def test_light_source_shading_default():
307308
assert_array_almost_equal(rgb, expect, decimal=2)
308309

309310

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'))
311313
def test_light_source_masked_shading():
312314
"""Array comparison test for a surface with a masked portion. Ensures that
313315
we don't wind up with "fringes" of odd colors around masked regions."""
@@ -371,7 +373,14 @@ def alternative_hillshade(azimuth, elev, z):
371373
dy = -dy
372374
dz = np.ones_like(dy)
373375
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.
375384

376385
intensity = np.tensordot(normals, illum, axes=(2, 0))
377386
intensity -= intensity.min()

0 commit comments

Comments
 (0)