|
| 1 | +--- |
| 2 | +title: "How to convert flow direction between different encodings in GRASS" |
| 3 | +author: "Huidae Cho" |
| 4 | +date: 2022-03-25 |
| 5 | +date-modified: today |
| 6 | +format: |
| 7 | + html: |
| 8 | + toc: true |
| 9 | + toc-depth: 2 |
| 10 | + code-tools: true |
| 11 | + code-copy: true |
| 12 | + code-fold: false |
| 13 | + html-math-method: katex |
| 14 | + theme: |
| 15 | + - cosmo |
| 16 | +categories: [bash, beginner] |
| 17 | +linkcolor: green |
| 18 | +urlcolor: green |
| 19 | +citecolor: green |
| 20 | +highlight-style: github |
| 21 | +# engine: knitr |
| 22 | +execute: |
| 23 | + eval: false |
| 24 | +--- |
| 25 | +# Introduction |
| 26 | + |
| 27 | +This document shows how to convert flow direction encodings between several formats in GRASS. Each section displays: |
| 28 | + |
| 29 | +- **Figure Left:** Input encoding |
| 30 | +- **Equation:** Conversion formula |
| 31 | +- **Figure Right:** Output encoding |
| 32 | +- **GRASS Command** |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## 1. Degree to 45degree |
| 37 | + |
| 38 | +::: columns |
| 39 | +:::: {.column width="20%"} |
| 40 | +{width=80%} |
| 41 | +:::: |
| 42 | + |
| 43 | +:::: {.column width="60%"} |
| 44 | +$$D = \frac{d}{45}$$ |
| 45 | +:::: |
| 46 | + |
| 47 | +:::: {.column width="20%"} |
| 48 | +{width=80%} |
| 49 | +:::: |
| 50 | +::: |
| 51 | +```bash |
| 52 | +r.mapcalc "45degree = int(degree / 45)" |
| 53 | +``` |
| 54 | + |
| 55 | +## 2. 45degree to Degree |
| 56 | + |
| 57 | +::: columns |
| 58 | +:::: {.column width="20%"} |
| 59 | +{width=80%} |
| 60 | +:::: |
| 61 | + |
| 62 | +:::: {.column width="60%"} |
| 63 | +$$d = 45 \times |D|$$ |
| 64 | +:::: |
| 65 | + |
| 66 | +:::: {.column width="20%"} |
| 67 | +{width=80%} |
| 68 | +:::: |
| 69 | +::: |
| 70 | +```bash |
| 71 | +r.mapcalc "degree = abs(45degree) * 45" |
| 72 | +``` |
| 73 | + |
| 74 | +## 3. Degree to Power2 |
| 75 | + |
| 76 | +::: columns |
| 77 | +:::: {.column width="20%"} |
| 78 | +{width=80%} |
| 79 | +:::: |
| 80 | + |
| 81 | +:::: {.column width="60%"} |
| 82 | +$$p = 2^{8 - \frac{d}{45}}$$ |
| 83 | +:::: |
| 84 | + |
| 85 | +:::: {.column width="20%"} |
| 86 | +{width=80%} |
| 87 | +:::: |
| 88 | +::: |
| 89 | +```bash |
| 90 | +r.mapcalc "power2 = 2^(8 - degree / 45)" |
| 91 | +``` |
| 92 | +--- |
| 93 | + |
| 94 | +## 4. Power2 to Degree |
| 95 | + |
| 96 | +::: columns |
| 97 | +:::: {.column width="20%"} |
| 98 | +{width=80%} |
| 99 | +:::: |
| 100 | + |
| 101 | +:::: {.column width="60%"} |
| 102 | +$$d = 45 \times (8 - \log_2 p)$$ |
| 103 | +:::: |
| 104 | + |
| 105 | +:::: {.column width="20%"} |
| 106 | +{width=80%} |
| 107 | +:::: |
| 108 | +::: |
| 109 | +```bash |
| 110 | +r.mapcalc "degree = 45 * int(8 - log(power2, 2))" |
| 111 | +``` |
| 112 | + |
| 113 | +## 5. Degree to TauDEM |
| 114 | + |
| 115 | +::: columns |
| 116 | +:::: {.column width="20%"} |
| 117 | +{width=80%} |
| 118 | +:::: |
| 119 | + |
| 120 | +:::: {.column width="60%"} |
| 121 | +$$t = 1 + \left( \frac{d}{45} \mod 8 \right)$$ |
| 122 | +:::: |
| 123 | + |
| 124 | +:::: {.column width="20%"} |
| 125 | +{width=80%} |
| 126 | +:::: |
| 127 | +::: |
| 128 | +```bash |
| 129 | +r.mapcalc "taudem = 1 + (degree / 45) % 8" |
| 130 | +``` |
| 131 | + |
| 132 | +## 6. TauDEM to Degree |
| 133 | + |
| 134 | +::: columns |
| 135 | +:::: {.column width="20%"} |
| 136 | +{width=80%} |
| 137 | +:::: |
| 138 | + |
| 139 | +:::: {.column width="60%"} |
| 140 | +$$d = 45 \times \left\{ \begin{array}{ll} t-1 & \text{if } t-1 > 0 \\ 8 & \text{otherwise} \end{array} \right.$$ |
| 141 | +:::: |
| 142 | + |
| 143 | +:::: {.column width="20%"} |
| 144 | +{width=80%} |
| 145 | +:::: |
| 146 | +::: |
| 147 | +```bash |
| 148 | +r.mapcalc "degree = 45 * if(taudem - 1, taudem - 1, 8)" |
| 149 | +``` |
| 150 | + |
| 151 | +## 7. 45degree to Power2 |
| 152 | + |
| 153 | +::: columns |
| 154 | +:::: {.column width="20%"} |
| 155 | +{width=80%} |
| 156 | +:::: |
| 157 | + |
| 158 | +:::: {.column width="60%"} |
| 159 | +$$p = 2^{8 - |D|}$$ |
| 160 | +:::: |
| 161 | + |
| 162 | +:::: {.column width="20%"} |
| 163 | +{width=80%} |
| 164 | +:::: |
| 165 | +::: |
| 166 | +```bash |
| 167 | +r.mapcalc "power2 = 2^(8 - abs(45degree))" |
| 168 | +``` |
| 169 | + |
| 170 | +## 8. Power2 to 45degree |
| 171 | + |
| 172 | +::: columns |
| 173 | +:::: {.column width="20%"} |
| 174 | +{width=80%} |
| 175 | +:::: |
| 176 | + |
| 177 | +:::: {.column width="60%"} |
| 178 | +$$D = 8 - \log_2 p$$ |
| 179 | +:::: |
| 180 | + |
| 181 | +:::: {.column width="20%"} |
| 182 | +{width=80%} |
| 183 | +:::: |
| 184 | +::: |
| 185 | +```bash |
| 186 | +r.mapcalc "45degree = int(8 - log(power2, 2))" |
| 187 | +``` |
| 188 | + |
| 189 | +## 9. 45degree to TauDEM |
| 190 | + |
| 191 | +::: columns |
| 192 | +:::: {.column width="20%"} |
| 193 | +{width=80%} |
| 194 | +:::: |
| 195 | + |
| 196 | +:::: {.column width="60%"} |
| 197 | +$$t = 1 + (|D| \mod 8)$$ |
| 198 | +:::: |
| 199 | + |
| 200 | +:::: {.column width="20%"} |
| 201 | +{width=80%} |
| 202 | +:::: |
| 203 | +::: |
| 204 | +```bash |
| 205 | +r.mapcalc "taudem = 1 + abs(45degree) % 8" |
| 206 | +``` |
| 207 | + |
| 208 | +## 10. TauDEM to 45degree |
| 209 | + |
| 210 | +::: columns |
| 211 | +:::: {.column width="20%"} |
| 212 | +{width=80%} |
| 213 | +:::: |
| 214 | + |
| 215 | +:::: {.column width="60%"} |
| 216 | +$$D = \left\{\begin{array}{ll} t-1 & \text{if } t-1 > 0 \\ 8 & \text{otherwise} \end{array} \right.$$ |
| 217 | +:::: |
| 218 | + |
| 219 | +:::: {.column width="20%"} |
| 220 | +{width=80%} |
| 221 | +:::: |
| 222 | +::: |
| 223 | +```bash |
| 224 | +r.mapcalc "45degree = if(taudem - 1, taudem - 1, 8)" |
| 225 | +``` |
| 226 | + |
| 227 | +## 11. Power2 to TauDEM |
| 228 | + |
| 229 | +::: columns |
| 230 | +:::: {.column width="20%"} |
| 231 | +{width=80%} |
| 232 | +:::: |
| 233 | + |
| 234 | +:::: {.column width="60%"} |
| 235 | +$$t = 1 + \left[ (8 - \log_2 p) \mod 8 \right]$$ |
| 236 | +:::: |
| 237 | + |
| 238 | +:::: {.column width="20%"} |
| 239 | +{width=80%} |
| 240 | +:::: |
| 241 | +::: |
| 242 | +```bash |
| 243 | +r.mapcalc "taudem = 1 + (8 - log(power2, 2)) % 8" |
| 244 | +``` |
| 245 | + |
| 246 | +## 12. TauDEM to Power2 |
| 247 | + |
| 248 | +::: columns |
| 249 | +:::: {.column width="20%"} |
| 250 | +{width=80%} |
| 251 | +:::: |
| 252 | + |
| 253 | +:::: {.column width="60%"} |
| 254 | +$$p = 2^{(9 - t) \mod 8}$$ |
| 255 | +:::: |
| 256 | + |
| 257 | +:::: {.column width="20%"} |
| 258 | +{width=80%} |
| 259 | +:::: |
| 260 | +::: |
| 261 | +```bash |
| 262 | +r.mapcalc "power2 = 2^((9 - taudem) % 8)" |
| 263 | +``` |
0 commit comments