本文整理汇总了Python中matplotlib.colors.LightSource.hillshade方法的典型用法代码示例。如果您正苦于以下问题:Python LightSource.hillshade方法的具体用法?Python LightSource.hillshade怎么用?Python LightSource.hillshade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors.LightSource
的用法示例。
在下文中一共展示了LightSource.hillshade方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getShaded
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
def _getShaded(self,ptopo):
maxvalue = self.contour_colormap.vmax
ls1 = LightSource(azdeg = 120, altdeg = 45)
ls2 = LightSource(azdeg = 225, altdeg = 45)
intensity1 = ls1.hillshade(ptopo, fraction = 0.25, vert_exag = VERT_EXAG)
intensity2 = ls2.hillshade(ptopo, fraction = 0.25, vert_exag = VERT_EXAG)
intensity = intensity1*0.5 + intensity2*0.5
ptoposc = ptopo/maxvalue
rgba = self.contour_colormap.cmap(ptoposc)
rgb = np.squeeze(rgba)
draped_hsv = ls1.blend_hsv(rgb,np.expand_dims(intensity,2))
return draped_hsv
示例2: _getDraped
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
def _getDraped(self,data,topodata):
maxvalue = self.intensity_colormap.vmax
mmisc = data/maxvalue
rgba_img = self.intensity_colormap.cmap(mmisc)
rgb = np.squeeze(rgba_img[:,:,0:3])
#use lightsource class to make our shaded topography
ls = LightSource(azdeg=135,altdeg=45)
# intensity = ls.hillshade(ptopo,fraction=0.25,vert_exag=1.0)
ls1 = LightSource(azdeg = 120, altdeg = 45)
ls2 = LightSource(azdeg = 225, altdeg = 45)
intensity1 = ls1.hillshade(topodata, fraction = 0.25, vert_exag = VERT_EXAG)
intensity2 = ls2.hillshade(topodata, fraction = 0.25, vert_exag = VERT_EXAG)
intensity = intensity1*0.5 + intensity2*0.5
draped_hsv = ls.blend_hsv(rgb,np.expand_dims(intensity,2))
return draped_hsv
示例3: compare
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
def compare(z, cmap, ve=1):
# Create subplots and hide ticks
fig, axes = plt.subplots(ncols=2, nrows=2)
for ax in axes.flat:
ax.set(xticks=[], yticks=[])
# Illuminate the scene from the northwest
ls = LightSource(azdeg=315, altdeg=45)
axes[0, 0].imshow(z, cmap=cmap)
axes[0, 0].set(xlabel='Colormapped Data')
axes[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')
axes[0, 1].set(xlabel='Illumination Intensity')
rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv')
axes[1, 0].imshow(rgb)
axes[1, 0].set(xlabel='Blend Mode: "hsv" (default)')
rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay')
axes[1, 1].imshow(rgb)
axes[1, 1].set(xlabel='Blend Mode: "overlay"')
return fig
示例4: LightSource
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
dx, dy = dem['dx'], dem['dy']
dy = 111200 * dy
dx = 111200 * dx * np.cos(np.radians(dem['ymin']))
#-----------------------------------------------------------------------------
# Shade from the northwest, with the sun 45 degrees from horizontal
ls = LightSource(azdeg=315, altdeg=45)
cmap = plt.cm.gist_earth
fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(8, 9))
plt.setp(axes.flat, xticks=[], yticks=[])
# Vary vertical exaggeration and blend mode and plot all combinations
for col, ve in zip(axes.T, [0.1, 1, 10]):
# Show the hillshade intensity image in the first row
col[0].imshow(ls.hillshade(z, vert_exag=ve, dx=dx, dy=dy), cmap='gray')
# Place hillshaded plots with different blend modes in the rest of the rows
for ax, mode in zip(col[1:], ['hsv', 'overlay', 'soft']):
rgb = ls.shade(z, cmap=cmap, blend_mode=mode,
vert_exag=ve, dx=dx, dy=dy)
ax.imshow(rgb)
# Label rows and columns
for ax, ve in zip(axes[0], [0.1, 1, 10]):
ax.set_title('{}'.format(ve), size=18)
for ax, mode in zip(axes[:, 0], ['Hillshade', 'hsv', 'overlay', 'soft']):
ax.set_ylabel(mode, size=18)
# Group labels...
axes[0, 1].annotate('Vertical Exaggeration', (0.5, 1), xytext=(0, 30),
示例5: modelMap
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
def modelMap(grids, shakefile=None, suptitle=None, inventory_shapefile=None,
plotorder=None, maskthreshes=None, colormaps=None, boundaries=None,
zthresh=0, scaletype='continuous', lims=None, logscale=False,
ALPHA=0.7, maproads=True, mapcities=True, isScenario=False,
roadfolder=None, topofile=None, cityfile=None, oceanfile=None,
roadcolor='#6E6E6E', watercolor='#B8EEFF', countrycolor='#177F10',
outputdir=None, savepdf=True, savepng=True, showplots=False,
roadref='unknown', cityref='unknown', oceanref='unknown',
printparam=False, ds=True, dstype='mean', upsample=False):
"""
This function creates maps of mapio grid layers (e.g. liquefaction or
landslide models with their input layers)
All grids must use the same bounds
TO DO change so that all input layers do not have to have the same bounds,
test plotting multiple probability layers, and add option so that if PDF and
PNG aren't output, opens plot on screen using plt.show()
:param grids: Dictionary of N layers and metadata formatted like:
maplayers['layer name']={
'grid': mapio grid2D object,
'label': 'label for colorbar and top line of subtitle',
'type': 'output or input to model',
'description': 'detailed description of layer for subtitle'}.
Layer names must be unique.
:type name: Dictionary or Ordered dictionary - import collections;
grids = collections.OrderedDict()
:param shakefile: optional ShakeMap file (url or full file path) to extract information for labels and folder names
:type shakefile: Shakemap Event Dictionary
:param suptitle: This will be displayed at the top of the plots and in the
figure names
:type suptitle: string
:param plotorder: List of keys describing the order to plot the grids, if
None and grids is an ordered dictionary, it will use the order of the
dictionary, otherwise it will choose order which may be somewhat random
but it will always put a probability grid first
:type plotorder: list
:param maskthreshes: N x 1 array or list of lower thresholds for masking
corresponding to order in plotorder or order of OrderedDict if plotorder
is None. If grids is not an ordered dict and plotorder is not specified,
this will not work right. If None (default), nothing will be masked
:param colormaps: List of strings of matplotlib colormaps (e.g. cm.autumn_r)
corresponding to plotorder or order of dictionary if plotorder is None.
The list can contain both strings and None e.g. colormaps = ['cm.autumn',
None, None, 'cm.jet'] and None's will default to default colormap
:param boundaries: None to show entire study area, 'zoom' to zoom in on the
area of action (only works if there is a probability layer) using zthresh
as a threshold, or a dictionary defining lats and lons in the form of
boundaries.xmin = minlon, boundaries.xmax = maxlon, boundaries.ymin =
min lat, boundaries.ymax = max lat
:param zthresh: threshold for computing zooming bounds, only used if
boundaries = 'zoom'
:type zthresh: float
:param scaletype: Type of scale for plotting, 'continuous' or 'binned' -
will be reflected in colorbar
:type scaletype: string
:param lims: None or Nx1 list of tuples or numpy arrays corresponding to
plotorder defining the limits for saturating the colorbar (vmin, vmax) if
scaletype is continuous or the bins to use (clev) if scaletype if binned.
The list can contain tuples, arrays, and Nones, e.g. lims = [(0., 10.),
None, (0.1, 1.5), np.linspace(0., 1.5, 15)]. When None is specified, the
program will estimate the limits, when an array is specified but the scale
type is continuous, vmin will be set to min(array) and vmax will be set
to max(array)
:param lims: None or Nx1 list of Trues and Falses corresponding to
plotorder defining whether to use a linear or log scale (log10) for
plotting the layer. This will be reflected in the labels
:param ALPHA: Transparency for mapping, if there is a hillshade that will
plot below each layer, it is recommended to set this to at least 0.7
:type ALPHA: float
:param maproads: Whether to show roads or not, default True, but requires
that roadfile is specified and valid to work
:type maproads: boolean
:param mapcities: Whether to show cities or not, default True, but requires
that cityfile is specified and valid to work
:type mapcities: boolean
:param isScenario: Whether this is a scenario (True) or a real event (False)
(default False)
:type isScenario: boolean
:param roadfolder: Full file path to folder containing road shapefiles
:type roadfolder: string
:param topofile: Full file path to topography grid (GDAL compatible) - this
is only needed to make a hillshade if a premade hillshade is not specified
:type topofile: string
:param cityfile: Full file path to Pager file containing city & population
information
:type cityfile: string
:param roadcolor: Color to use for roads, if plotted, default #6E6E6E
:type roadcolor: Hex color or other matplotlib compatible way of defining
color
:param watercolor: Color to use for oceans, lakes, and rivers, default
#B8EEFF
:type watercolor: Hex color or other matplotlib compatible way of defining
color
:param countrycolor: Color for country borders, default #177F10
:type countrycolor: Hex color or other matplotlib compatible way of defining
color
:param outputdir: File path for outputting figures, if edict is defined, a
subfolder based on the event id will be created in this folder. If None,
will use current directory
:param savepdf: True to save pdf figure, False to not
#.........这里部分代码省略.........
示例6: LightSource
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
plt.show()
t=np.arange(-10,10.01,0.01)
x=np.cosh(t)
y=np.sin(t)
plt.fill_between(x,y, facecolor='y',linestyle='--')
plt.show()
x=np.arange(0.1,10.1,0.1)
y=np.arange(0.1,10.1,0.1)
X, Y = np.meshgrid(x, y)
Z=np.cos(X)*np.sin(Y)-np.log(X**2+Y**2)
plt.contour(X,Y,Z)
plt.show()
ls = LightSource(azdeg=0, altdeg=0)
plt.imshow(ls.hillshade(Z), cmap='gray')
plt.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z,rstride=1, cstride=1, cmap=cm.coolwarm,linewidth=0, antialiased=False)
plt.show()
x=np.arange(-10,11,1)
y=np.arange(-10,11,1)
X, Y = np.meshgrid(x, y)
plt.streamplot(x, y, -1+np.cos(X)+Y**2, np.sin(Y)-X**2)
plt.show()
u=np.arange(-10,10.1,0.1)
v=np.arange(-10,10.1,0.1)
U, V = np.meshgrid(u, v)
示例7: timer
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
start = timer()
hs_array = hillshade(arr, 315, 45)
end = timer()
print "naive hillshade took %dms" % (end - start)
dst.write(hs_array.astype(rasterio.int32), 1)
profile = src.profile
profile.update(
dtype=rasterio.uint8,
predictor=1,
nodata=None,
)
with rasterio.open("gt.tif", "w", **profile) as dst:
start = timer()
hs = gt_hillshade(arr, 315, 45, 0.05)
end = timer()
print "hillshade took %dms" % (end - start)
dst.write(hs, 1)
with rasterio.open("plt.tif", "w", **profile) as dst:
start = timer()
ls = LightSource()
hs = ls.hillshade(arr,
dx=dx,
dy=dy,
)
hs = (255.0 * hs).astype(np.uint8)
end = timer()
print "hillshade took %dms" % (end - start)
dst.write(hs, 1)
示例8: LightSource
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import hillshade [as 别名]
sparse_ok=True,
blockxsize=DST_BLOCK_SIZE,
blockysize=DST_BLOCK_SIZE,
height=DST_TILE_HEIGHT,
width=DST_TILE_WIDTH,
)
# Get the bounds of the tile.
ulx, uly = mercantile.xy(*mercantile.ul(tile.x, tile.y, tile.z))
lrx, lry = mercantile.xy(*mercantile.ul(tile.x + 1, tile.y + 1, tile.z))
meta["affine"] = src.window_transform(window)
ls = LightSource()
hs = ls.hillshade(data,
dx=dx,
dy=dy,
)
hs = (255.0 * hs).astype(np.uint8)
with rasterio.open("windowed.tif", "w", **meta) as dst:
# ignore the border pixels when writing
dst.write(hs[BUFFER:-BUFFER, BUFFER:-BUFFER], 1)
cdict = {
"red": [(0.0, 60 / 255.0, 60 / 255.0),
(1.0, 220 / 255.0, 220 / 255.0)],
"green": [(0.0, 75 / 255.0, 75 / 255.0),
(1.0, 1.0, 1.0)],
"blue": [(0.0, 80 / 255.0, 80 / 255.0),
(1.0, 100 / 255.0, 100 / 255.0)],
"alpha": [(0.0, 0.4, 0.4),