示例#1
0
def main():

    fig, ax = plt.subplots(3, 2, figsize=(7, 10))
    fig.tight_layout()    

    if 1:
        # Same terrain and data.
        data = make_test_data('circles', noise_factor=0.05) * 2 - 7
        terrain = data
    else:
        # Different terrain and data. Matplotlib hill shading can only show the data.
        data = make_test_data('hills') * -1
        terrain = make_test_data('circles', noise_factor=0.05) * 2
        
    assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape)
    print("data range: {} {}".format(np.min(data), np.max(data)))
    
    if len(sys.argv) > 1:
        cmap_name = sys.argv[1]
    else:
        #cmap_name = 'copper' # from http://matplotlib.org/examples/pylab_examples/shading_example.html?highlight=codex%20shade
        #cmap_name = 'gist_earth' # works reasonably fine with all of them
        cmap_name = 'bwr'        # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'cubehelix'  # shows that HSV blending does not work were color is black
        #cmap_name = 'rainbow'    # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'Paired_r'   # is nice to inspect when the data is different from the terrain
        
    print ("Using colormap: {!r}".format(cmap_name))
    cmap = plt.cm.get_cmap(cmap_name)
    cmap.set_bad('cyan')
    cmap.set_over('cyan')
    cmap.set_under('cyan')
    
    abs_max = np.max(np.abs(data)) # force color bar to be symmetrical. 
    norm = mpl.colors.Normalize(vmin=-abs_max, vmax=abs_max)
    #norm = mpl.colors.Normalize(vmin=-2, vmax=3)
    
    draw(ax[0, 0], cmap=cmap, norm=norm, title='No shading', 
         image_data = data)

    draw(ax[0, 1], cmap=plt.cm.gray, title='Matplotlib intensity', 
         image_data = mpl_surface_intensity(terrain))

    ls = LightSource(azdeg=DEF_AZIMUTH, altdeg=DEF_ELEVATION)
    draw(ax[1, 0], cmap=cmap, norm=norm, title='Matplotlib hill shading', 
         image_data = ls.shade(data, cmap=cmap, norm=norm))
    
    draw(ax[1, 1], cmap=cmap, norm=norm, title='Pegtop blending', 
         image_data = mpl_hill_shade(data, terrain=terrain,  
                                     cmap=cmap, norm=norm, blend_function=pegtop_blending))
    
    draw(ax[2, 0], cmap=cmap, norm=norm, title='RGB blending', 
         image_data = mpl_hill_shade(data, terrain=terrain, 
                                     cmap=cmap, norm=norm, blend_function=rgb_blending))    
    
    draw(ax[2, 1], cmap=cmap, norm=norm, title='HSV blending', 
         image_data = mpl_hill_shade(data, terrain=terrain, 
                                     cmap=cmap, norm=norm, blend_function=hsv_blending))    

    plt.show()
示例#2
0
def main():
    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    fig.tight_layout()

    data = make_test_data('circles')
    terrain = 10 * make_test_data('hills', noise_factor=0.05)
    assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape)
    print("min data: {}".format(np.min(data)))
    print("max data: {}".format(np.max(data)))

    # Some color maps to try.
    #cmap = plt.cm.get_cmap('bwr')
    #cmap = plt.cm.get_cmap('CMRmap')
    #cmap = plt.cm.get_cmap('rainbow')
    #cmap = plt.cm.get_cmap('cool_r')
    cmap = plt.cm.get_cmap('Set1')
    
    # Optionally set the over and under flow colors.
    #cmap.set_bad('yellow')
    #cmap.set_over('cyan')
    #cmap.set_under('magenta')
         
    if ['--autoscale'] in sys.argv:
        print ("Auto scale legend")
        dnorm = mpl.colors.Normalize()
    else:
        dmin = 0
        dmax = 10
        print ("clip legend at ({}, {})".format(dmin, dmax))
        dnorm = mpl.colors.Normalize(vmin=dmin, vmax=dmax)
        
    # Don't auto scale the intensities, it gives the wrong impression
    inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)
            
    azimuth = DEF_AZIMUTH 
    elevation = DEF_ELEVATION

    draw(ax[0, 0], cmap=plt.cm.gist_earth, title='Terrain height', 
         image_data = terrain)

    draw(ax[0, 1], cmap=INTENSITY_CMAP, norm=inorm, 
         title='Shaded terrain (azim = {}, elev = {})'.format(azimuth, elevation), 
         image_data = hill_shade(terrain, blend_function=no_blending, 
                                 azimuth=azimuth, elevation=elevation)) 

    draw(ax[1, 0], cmap=cmap, norm=dnorm, title='Surface properties', 
         image_data = data)
    
    draw(ax[1, 1], cmap=cmap, norm=dnorm, title='Shaded terrain with surface properties', 
         image_data = hill_shade(data, terrain=terrain,
                                 azimuth=azimuth, elevation=elevation, 
                                 cmap=cmap, norm=dnorm))
    plt.show()
