Skip to content

mounts module

Module for delineating the nested hierarchy of elevated features (i.e., mounts).

DelineateMounts(in_dem, min_size, min_height, interval, out_dir, bool_shp=False)

Delineates the nested hierarchy of elevated features (i.e., mounts).

Parameters:

Name Type Description Default
in_dem str

File path to the input DEM.

required
min_size int

The minimum number of pixels to be considered as an object.

required
min_height float

The minimum depth of the feature to be considered as an object.

required
interval float

The slicing interval.

required
out_dir str

The output directory.

required
bool_shp bool

Whether to generate shapefiles. Defaults to False.

False

Returns:

Name Type Description
tuple

File paths to the depression ID and level.

Source code in lidar/mounts.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def DelineateMounts(in_dem, min_size, min_height, interval, out_dir, bool_shp=False):
    """Delineates the nested hierarchy of elevated features (i.e., mounts).

    Args:
        in_dem (str): File path to the input DEM.
        min_size (int): The minimum number of pixels to be considered as an object.
        min_height (float): The minimum depth of the feature to be considered as an object.
        interval (float): The slicing interval.
        out_dir (str): The output directory.
        bool_shp (bool, optional): Whether to generate shapefiles. Defaults to False.

    Returns:
        tuple: File paths to the depression ID and level.
    """
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)

    print("Loading data ...")
    dem = rd.LoadGDAL(in_dem)
    # projection = dem.projection
    geotransform = dem.geotransform
    cell_size = np.round(geotransform[1], decimals=3)

    out_dem = os.path.join(out_dir, "dem_flip.tif")
    in_dem = FlipDEM(dem, delta=100, out_file=out_dem)

    min_elev, max_elev, no_data = get_min_max_nodata(dem)
    print(
        "min = {:.2f}, max = {:.2f}, no_data = {}, cell_size = {}".format(
            min_elev, max_elev, no_data, cell_size
        )
    )

    sink_path = ExtractSinks(in_dem, min_size, out_dir)
    dep_id_path, dep_level_path = DelineateDepressions(
        sink_path, min_size, min_height, interval, out_dir, bool_shp
    )

    return dep_id_path, dep_level_path

FlipDEM(dem, delta=100, out_file=None)

Flips the DEM.

Parameters:

Name Type Description Default
dem array

The numpy array containing the image.

required
delta int

The base value to be added to the flipped DEM. Defaults to 100.

100
out_file str

File path to the output image. Defaults to None.

None

Returns:

Type Description

np.array: The numpy array containing the flipped DEM.

Source code in lidar/mounts.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def FlipDEM(dem, delta=100, out_file=None):
    """Flips the DEM.

    Args:
        dem (np.array): The numpy array containing the image.
        delta (int, optional): The base value to be added to the flipped DEM. Defaults to 100.
        out_file (str, optional): File path to the output image. Defaults to None.

    Returns:
        np.array: The numpy array containing the flipped DEM.
    """
    # get min and max elevation of the dem
    no_data = dem.no_data
    max_elev = float(np.max(dem[dem != no_data]))
    # min_elev = float(np.min(dem[dem != no_data]))

    dem = dem * (-1) + max_elev + delta
    dem[dem == no_data * (-1)] = no_data

    if out_file is not None:
        print("Saving flipped dem ...")
        rd.SaveGDAL(out_file, dem)
        return out_file

    return dem

get_min_max_nodata(dem)

Gets the minimum, maximum, and no_data value of a numpy array.

Parameters:

Name Type Description Default
dem array

The numpy array containing the image.

required

Returns:

Name Type Description
tuple

The minimum, maximum, and no_data value.

Source code in lidar/mounts.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def get_min_max_nodata(dem):
    """Gets the minimum, maximum, and no_data value of a numpy array.

    Args:
        dem (np.array): The numpy array containing the image.

    Returns:
        tuple: The minimum, maximum, and no_data value.
    """
    no_data = dem.no_data
    max_elev = float(np.max(dem[dem != no_data]))
    min_elev = float(np.min(dem[dem != no_data]))

    return min_elev, max_elev, no_data