Skip to content

Commit

Permalink
Updates hydroweight to fix Mac issue running whitebox::wbt_reclass();…
Browse files Browse the repository at this point in the history
… adds copyright and funding information
  • Loading branch information
bkielstr committed Apr 29, 2021
1 parent a45ca4d commit 9deba19
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
9 changes: 5 additions & 4 deletions R/hydroweight.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ hydroweight <- function(hydroweight_dir = NULL,
whitebox::wbt_reclass(
input = file.path(hydroweight_dir, clip_region),
output = file.path(hydroweight_dir, "TEMP-clip_region.tif"),
reclass_vals = "1;min,max"
reclass_vals = "1,min,max"
)

whitebox::wbt_raster_to_vector_polygons(
Expand All @@ -126,10 +126,11 @@ hydroweight <- function(hydroweight_dir = NULL,
}

if (is.null(clip_region)) {

whitebox::wbt_reclass(
input = file.path(hydroweight_dir, dem),
output = file.path(hydroweight_dir, "TEMP-clip_region.tif"),
reclass_vals = "1;min;30000", # because max sometimes misses max values?
reclass_vals = "1,min,30000", # because max sometimes misses max values?
# verbose_mode = TRUE
)

Expand Down Expand Up @@ -345,7 +346,7 @@ hydroweight <- function(hydroweight_dir = NULL,
whitebox::wbt_reclass(
input = file.path(hydroweight_dir, "TEMP-dem_clip.tif"),
output = file.path(hydroweight_dir, "TEMP-lumped.tif"),
reclass_vals = "1;min;30000"
reclass_vals = "1,min,30000"
) # because max sometimes misses max values?

lumped_inv <- raster::raster(file.path(hydroweight_dir, "TEMP-lumped.tif"), values = TRUE)
Expand All @@ -360,7 +361,7 @@ hydroweight <- function(hydroweight_dir = NULL,
whitebox::wbt_reclass(
input = file.path(hydroweight_dir, "TEMP-dem_clip.tif"),
output = file.path(hydroweight_dir, "TEMP_dem_clip_cost.tif"),
reclass_vals = "1;min;30000"
reclass_vals = "1,min,30000"
) # because max sometimes misses max values?

# cost <- dem_clip
Expand Down
14 changes: 12 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ knitr::opts_chunk$set(
* [6.0 Future plans](#60-future-plans)
* [7.0 Acknowledgements](#70-acknowledgements)
* [8.0 References](#80-references)
* [9.0 Copyright](#90-copyright)


## 1.0 Introduction

Expand Down Expand Up @@ -109,7 +111,7 @@ Distance weights defined by Peterson *et al.* (2011) are:
## 2.0 System setup and installation

*WhiteboxTools* must be installed for ***hydroweight*** to run. See [whiteboxR](https://github.com/giswqs/whiteboxR) or below for installation.
*R*'s `whitebox` runs `whitebox_tools.exe` which is installed to `your-R-libary-path/whitebox/WBT`.
*R*'s `whitebox` runs `whitebox_tools` which is installed to `your-R-libary-path/whitebox/WBT`.
This may cause problems depending on your specific computer setup. One possible
solution is to ensure there are no spaces in the R library path (check using `.libPaths()`).

Expand All @@ -120,9 +122,10 @@ install.packages("whitebox", repos="http://R-Forge.R-project.org")
library(whitebox)
whitebox::wbt_init()
whitebox::wbt_version()
## Install current version of hydroweight
devtools::install_github("bkielstr/hydroweight")
devtools::install_github("bkielstr/hydroweight@main")
```

[Back to top](#contents)
Expand Down Expand Up @@ -1047,6 +1050,9 @@ Thank you to for early review/testing (alphabetical order):

Darren McCormick, Courtney Mondoux, Emily Smenderovac

We acknowledge the funding support of Natural Resources Canada, the Ontario Ministry of Natural Resources,
and a Natural Sciences and Engineering Research Council of Canada Strategic Partnership Grant (STPGP 521405-2018).

[Back to top](#contents)

## 8.0 References
Expand All @@ -1069,3 +1075,7 @@ Wickham, H., Bryan, J. (2021). R Packages. 2nd edition. https://r-pkgs.org/.
Wu, Q. (2020). whitebox: 'WhiteboxTools' R Frontend. R package version 1.4.0. https://github.com/giswqs/whiteboxR

[Back to top](#contents)

## 9.0 Copyright

Copyright (C) 2021 Her Majesty the Queen in Right of Canada, as represented by the Minister of Natural Resources Canada
51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ hydroweight: Inverse distance-weighted rasters and landscape attributes
- [6.0 Future plans](#60-future-plans)
- [7.0 Acknowledgements](#70-acknowledgements)
- [8.0 References](#80-references)
- [9.0 Copyright](#90-copyright)

## 1.0 Introduction

Expand Down Expand Up @@ -125,21 +126,21 @@ Distance weights defined by Peterson *et al.* (2011) are:

*WhiteboxTools* must be installed for ***hydroweight*** to run. See
[whiteboxR](https://github.com/giswqs/whiteboxR) or below for
installation. *R*’s `whitebox` runs `whitebox_tools.exe` which is
installed to `your-R-libary-path/whitebox/WBT`. This may cause problems
depending on your specific computer setup. One possible solution is to
ensure there are no spaces in the R library path (check using
`.libPaths()`).
installation. *R*’s `whitebox` runs `whitebox_tools` which is installed
to `your-R-libary-path/whitebox/WBT`. This may cause problems depending
on your specific computer setup. One possible solution is to ensure
there are no spaces in the R library path (check using `.libPaths()`).

``` r
## Follow instructions for whitebox installation accordingly
install.packages("whitebox", repos="http://R-Forge.R-project.org")

library(whitebox)
whitebox::wbt_init()
whitebox::wbt_version()

## Install current version of hydroweight
devtools::install_github("bkielstr/hydroweight")
devtools::install_github("bkielstr/hydroweight@main")
```

[Back to top](#contents)
Expand Down Expand Up @@ -180,7 +181,7 @@ wbt_breach_depressions(
dem = file.path(hydroweight_dir, "toy_dem.tif"),
output = file.path(hydroweight_dir, "toy_dem_breached.tif")
)
#> [1] "breach_depressions - Elapsed Time (excluding I/O): 0.7s"
#> [1] "breach_depressions - Elapsed Time (excluding I/O): 0.8s"

## Generate d8 flow pointer (note: other flow directions are available)
wbt_d8_pointer(
Expand All @@ -195,7 +196,7 @@ wbt_d8_flow_accumulation(
output = file.path(hydroweight_dir, "toy_dem_breached_accum.tif"),
out_type = "cells"
)
#> [1] "d8_flow_accumulation - Elapsed Time (excluding I/O): 0.49s"
#> [1] "d8_flow_accumulation - Elapsed Time (excluding I/O): 0.36s"

## Generate streams with a stream initiation threshold of 2000 cells
wbt_extract_streams(
Expand Down Expand Up @@ -242,7 +243,7 @@ wbt_watershed(
pour_pts = file.path(hydroweight_dir, "tg_O.tif"),
output = file.path(hydroweight_dir, "tg_O_catchment.tif")
)
#> [1] "watershed - Elapsed Time (excluding I/O): 0.7s"
#> [1] "watershed - Elapsed Time (excluding I/O): 0.9s"

tg_O_catchment <- raster(file.path(hydroweight_dir, "tg_O_catchment.tif"))
tg_O_catchment <- rasterToPolygons(tg_O_catchment, dissolve = TRUE)
Expand Down Expand Up @@ -355,8 +356,8 @@ hw_test_1 <- hydroweight::hydroweight(
),
inv_function = myinv
)
#> Preparing hydroweight layers @ 2021-04-28 16:47:53
#> Running distance-weighting @ 2021-04-28 16:47:55
#> Preparing hydroweight layers @ 2021-04-29 16:31:42
#> Running distance-weighting @ 2021-04-29 16:31:45

## Resultant structure:
# length(hw_test_1) ## 1 set of targets and 7 distance-weighted rasters
Expand Down Expand Up @@ -527,15 +528,15 @@ hw_test_5 <- foreach(xx = 1:nrow(tg_O_multi), .errorhandling = "pass") %do% {

return(hw_test_xx)
}
#> Running hydroweight for site 1 at 2021-04-28 16:48:15
#> Preparing hydroweight layers @ 2021-04-28 16:48:15
#> Running distance-weighting @ 2021-04-28 16:48:17
#> Running hydroweight for site 2 at 2021-04-28 16:48:22
#> Preparing hydroweight layers @ 2021-04-28 16:48:22
#> Running distance-weighting @ 2021-04-28 16:48:24
#> Running hydroweight for site 3 at 2021-04-28 16:48:28
#> Preparing hydroweight layers @ 2021-04-28 16:48:28
#> Running distance-weighting @ 2021-04-28 16:48:30
#> Running hydroweight for site 1 at 2021-04-29 16:32:06
#> Preparing hydroweight layers @ 2021-04-29 16:32:06
#> Running distance-weighting @ 2021-04-29 16:32:08
#> Running hydroweight for site 2 at 2021-04-29 16:32:13
#> Preparing hydroweight layers @ 2021-04-29 16:32:13
#> Running distance-weighting @ 2021-04-29 16:32:15
#> Running hydroweight for site 3 at 2021-04-29 16:32:20
#> Preparing hydroweight layers @ 2021-04-29 16:32:20
#> Running distance-weighting @ 2021-04-29 16:32:22

## Resultant structure:
## length(hw_test_5) # 3 sites
Expand Down Expand Up @@ -1287,6 +1288,11 @@ Thank you to for early review/testing (alphabetical order):

Darren McCormick, Courtney Mondoux, Emily Smenderovac

We acknowledge the funding support of Natural Resources Canada, the
Ontario Ministry of Natural Resources, and a Natural Sciences and
Engineering Research Council of Canada Strategic Partnership Grant
(STPGP 521405-2018).

[Back to top](#contents)

## 8.0 References
Expand Down Expand Up @@ -1324,3 +1330,8 @@ Wu, Q. (2020). whitebox: ‘WhiteboxTools’ R Frontend. R package version
1.4.0. <https://github.com/giswqs/whiteboxR>

[Back to top](#contents)

## 9.0 Copyright

Copyright (C) 2021 Her Majesty the Queen in Right of Canada, as
represented by the Minister of Natural Resources Canada
Binary file modified man/figures/README-unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9deba19

Please sign in to comment.