示例#3
0
def main():
    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    fig.tight_layout()

    data = -25 * make_test_data('hills',
                                noise_factor=0.025)  # secretly swapped :-)
    #data = -25 * make_test_data('circles', noise_factor=0.025) # secretly swapped :-)
    terrain = data
    assert terrain.shape == data.shape, "{} != {}".format(
        terrain.shape, data.shape)

    if '--bw' in sys.argv:
        # Only intensities
        blend_function = no_blending
        cmap = INTENSITY_CMAP

        # Don't auto scale the intensities, it gives the wrong impression
        norm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)
    else:
        blend_function = rgb_blending
        cmap = plt.cm.get_cmap('gist_earth')
        norm = mpl.colors.Normalize()

    azimuths = [45, 135, 270]  # North-East, North-West and South.
    elevations = [60] * len(azimuths)

    # Draw shading by separate light sources
    for idx, (azim, elev) in enumerate(zip(azimuths, elevations)):
        row = idx // 2
        col = idx % 2
        draw(ax[row, col],
             cmap=cmap,
             norm=norm,
             title='azim = {}, elev = {}'.format(azim, elev),
             image_data=hill_shade(data,
                                   terrain,
                                   blend_function=blend_function,
                                   ambient_weight=1,
                                   lamp_weight=5,
                                   cmap=cmap,
                                   norm=norm,
                                   azimuth=azim,
                                   elevation=elev))

    # Draw shading by all light sources combined
    draw(ax[1, 1],
         cmap=cmap,
         norm=norm,
         title='combined'.format(azim, elev),
         image_data=hill_shade(data,
                               terrain,
                               blend_function=blend_function,
                               ambient_weight=1,
                               lamp_weight=[5, 5, 5],
                               cmap=cmap,
                               norm=norm,
                               azimuth=azimuths,
                               elevation=elevations))

    plt.show()
示例#4
0
def main():
    fig, axes = plt.subplots(1, 1)

    # Generate terrain of 200 by 200 km, height between -2.25 and 5.7 km
    data = make_test_data('hills', noise_factor=0.05) / 2 + 2
    print("data range: {} {}".format(np.min(data), np.max(data)))

    cmap = plt.cm.get_cmap('gist_earth')
    vmin, vmax = -5, 5  # scale clip color map between -5, 5

    rgb = hill_shade(
        data,
        terrain=data * 5,  # scale terrain height to make relief visible 
        #azimuth=90, elevation=60,        # un-comment to use non-default values
        #ambient_weight=0, lamp_weight=5, # un-comment to use non-default values
        cmap=cmap,
        vmin=vmin,
        vmax=vmax)

    axes.imshow(rgb, norm=None, origin='lower')
    add_colorbar(axes,
                 label='Terrain height [km]',
                 cmap=cmap,
                 vmin=vmin,
                 vmax=vmax)
    axes.set_xlabel('[km]')
    axes.set_ylabel('[km]')

    fig.tight_layout()
    plt.show()
