make_los_table
Generate line of sight lookup tables.
bin_slope_azim(az, slope, az_bins, slope_bins)
Return count of facets in each slope, azim bin using 2d histogram.
Parameters
slope (1D or 2D arr): Facet slope values. az (1D or 2D arr): Facet azim values. slope_bins (1D arr): Bin edges of slopes. az_bins (1D arr): Bin edges of azims.
Return
counts (2D arr nslope, naz): Counts in each slope/az bin; shape defined by bins.
Source code in roughness/make_los_table.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
buffered_raytrace(dem, inc, az=270)
Return line of sight array for dem, with left portion of dem repeated by leftbuffer then removed from the output. This is intended to extend a randomly rough dem to the west to correct for the longest shadow distance possible in the raytrace (otherwise we undercount shadows).
Source code in roughness/make_los_table.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
get_dem_los_buffer(dem, inc)
Return in_buffer, sections of dem too close to the edge to have shadows.
Since dem is of finite size and illuminated from the West at some inc, some facets towards the left edge of dem cannot have shadows cast onto them. We compute the max possible shadow length and exclude pixels within that length from the western edge of dem.
Parameters
dem (2D arr): Input DEM to ray trace where values are z-height. inc (1D arr): Input vector incidence angle (0 is nadir).
Return
buffer (int): Number of pixels to exclude from western edge of dem.
Source code in roughness/make_los_table.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
get_rms(y)
Compute the root mean square of an array, usually a Y array.
Parameters
y (vector array): Array of values where the variance needs to be computes.
Returns
RMS (value): The RMS value.
Source code in roughness/make_los_table.py
521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
get_slope_aspect(dem, get_aspect=True)
Return the instantaneous slope and aspect (if get_aspect) for dem.
Both values derived using NumPy's gradient method by methods from:
Ritter, Paul. "A vector-based slope and aspect generation algorithm." Photogrammetric Engineering and Remote Sensing 53, no. 8 (1987): 1109-1111
Parameters
dem(height) (2D array): A two dimensional array of elevation data. get_aspect (bool): Whether to also compute and return aspect (default True)
Returns
slope (2D array): A two dimensional array of slope data. aspect (2D array, optional): A two dimensional array of aspect data.
Source code in roughness/make_los_table.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
load_zsurf(path=FZSURF)
cached
Return z surface with self-affine roughness at path.
Parameters
path (optional: str): Path to zsurf numpy array
Returns
zsurf (2D array): Artifical z surface with self-affine roughness.
Source code in roughness/make_los_table.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
load_zsurf_scale_factors(path=FZ_FACTORS)
cached
Return scale factors at path.
Parameters
path (optional: str): Path to zsurf numpy array
Returns
scale_factors (1D array): : Scale factors for zsurf.
Source code in roughness/make_los_table.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
make_conj_sym(inarray, n, phase=0)
Takes square mag/phase arrays and impose conjugate symmetry for ifft.
Parameters
inarray: Square array that will be fed to ifft. n: Single axis dimension. phase: If the input is the phase portion of the complex FFT, set phase = 1.
Returns
out: inarray modified to have conjugate symmetry.
Source code in roughness/make_los_table.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
make_default_los_table()
Return default los table.
Source code in roughness/make_los_table.py
21 22 23 24 25 26 |
|
make_los_table(zsurf, rmss, incs, naz=36, ntheta=45, thresh=1, az0=AZ0, fout=None)
Generate line of sight probability table with dims (rms, inc, slope, az).
Tables are generated using raytracing on a synthetic Gaussian surface with a range of RMS slopes and observed from a range of solar inc angles. Final los_prob table is binned by facet slope/azimuth:
- los_prob == 1: All facets in line of sight (i.e. visible / illuminated)
- los_prob == 0: No facets in line of sight (i.e. not visible / shadowed)
- los_prob == np.nan: Fewer than threshold facets observed in bin
Parameters
zsurf (n x n arr): Artifical z surface with self-affine roughness. rmss (arr): RMS slope of surface to raytrace incs (arr): Solar incidence angles to raytrace [degrees] naz (int): Number of facet azimuth bins. Default=36 ntheta (int): Number of facet slope bins. Default=45 thresh (int): Min facets in bin to assign probability. Default=1 az0 (float): Raytrace azimuth from north in degrees. Default=270 fout (str): Path to write table with xarray extension (e.g. ".nc").
Returns
xarray.Dataset with 3 DataArrays: total: Total number of facets in bin los: Number of facets in line of sight in bin prob: Fraction of facets in line of sight in bin (los/total)
Source code in roughness/make_los_table.py
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 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
make_scale_factors(zsurf, rms_arr, write=True, fout=FZ_FACTORS, default=False)
Determine scale factors that produce rms_arr slopes from zsurf.
Computes RMS slope of zsurf at several multiplicative scale factors, then interpolates to find scale_factors at desired rms_arr values.
Parameters
zsurf (n x n arr): Artifical z surface with self-affine roughness. rms_arr (arr): Array of RMS values to scale zsurf to (max 80 degrees). write (bool): Write out scale factors to file. fout (str): Path to write scale factors. default (bool): Use default scale factors if they exist.
Returns
scale_factors (arr): Factors to scale zsurf by to get each rms_arr value.
Source code in roughness/make_los_table.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
make_zsurf(n=10000, H=0.8, qr=100, fout=FZSURF, write=True, default=False)
Return a synthetic surface with self-affine roughness. Much of this is detailed in this paper: Tevis D B Jacobs et al 2017 Surf. Topogr.: Metrol. Prop. 5 013001 https://doi.org/10.1088/2051-672X/aa51f8
Parameters
n: Side length of synthetic surface. Default=10000 H: Hurst exponent. qr: Rolloff wavelength in units of q (wavevector; 1/m). fout (str): Path to write z surface (.npy).
Returns
zsurf (n x n arr): Artifical z surface with self-affine roughness.
Source code in roughness/make_los_table.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
raytrace(dem, inc, az=270)
Return line of sight boolean array of 2D dem viewed from (inc, azim).
Wraps lineofsight raytrace module.
Parameters
dem (2D arr): Input DEM to ray trace where values are z-height. inc (1D arr): Input vector incidence angle [0, 90) where 0 is nadir. az (1D arr): Input vector azimuth angle [0, 360) where 0 is North.
Returns
out (2D bool arr, dem.shape): True - in los; False - not in los
Source code in roughness/make_los_table.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
scale_dem(dem, rms, scale_factors, rmss)
Scale a DEM by a set of scale factors.
Parameters
dem (n x n arr): DEM to scale. rms (int): RMS value to scale to. scale_factors (arr): Factors to scale dem by. rmss (arr): RMS values corresponding to scale_factors.
Returns
scaled_dem (n x n arr): DEM scaled to have rms roughness.
Source code in roughness/make_los_table.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|