-
Notifications
You must be signed in to change notification settings - Fork 2
/
DCE_preprocess.py
57 lines (41 loc) · 1.63 KB
/
DCE_preprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 4 10:22:30 2019
DCE Preprocess, gets all of the inputs needed for the optimized DC_Eig_par function. This fucntion calculates the directional consines across the entire DEM (cy, cx, cz). This is a heavily modified function from Matteo Berti.
This separate script was written as several of the function calls herein are not supported by Numba, which was used to parallelize the secondary function (DC_eig_par.py).
INPUT:
DEM - digital elevation model;
cellsize - grid resolution
w - size of moving window
OUTPUT:
cy
cx
cz
Directional cosine(s) calculated in the x, y, and z directions
EXAMPLES:
w = 20
cellsize = 0.5
[cx,cy,cz] = DCE_preprocess(DEM,cellsize,w)
REFERENCES:
McKean and Roering, 2004, Objective landslide detection and surface morphology mapping using high-resolution airborne laser altimetry, Geomorphology, v. 57, no. 3-4, 331 - 351.
@author: matthewmorriss
"""
import numpy as np
def DCE_preprocess(DEM, cellsize, w):
[nrows, ncols] = np.shape(DEM)
#initiate an empty array same size as dem
rms = DEM*np.nan
# rms = np.float32(rms)
# #compute the directional cosines
[fx, fy] = np.gradient(DEM, cellsize, cellsize)
grad = np.sqrt(fx**2 + fy**2)
asp = np.arctan2(fy, fx)
grad=np.pi/2-np.arctan(grad) #normal of steepest slope
asp[asp<np.pi]=asp[asp<np.pi]+[np.pi/2]
asp[asp<0]=asp[asp<0]+[2*np.pi]
#spherical to cartesian conversion
r = 1
cy = r * np.cos(grad) * np.sin(asp)
cx = r * np.cos(grad) * np.cos(asp)
cz = r * np.sin(grad)
return(cx,cy,cz)