def main():

    fig, ax = plt.subplots(3, 4, figsize=(15, 10))
    fig.tight_layout()
    
    #terrain = make_test_data('circles', noise_factor=0.0)
    terrain = make_test_data('hills', noise_factor=0.1)

    # Scale terrain. 
    terrain *= 5

    # Don't auto scale the intensities, it gives the wrong impression
    inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)

    # Draw the terrain as color map
    draw(ax[0, 0], cmap=plt.cm.gist_earth, title='No shading', ticks=True,  
         image_data = terrain)
    
    # Draw empty space
    ax[1, 0].set_axis_off()
    ax[2, 0].set_axis_off()
    
    cmap = INTENSITY_CMAP
    azim0_is_east = True # If true, azimuth 0 will correspond to east just as in our implementation
    azimuths = [45, 90, 135]
    #elev = 50
    
    # At low elevation you will see still noise bumps in places that are completely in the shadows.
    # This may seem nice but it is incorrect.
    elev = 15 
    
    for idx, azim in enumerate(azimuths):
        col = idx + 1
        
        draw(ax[0, col], cmap=cmap, norm=inorm, 
             title="MPL normalized (azim = {}, elev = {})".format(azim, elev),  
             image_data = mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, 
                                               azim0_is_east=azim0_is_east, normalize=True))
           
        draw(ax[1, col], cmap=cmap, norm=inorm, 
             title="MPL (azim = {}, elev = {})".format(azim, elev), 
             image_data = mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, 
                                               azim0_is_east=azim0_is_east, normalize=False))   
        
        draw(ax[2, col], cmap=cmap, norm=inorm, 
             title="Diffuse (azim = {}, elev = {})".format(azim, elev), 
             image_data = relative_surface_intensity(terrain, azimuth=azim, elevation=elev))

    plt.show()
def main():
    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    fig.tight_layout()

    data = -25 * make_test_data('hills', noise_factor=0.025) # secretly swapped :-)
    #data = -25 * make_test_data('circles', noise_factor=0.025) # secretly swapped :-)
    terrain = data
    assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape)
    
    if '--bw' in sys.argv:
        # Only intensities
        blend_function = no_blending
        cmap=INTENSITY_CMAP
        
        # Don't auto scale the intensities, it gives the wrong impression
        norm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)
    else:
        blend_function = rgb_blending
        cmap = plt.cm.get_cmap('gist_earth')
        norm = mpl.colors.Normalize()
    
    azimuths = [45, 135, 270] # North-East, North-West and South.
    elevations = [60] * len(azimuths)
    
    # Draw shading by separate light sources
    for idx, (azim, elev) in enumerate(zip(azimuths, elevations)):
        row = idx // 2
        col = idx % 2
        draw(ax[row, col], cmap=cmap, norm=norm, 
             title='azim = {}, elev = {}'.format(azim, elev), 
             image_data = hill_shade(data, terrain, blend_function=blend_function, 
                                     ambient_weight = 1, lamp_weight = 5,
                                     cmap=cmap, norm=norm,  
                                     azimuth=azim, elevation=elev))
    
    # Draw shading by all light sources combined 
    draw(ax[1, 1], cmap=cmap, norm=norm, 
         title='combined'.format(azim, elev), 
         image_data = hill_shade(data, terrain, blend_function=blend_function, 
                                 ambient_weight = 1, lamp_weight = [5, 5, 5],
                                 cmap=cmap, norm=norm,  
                                 azimuth=azimuths, elevation=elevations))

    plt.show()
