Exemplo n.º 1
0
def test_hillshade_altitude(hillshade_arr):
    """An altitude value >90 returns a ValueError."""

    # Check ValueError
    with pytest.raises(
            ValueError,
            match="Altitude value should be less than or equal to 90 degrees",
    ):
        es.hillshade(hillshade_arr, azimuth=315, angle_altitude=100)
Exemplo n.º 2
0
def test_hillshade_azimuth(hillshade_arr):
    """An azimuth value >360 returns a ValueError."""

    # Check ValueError
    with pytest.raises(
            ValueError,
            match="Azimuth value should be less than or equal to 360 degrees",
    ):
        es.hillshade(hillshade_arr, azimuth=375, angle_altitude=45)
Exemplo n.º 3
0
def test_hillshade_shape(hillshade_arr):
    """A 3-dimensional array should return a ValueError."""

    # Test 3-dimensional array
    hillshade_arr_3d = hillshade_arr[np.newaxis, :]

    # Check ValueError
    with pytest.raises(ValueError,
                       match="Input array should be two-dimensional"):
        es.hillshade(hillshade_arr_3d, azimuth=315, angle_altitude=45)
Exemplo n.º 4
0
def test_hillshade_result(hillshade_arr, hillshade_result):
    """Returned array using hillshade_arr as input should equal
    hillshade_result."""

    # Tolerance used for floating point numbers
    assert np.allclose(
        es.hillshade(hillshade_arr, azimuth=315, angle_altitude=45),
        hillshade_result,
        atol=1e-10,
        rtol=1e-10,
    )
Exemplo n.º 5
0
def fshade(DEM_path, azimuth, altitude, out_folder, name="shade"):
    elevation = tf.imread(DEM_path)
    elevation_array = np.array(elevation).astype(np.float32)
    #Divided by 255 to standardize from hillshade scale (0-255) to 0-1 scale
    result_shade = es.hillshade(elevation_array, azimuth, altitude) / 255

    result_shade_path = os.path.join(out_folder, name + ".TIF")

    fGeoref(result_shade, DEM_path, result_shade_path)

    #tf.imsave(result_shade_path, result_shade)
    return result_shade_path
Exemplo n.º 6
0
ep.plot_bands(
    elevation,
    scale=False,
    cmap="gist_earth",
    title="DTM Without Hillshade",
    figsize=(10, 6),
)
plt.show()

####################################################################################
# Create the Hillshade
# --------------------
# Once the DEM is read in, call ``es.hillshade()`` to create the hillshade.

# Create and plot the hillshade with earthpy
hillshade = es.hillshade(elevation)

ep.plot_bands(
    hillshade,
    scale=False,
    cbar=False,
    title="Hillshade made from DTM",
    figsize=(10, 6),
)
plt.show()

####################################################################################
# Change the Azimuth of the Sun
# -------------------------------
# The angle that sun light hits the landscape, impacts the shadows and highlights
# created on the landscape. You can adjust the azimuth values to adjust angle of the
dest_dir = 'Hillshaded'
file_list = glob.glob(os.path.join(data_dir, '*.tif'))

for file in file_list:
    with rio.open(file) as src:
        elevation = src.read(1)
        dim = (src.width * src.height) // 2
        # If masked values are less than half of the total num of pixels
        if np.sum(elevation < 0) < dim:
            # Set masked values to np.nan
            elevation[elevation < 0] = np.nan
            # Get metadata of TIFF file
            dtm_meta = src.meta
            dtm_meta.update(dtype=rio.float32)
            for x in azimuths:
                hillshade = es.hillshade(elevation, azimuth=x, altitude=altitude)

                dest = dest_dir + '/' + str(x)
                write_file(dest, file, dtm_meta, hillshade)

print('Processor Time: ', time.clock() - start_time, 'seconds')
print('Wall Time: ', time.time() - start_time, 'seconds')

# Checking output of one tile
for x in azimuths:
    filename = 'Hillshaded/' + str(x) + '/Tiled Ilocos.100.tif'
    with rio.open(filename) as src:
        hillshade = src.read(1)

    title = 'Azimuth = ' + str(x)
    ep.plot_bands(