@@ -1457,15 +1457,16 @@ def hsv_to_rgb(hsv):
1457
1457
1458
1458
return rgb
1459
1459
1460
+
1460
1461
class LightSource (object ):
1461
1462
"""
1462
1463
Create a light source coming from the specified azimuth and elevation.
1463
1464
Angles are in degrees, with the azimuth measured
1464
1465
clockwise from north and elevation up from the zero plane of the surface.
1465
1466
1466
1467
The :meth:`shade` is used to produce "shaded" rgb values for a data array.
1467
- :meth:`shade_rgb` can be used to combine an rgb image with
1468
- The :meth:`shade_rgb`
1468
+ :meth:`shade_rgb` can be used to combine an rgb image with
1469
+ The :meth:`shade_rgb`
1469
1470
The :meth:`hillshade` produces an illumination map of a surface.
1470
1471
"""
1471
1472
def __init__ (self , azdeg = 315 , altdeg = 45 , hsv_min_val = 0 , hsv_max_val = 1 ,
@@ -1486,7 +1487,7 @@ def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1,
1486
1487
1487
1488
Notes
1488
1489
-----
1489
- For backwards compatibility, the parameters *hsv_min_val*,
1490
+ For backwards compatibility, the parameters *hsv_min_val*,
1490
1491
*hsv_max_val*, *hsv_min_sat*, and *hsv_max_sat* may be supplied at
1491
1492
initialization as well. However, these parameters will only be used if
1492
1493
"blend_mode='hsv'" is passed into :meth:`shade` or :meth:`shade_rgb`.
@@ -1502,12 +1503,12 @@ def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1,
1502
1503
def hillshade (self , elevation , vert_exag = 1 , dx = 1 , dy = 1 , fraction = 1. ):
1503
1504
"""
1504
1505
Calculates the illumination intensity for a surface using the defined
1505
- azimuth and elevation for the light source.
1506
-
1506
+ azimuth and elevation for the light source.
1507
+
1507
1508
Imagine an artificial sun placed at infinity in some azimuth and
1508
1509
elevation position illuminating our surface. The parts of the surface
1509
1510
that slope toward the sun should brighten while those sides facing away
1510
- should become darker.
1511
+ should become darker.
1511
1512
1512
1513
Parameters
1513
1514
----------
@@ -1549,8 +1550,8 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
1549
1550
dy , dx = np .gradient (vert_exag * elevation , dy , dx )
1550
1551
slope = 0.5 * np .pi - np .arctan (np .hypot (dx , dy ))
1551
1552
aspect = np .arctan2 (dx , dy )
1552
- intensity = (np .sin (alt ) * np .sin (slope )
1553
- + np .cos (alt ) * np .cos (slope )
1553
+ intensity = (np .sin (alt ) * np .sin (slope )
1554
+ + np .cos (alt ) * np .cos (slope )
1554
1555
* np .cos (az - aspect ))
1555
1556
1556
1557
# Apply contrast stretch
@@ -1565,10 +1566,10 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
1565
1566
1566
1567
return intensity
1567
1568
1568
- def shade (self , data , cmap , norm = None , blend_mode = 'hsv' ,
1569
+ def shade (self , data , cmap , norm = None , blend_mode = 'hsv' ,
1569
1570
vert_exag = 1 , dx = 1 , dy = 1 , fraction = 1 , ** kwargs ):
1570
1571
"""
1571
- Combine colormapped data values with an illumination intensity map
1572
+ Combine colormapped data values with an illumination intensity map
1572
1573
(a.k.a. "hillshade") of the values.
1573
1574
1574
1575
Parameters
@@ -1587,7 +1588,7 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
1587
1588
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
1588
1589
The type of blending used to combine the colormapped data values
1589
1590
with the illumination intensity. For backwards compatibility, this
1590
- defaults to "hsv". Note that for most topographic surfaces,
1591
+ defaults to "hsv". Note that for most topographic surfaces,
1591
1592
"overlay" or "soft" appear more visually realistic. If a
1592
1593
user-defined function is supplied, it is expected to combine an
1593
1594
MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade
@@ -1610,8 +1611,8 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
1610
1611
full illumination or shadow (and clipping any values that move
1611
1612
beyond 0 or 1). Note that this is not visually or mathematically
1612
1613
the same as vertical exaggeration.
1613
- Additional kwargs are passed on to the *blend_mode* function.
1614
-
1614
+ Additional kwargs are passed on to the *blend_mode* function.
1615
+
1615
1616
Returns
1616
1617
-------
1617
1618
rgba : ndarray
@@ -1621,14 +1622,14 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
1621
1622
norm = Normalize (vmin = data .min (), vmax = data .max ())
1622
1623
1623
1624
rgb0 = cmap (norm (data ))
1624
- rgb1 = self .shade_rgb (rgb0 , elevation = data , blend_mode = blend_mode ,
1625
+ rgb1 = self .shade_rgb (rgb0 , elevation = data , blend_mode = blend_mode ,
1625
1626
vert_exag = vert_exag , dx = dx , dy = dy ,
1626
1627
fraction = fraction , ** kwargs )
1627
1628
# Don't overwrite the alpha channel, if present.
1628
1629
rgb0 [..., :3 ] = rgb1 [..., :3 ]
1629
1630
return rgb0
1630
1631
1631
- def shade_rgb (self , rgb , elevation , fraction = 1. , blend_mode = 'hsv' ,
1632
+ def shade_rgb (self , rgb , elevation , fraction = 1. , blend_mode = 'hsv' ,
1632
1633
vert_exag = 1 , dx = 1 , dy = 1 , ** kwargs ):
1633
1634
"""
1634
1635
Take the input RGB array (ny*nx*3) adjust their color values
@@ -1652,7 +1653,7 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
1652
1653
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
1653
1654
The type of blending used to combine the colormapped data values
1654
1655
with the illumination intensity. For backwards compatibility, this
1655
- defaults to "hsv". Note that for most topographic surfaces,
1656
+ defaults to "hsv". Note that for most topographic surfaces,
1656
1657
"overlay" or "soft" appear more visually realistic. If a
1657
1658
user-defined function is supplied, it is expected to combine an
1658
1659
MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade
@@ -1669,8 +1670,8 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
1669
1670
The x-spacing (columns) of the input *elevation* grid.
1670
1671
dy : number, optional
1671
1672
The y-spacing (rows) of the input *elevation* grid.
1672
- Additional kwargs are passed on to the *blend_mode* function.
1673
-
1673
+ Additional kwargs are passed on to the *blend_mode* function.
1674
+
1674
1675
Returns
1675
1676
-------
1676
1677
shaded_rgb : ndarray
@@ -1682,9 +1683,9 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
1682
1683
1683
1684
# Blend the hillshade and rgb data using the specified mode
1684
1685
lookup = {
1685
- 'hsv' :self .blend_hsv ,
1686
- 'soft' :self .blend_soft_light ,
1687
- 'overlay' :self .blend_overlay ,
1686
+ 'hsv' : self .blend_hsv ,
1687
+ 'soft' : self .blend_soft_light ,
1688
+ 'overlay' : self .blend_overlay ,
1688
1689
}
1689
1690
if blend_mode in lookup :
1690
1691
return lookup [blend_mode ](rgb , intensity , ** kwargs )
@@ -1794,7 +1795,7 @@ def blend_soft_light(self, rgb, intensity):
1794
1795
rgb : ndarray
1795
1796
An MxNx3 RGB array representing the combined images.
1796
1797
"""
1797
- return 2 * intensity * rgb + (1 - 2 * intensity ) * rgb ** 2
1798
+ return 2 * intensity * rgb + (1 - 2 * intensity ) * rgb ** 2
1798
1799
1799
1800
def blend_overlay (self , rgb , intensity ):
1800
1801
"""
@@ -1816,6 +1817,7 @@ def blend_overlay(self, rgb, intensity):
1816
1817
high = 1 - 2 * (1 - intensity ) * (1 - rgb )
1817
1818
return np .where (rgb <= 0.5 , low , high )
1818
1819
1820
+
1819
1821
def from_levels_and_colors (levels , colors , extend = 'neither' ):
1820
1822
"""
1821
1823
A helper routine to generate a cmap and a norm instance which
0 commit comments