示例#7
0
def main():
    fig, axes = plt.subplots(1, 1) 
    
    # Generate terrain of 200 by 200 km, height between -2.25 and 5.7 km
    data = make_test_data('hills', noise_factor=0.05) / 2 + 2 
    print("data range: {} {}".format(np.min(data), np.max(data)))
    
    cmap=plt.cm.get_cmap('gist_earth')
    vmin, vmax = -5, 5  # scale clip color map between -5, 5
    
    rgb = hill_shade(data, terrain=data * 5, # scale terrain height to make relief visible 
                     #azimuth=90, elevation=60,        # un-comment to use non-default values
                     #ambient_weight=0, lamp_weight=5, # un-comment to use non-default values
                     cmap=cmap, vmin=vmin, vmax=vmax)
        
    axes.imshow(rgb, norm=None, origin='lower')
    add_colorbar(axes, label='Terrain height [km]', cmap=cmap, vmin=vmin, vmax=vmax)
    axes.set_xlabel('[km]')
    axes.set_ylabel('[km]')

    fig.tight_layout()
    plt.show()
示例#8
0
def main():

    fig, ax = plt.subplots(3, 2, figsize=(7, 10))
    fig.tight_layout()

    if 1:
        # Same terrain and data.
        data = make_test_data('circles', noise_factor=0.05) * 2 - 7
        terrain = data
    else:
        # Different terrain and data. Matplotlib hill shading can only show the data.
        data = make_test_data('hills') * -1
        terrain = make_test_data('circles', noise_factor=0.05) * 2

    assert terrain.shape == data.shape, "{} != {}".format(
        terrain.shape, data.shape)
    print("data range: {} {}".format(np.min(data), np.max(data)))

    if len(sys.argv) > 1:
        cmap_name = sys.argv[1]
    else:
        #cmap_name = 'copper' # from http://matplotlib.org/examples/pylab_examples/shading_example.html?highlight=codex%20shade
        #cmap_name = 'gist_earth' # works reasonably fine with all of them
        cmap_name = 'bwr'  # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'cubehelix'  # shows that HSV blending does not work were color is black
        #cmap_name = 'rainbow'    # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'Paired_r'   # is nice to inspect when the data is different from the terrain

    print("Using colormap: {!r}".format(cmap_name))
    cmap = plt.cm.get_cmap(cmap_name)
    cmap.set_bad('cyan')
    cmap.set_over('cyan')
    cmap.set_under('cyan')

    abs_max = np.max(np.abs(data))  # force color bar to be symmetrical.
    norm = mpl.colors.Normalize(vmin=-abs_max, vmax=abs_max)
    #norm = mpl.colors.Normalize(vmin=-2, vmax=3)

    draw(ax[0, 0], cmap=cmap, norm=norm, title='No shading', image_data=data)

    draw(ax[0, 1],
         cmap=plt.cm.gray,
         title='Matplotlib intensity',
         image_data=mpl_surface_intensity(terrain))

    ls = LightSource(azdeg=DEF_AZIMUTH, altdeg=DEF_ELEVATION)
    draw(ax[1, 0],
         cmap=cmap,
         norm=norm,
         title='Matplotlib hill shading',
         image_data=ls.shade(data, cmap=cmap, norm=norm))

    draw(ax[1, 1],
         cmap=cmap,
         norm=norm,
         title='Pegtop blending',
         image_data=mpl_hill_shade(data,
                                   terrain=terrain,
                                   cmap=cmap,
                                   norm=norm,
                                   blend_function=pegtop_blending))

    draw(ax[2, 0],
         cmap=cmap,
         norm=norm,
         title='RGB blending',
         image_data=mpl_hill_shade(data,
                                   terrain=terrain,
                                   cmap=cmap,
                                   norm=norm,
                                   blend_function=rgb_blending))

    draw(ax[2, 1],
         cmap=cmap,
         norm=norm,
         title='HSV blending',
         image_data=mpl_hill_shade(data,
                                   terrain=terrain,
                                   cmap=cmap,
                                   norm=norm,
                                   blend_function=hsv_blending))

    plt.show()
