Skip to content

Commit

Permalink
Merge pull request #3661 from jenshnielsen/numpy_16_fixes
Browse files Browse the repository at this point in the history
TST : Numpy 1.6 fixes
  • Loading branch information
tacaswell committed Oct 17, 2014
2 parents 46a5603 + 244c1bb commit dbeed94
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/matplotlib/tests/test_colors.py
Expand Up @@ -237,13 +237,14 @@ def gray_from_float_rgba():
def test_light_source_topo_surface():
"""Shades a DEM using different v.e.'s and blend modes."""
fname = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
with np.load(fname) as dem:
elev = dem['elevation']
# Get the true cellsize in meters for accurate vertical exaggeration
# Convert from decimal degrees to meters
dx, dy = dem['dx'], dem['dy']
dx = 111320.0 * dx * np.cos(dem['ymin'])
dy = 111320.0 * dy
dem = np.load(fname)
elev = dem['elevation']
# Get the true cellsize in meters for accurate vertical exaggeration
# Convert from decimal degrees to meters
dx, dy = dem['dx'], dem['dy']
dx = 111320.0 * dx * np.cos(dem['ymin'])
dy = 111320.0 * dy
dem.close()

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


@knownfailureif(V(np.__version__) >= V('1.9.0'))
@knownfailureif(V(np.__version__) >= V('1.9.0') or
V(np.__version__) < V('1.7.0'))
def test_light_source_masked_shading():
"""Array comparison test for a surface with a masked portion. Ensures that
we don't wind up with "fringes" of odd colors around masked regions."""
Expand Down Expand Up @@ -371,7 +373,14 @@ def alternative_hillshade(azimuth, elev, z):
dy = -dy
dz = np.ones_like(dy)
normals = np.dstack([dx, dy, dz])
normals /= np.linalg.norm(normals, axis=2)[..., None]
dividers = np.zeros_like(z)[..., None]
for i, mat in enumerate(normals):
for j, vec in enumerate(mat):
dividers[i, j, 0] = np.linalg.norm(vec)
normals /= dividers
# once we drop support for numpy 1.7.x the above can be written as
# normals /= np.linalg.norm(normals, axis=2)[..., None]
# aviding the double loop.

intensity = np.tensordot(normals, illum, axes=(2, 0))
intensity -= intensity.min()
Expand Down

0 comments on commit dbeed94

Please sign in to comment.