MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / hillshade

Method hillshade

lib/matplotlib/colors.py:3861–3912  ·  view source on GitHub ↗

Calculate the illumination intensity for a surface using the defined azimuth and elevation for the light source. This computes the normal vectors for the surface, and then passes them on to `shade_normals` Parameters ---------- elevation : 2

(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.)

Source from the content-addressed store, hash-verified

3859 ])
3860
3861 def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
3862 """
3863 Calculate the illumination intensity for a surface using the defined
3864 azimuth and elevation for the light source.
3865
3866 This computes the normal vectors for the surface, and then passes them
3867 on to `shade_normals`
3868
3869 Parameters
3870 ----------
3871 elevation : 2D array-like
3872 The height values used to generate an illumination map
3873 vert_exag : number, optional
3874 The amount to exaggerate the elevation values by when calculating
3875 illumination. This can be used either to correct for differences in
3876 units between the x-y coordinate system and the elevation
3877 coordinate system (e.g. decimal degrees vs. meters) or to
3878 exaggerate or de-emphasize topographic effects.
3879 dx : number, optional
3880 The x-spacing (columns) of the input *elevation* grid.
3881 dy : number, optional
3882 The y-spacing (rows) of the input *elevation* grid.
3883 fraction : number, optional
3884 Increases or decreases the contrast of the hillshade. Values
3885 greater than one will cause intermediate values to move closer to
3886 full illumination or shadow (and clipping any values that move
3887 beyond 0 or 1). Note that this is not visually or mathematically
3888 the same as vertical exaggeration.
3889
3890 Returns
3891 -------
3892 `~numpy.ndarray`
3893 A 2D array of illumination values between 0-1, where 0 is
3894 completely in shadow and 1 is completely illuminated.
3895 """
3896
3897 # Because most image and raster GIS data has the first row in the array
3898 # as the "top" of the image, dy is implicitly negative. This is
3899 # consistent to what `imshow` assumes, as well.
3900 dy = -dy
3901
3902 # compute the normal vectors from the partial derivatives
3903 e_dy, e_dx = np.gradient(vert_exag * elevation, dy, dx)
3904
3905 # .view is to keep subclasses
3906 normal = np.empty(elevation.shape + (3,)).view(type(elevation))
3907 normal[..., 0] = -e_dx
3908 normal[..., 1] = -e_dy
3909 normal[..., 2] = 1
3910 normal /= _vector_magnitude(normal)
3911
3912 return self.shade_normals(normal, fraction)
3913
3914 def shade_normals(self, normals, fraction=1.):
3915 """

Callers 5

shade_rgbMethod · 0.95
compareFunction · 0.95

Calls 3

shade_normalsMethod · 0.95
_vector_magnitudeFunction · 0.85
gradientMethod · 0.45