示例#9
0
def main():

    fig, ax = plt.subplots(3, 4, figsize=(15, 10))
    fig.tight_layout()

    #terrain = make_test_data('circles', noise_factor=0.0)
    terrain = make_test_data('hills', noise_factor=0.1)

    # Scale terrain.
    terrain *= 5

    # Don't auto scale the intensities, it gives the wrong impression
    inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)

    # Draw the terrain as color map
    draw(ax[0, 0],
         cmap=plt.cm.gist_earth,
         title='No shading',
         ticks=True,
         image_data=terrain)

    # Draw empty space
    ax[1, 0].set_axis_off()
    ax[2, 0].set_axis_off()

    cmap = INTENSITY_CMAP
    azim0_is_east = True  # If true, azimuth 0 will correspond to east just as in our implementation
    azimuths = [45, 90, 135]
    #elev = 50

    # At low elevation you will see still noise bumps in places that are completely in the shadows.
    # This may seem nice but it is incorrect.
    elev = 15

    for idx, azim in enumerate(azimuths):
        col = idx + 1

        draw(ax[0, col],
             cmap=cmap,
             norm=inorm,
             title="MPL normalized (azim = {}, elev = {})".format(azim, elev),
             image_data=mpl_surface_intensity(terrain,
                                              azimuth=azim,
                                              elevation=elev,
                                              azim0_is_east=azim0_is_east,
                                              normalize=True))

        draw(ax[1, col],
             cmap=cmap,
             norm=inorm,
             title="MPL (azim = {}, elev = {})".format(azim, elev),
             image_data=mpl_surface_intensity(terrain,
                                              azimuth=azim,
                                              elevation=elev,
                                              azim0_is_east=azim0_is_east,
                                              normalize=False))

        draw(ax[2, col],
             cmap=cmap,
             norm=inorm,
             title="Diffuse (azim = {}, elev = {})".format(azim, elev),
             image_data=relative_surface_intensity(terrain,
                                                   azimuth=azim,
                                                   elevation=elev))

    plt.show()
def main():
    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    fig.tight_layout()

    data = make_test_data('circles')
    terrain = 10 * make_test_data('hills', noise_factor=0.05)
    assert terrain.shape == data.shape, "{} != {}".format(
        terrain.shape, data.shape)
    print("min data: {}".format(np.min(data)))
    print("max data: {}".format(np.max(data)))

    # Some color maps to try.
    #cmap = plt.cm.get_cmap('bwr')
    #cmap = plt.cm.get_cmap('CMRmap')
    #cmap = plt.cm.get_cmap('rainbow')
    #cmap = plt.cm.get_cmap('cool_r')
    cmap = plt.cm.get_cmap('Set1')

    # Optionally set the over and under flow colors.
    #cmap.set_bad('yellow')
    #cmap.set_over('cyan')
    #cmap.set_under('magenta')

    if ['--autoscale'] in sys.argv:
        print("Auto scale legend")
        dnorm = mpl.colors.Normalize()
    else:
        dmin = 0
        dmax = 10
        print("clip legend at ({}, {})".format(dmin, dmax))
        dnorm = mpl.colors.Normalize(vmin=dmin, vmax=dmax)

    # Don't auto scale the intensities, it gives the wrong impression
    inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0)

    azimuth = DEF_AZIMUTH
    elevation = DEF_ELEVATION

    draw(ax[0, 0],
         cmap=plt.cm.gist_earth,
         title='Terrain height',
         image_data=terrain)

    draw(ax[0, 1],
         cmap=INTENSITY_CMAP,
         norm=inorm,
         title='Shaded terrain (azim = {}, elev = {})'.format(
             azimuth, elevation),
         image_data=hill_shade(terrain,
                               blend_function=no_blending,
                               azimuth=azimuth,
                               elevation=elevation))

    draw(ax[1, 0],
         cmap=cmap,
         norm=dnorm,
         title='Surface properties',
         image_data=data)

    draw(ax[1, 1],
         cmap=cmap,
         norm=dnorm,
         title='Shaded terrain with surface properties',
         image_data=hill_shade(data,
                               terrain=terrain,
                               azimuth=azimuth,
                               elevation=elevation,
                               cmap=cmap,
                               norm=dnorm))
    plt.show()