Coder Social home page Coder Social logo

ropensci / landscapetools Goto Github PK

View Code? Open in Web Editor NEW
46.0 13.0 16.0 22.17 MB

๐Ÿ“ฆ R package for some of the less-glamorous tasks involved in landscape analysis ๐ŸŒ

Home Page: https://docs.ropensci.org/landscapetools

License: GNU General Public License v3.0

R 95.62% C 4.38%
r rstats raster landscape landscape-ecology visualization workflow r-package

landscapetools's Introduction

R-CMD-check codecov lifecycle CRAN status DOI:10.1111/2041-210X.13076

landscapetools

landscapetools provides utility functions for some of the less-glamorous tasks involved in landscape analysis:

Utilities:

  • util_binarize: Binarize continuous raster values, if > 1 breaks are given, return a RasterBrick.
  • util_classify: Classify a raster into proportions based upon a vector of class weightings.
  • util_merge: Merge a primary raster with other rasters weighted by scaling factors.
  • util_raster2tibble, util_tibble2raster: Coerce raster* objects to tibbles and vice versa.
  • util_rescale: Linearly rescale element values in a raster to a range between 0 and 1.
  • util_writeESRI: Export raster objects as ESRI asciis (with Windows linebreaks).

Visualization

  • show_landscape: Plot a Raster* object with the landscapetools default theme (as ggplot) or multiple raster (RasterStack, -brick or list of raster) side by side as facets.
  • show_shareplot: Plot the landscape share in subsequential buffers around a/multiple point(s) of interest

Themes:

  • theme_nlm, theme_nlm_grey: Opinionated ggplot2 theme to visualize raster (continuous data).
  • theme_nlm_discrete, theme_nlm_grey_discrete: Opinionated ggplot2 theme to visualize raster (discrete data).
  • theme_faceplot: Opinionated ggplot2 theme to visualize raster in a facet wrap.

Installation

You can install the released version from CRAN with:

install.packages("landscapetools")

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("ropensci/landscapetools")

Utilities

Classify

# Classify the landscape into land uses
classified_landscape <- util_classify(fractal_landscape,
                                      n = 3,
                                      level_names = c("Land Use 1", 
                                                      "Land Use 2",
                                                      "Land Use 3"))

show_landscape(classified_landscape, discrete = TRUE)

Merge

# Merge all landscapes into one
merged_landscape <- util_merge(fractal_landscape,
                               c(gradient_landscape, random_landscape),
                               scalingfactor = 1)

# Plot an overview
merge_vis <- list(
    "1) Primary" = fractal_landscape,
    "2) Secondary 1" = gradient_landscape,
    "3) Secondary 2" = random_landscape,
    "4) Result" = merged_landscape
)

show_landscape(merge_vis)
#> Warning: Removed 1196 rows containing missing values (geom_raster).

See also

In the examples above we make heavy use of the NLMR package. Both packages were developed together until we split them into pure landscape functionality and utility tools. If you are interested in generating neutral landscapes via a multitude of available algorithms take a closer look at the NLMR package.

Meta

  • Please report any issues or bugs.
  • License: GPL3
  • Get citation information for landscapetools in R doing citation(package = 'landscapetools')
  • We are very open to contributions - if you are interested check Contributing.
    • Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

ropensci_footer

landscapetools's People

Contributors

actions-user avatar bitbacchus avatar bniebuhr avatar jeroen avatar joshobrien avatar marcosci avatar mattfrit avatar mhesselbarth avatar nowosad avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

landscapetools's Issues

landscapetools 0.5

Tasks to streamline landscapetools for future updates:

  • Remove font related code/files
  • Write tests for everything
  • Write more detailed documentation
  • Vignettes for the homepage
  • Get rid of dependencies: viridis, rastervis, purrr, cowplot, magrittr, checkmate, extrafont

... in light of future updates:

  1. Do we want to stick to the current naming scheme?
  2. If anything bugs you here - feel free to discuss.

Support for terra

Hi!

Is there any intended support for terra? If not, I would like to suggest this as an improvement.

The landscapetools package is very useful, but now that I am trying to migrate for terra (which is incredible faster for some things), I still need to come back to raster functions to allow compatibility with other packages (such as landscapetools). I guess several other people in the R community might be in this movement (at least from my personal contacts and colleagues).

Discrepancy in the `util_classify()` docs

The util_classify() doc states "The classes start with the value 1. ", but in fact they start from a value of zero:

library(landscapetools)
weight <- c(0.5, 0.25, 0.25)
a = util_classify(fbmmap, weight,
                  level_names = c("Land Use 1", "Land Use 2", "Land Use 3"))
b = util_classify(fbmmap, weight)

a
#> class       : RasterLayer 
#> dimensions  : 200, 200, 40000  (nrow, ncol, ncell)
#> resolution  : 1, 1  (x, y)
#> extent      : 0, 200, 0, 200  (xmin, xmax, ymin, ymax)
#> coord. ref. : NA 
#> data source : in memory
#> names       : layer 
#> values      : 0, 2  (min, max)
#> attributes  :
#>  ID Categories
#>   0 Land Use 1
#>   1 Land Use 2
#>   2 Land Use 3
b
#> class       : RasterLayer 
#> dimensions  : 200, 200, 40000  (nrow, ncol, ncell)
#> resolution  : 1, 1  (x, y)
#> extent      : 0, 200, 0, 200  (xmin, xmax, ymin, ymax)
#> coord. ref. : NA 
#> data source : in memory
#> names       : layer 
#> values      : 0, 2  (min, max)

Created on 2018-05-15 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2018-05-15
#> Packages -----------------------------------------------------------------
#>  package        * version date      
#>  backports        1.1.2   2017-12-13
#>  base           * 3.4.4   2018-03-28
#>  checkmate        1.8.5   2017-10-24
#>  compiler         3.4.4   2018-03-28
#>  datasets       * 3.4.4   2018-03-28
#>  devtools         1.13.5  2018-02-18
#>  digest           0.6.15  2018-01-28
#>  evaluate         0.10.1  2017-06-24
#>  extrafont        0.17    2014-12-08
#>  extrafontdb      1.0     2012-06-11
#>  graphics       * 3.4.4   2018-03-28
#>  grDevices      * 3.4.4   2018-03-28
#>  grid             3.4.4   2018-03-28
#>  htmltools        0.3.6   2017-04-28
#>  knitr            1.20    2018-02-20
#>  landscapetools * 0.3.0   2018-05-04
#>  lattice          0.20-35 2017-03-25
#>  magrittr         1.5     2014-11-22
#>  memoise          1.1.0   2017-04-21
#>  methods        * 3.4.4   2018-03-28
#>  raster         * 2.6-7   2017-11-13
#>  Rcpp             0.12.16 2018-03-13
#>  rmarkdown        1.9     2018-03-01
#>  rprojroot        1.3-2   2018-01-03
#>  Rttf2pt1         1.3.6   2018-02-22
#>  sp             * 1.2-7   2018-01-19
#>  stats          * 3.4.4   2018-03-28
#>  stringi          1.2.2   2018-05-02
#>  stringr          1.3.0   2018-02-19
#>  tools            3.4.4   2018-03-28
#>  utils          * 3.4.4   2018-03-28
#>  withr            2.1.2   2018-03-17
#>  yaml             2.1.18  2018-03-08
#>  source                                  
#>  CRAN (R 3.4.2)                          
#>  local                                   
#>  CRAN (R 3.4.1)                          
#>  local                                   
#>  local                                   
#>  CRAN (R 3.4.3)                          
#>  cran (@0.6.15)                          
#>  cran (@0.10.1)                          
#>  CRAN (R 3.4.2)                          
#>  CRAN (R 3.4.2)                          
#>  local                                   
#>  local                                   
#>  local                                   
#>  CRAN (R 3.4.0)                          
#>  cran (@1.20)                            
#>  Github (ropensci/landscapetools@eb3ebb8)
#>  CRAN (R 3.4.4)                          
#>  CRAN (R 3.4.0)                          
#>  CRAN (R 3.4.0)                          
#>  local                                   
#>  cran (@2.6-7)                           
#>  CRAN (R 3.4.3)                          
#>  CRAN (R 3.4.3)                          
#>  CRAN (R 3.4.2)                          
#>  CRAN (R 3.4.3)                          
#>  CRAN (R 3.4.2)                          
#>  local                                   
#>  cran (@1.2.2)                           
#>  cran (@1.3.0)                           
#>  local                                   
#>  local                                   
#>  Github (jimhester/withr@79d7b0d)        
#>  CRAN (R 3.4.3)

random % with corresponding % from real landscape

Dear authors of landscapetools,

thanks a lot, the package looks great.

Just an idea: if the percentage for the random class landscape can be picked automatically from a real classification then these two landscapes could be compared. Additionally "constraints" for the random landscape could be added, e.g. no landscape on masked areas such as water. This would allow to test for driving factors of landscape arrangement.

the r.pi.nlm command in the r.pi suit within GRASS GIS is doing similar stuff, maybe interesting to look at it:
https://grass.osgeo.org/grass74/manuals/addons/r.pi.html

Share plots

I created something that I called "a share plot" for one of my projects.
It show a share of each raster categories for some distance around a point of interest.
One example of this plot can be seen below.

@marcosci, @mhesselbarth, @mattfrit - do you think it could be useful in spatial ecology?

rplot

Fix pkgdown configuration for reference

Some topics are missing from the configuration file.

 Error in check_missing_topics(rows, pkg) : 
  All topics must be included in reference index
โ€ข Missing topics: gradient_landscape, landscapetools-package, util_extract_multibuffer

Note that for topics you do not want to include in the index you can create an "internal" section https://pkgdown.r-lib.org/reference/build_reference.html?q=internal#missing-topics

To check all topics are listed, after editing the configuration file you can run pkgdown::check_pkgdown().

Build failure

==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.159.3
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /__w/_temp/1349b40d-8eed-4090-ae4c-ab2e4f5cb7e8.sh
* checking for file โ€˜landscapetools/DESCRIPTIONโ€™ ... OK
* preparing โ€˜landscapetoolsโ€™:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
* creating vignettes ... ERROR
--- re-building โ€˜overview.Rmdโ€™ using rmarkdown
Loading required package: raster
Loading required package: sp
Quitting from lines 56-63 (overview.Rmd) 
Error: processing vignette 'overview.Rmd' failed with diagnostics:
Discrete value supplied to continuous scale
--- failed re-building โ€˜overview.Rmdโ€™

SUMMARY: processing the following file failed:
  โ€˜overview.Rmdโ€™

Error: Vignette re-building failed.
Execution halted

How to define the order of the rasters shown with `show_landscape()`?

Hi,

I want to show a set of rasters in a given order with landscapetools::show_landscape(), but it seems the function always plot the several rasters in alfabetic order, according to their names. Would it be possible to plot using the same sequence of the input list of rasters (regardless of their names), or even to decide which order to use?

Here an example to show that.

library(raster)
library(NLMR)
library(landscapetools)

set.seed(123)

# parameters
param_df <- expand.grid(ncol = 100,
                        nrow = 100,
                        resolution = 100, 
                        roughness = c(2, seq(0.9, 0.1, -0.2))) %>% 
  tibble::as_tibble()

# simulated landscapes
nlm_mpd_seed <- function(user_seed = 123, ...) {
  set.seed(user_seed)
  NLMR::nlm_mpd(...)
}

# simulate rasters
nlm_list <- param_df %>% purrr::pmap(nlm_mpd_seed, user_seed = 123)
names(nlm_list) <- types <- c("random", paste0("clust", 1:5))

# plot
landscapetools::show_landscape(nlm_list)

image

I wanted to show the random landscape first, followed by the maps in a gradient of clumpiness. However, because of the name, the random one is moved to the end of the plot.

Session Info
> devtools::session_info()
โ”€ Session info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 setting  value                       
 version  R version 4.0.3 (2020-10-10)
 os       Ubuntu 18.04.6 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Oslo                 
 date     2021-12-01                  

โ”€ Packages โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 !  package        * version  date       lib source                                  
    assertthat       0.2.1    2019-03-21 [2] CRAN (R 4.0.3)                          
    backports        1.4.0    2021-11-23 [1] CRAN (R 4.0.3)                          
    cachem           1.0.6    2021-08-19 [2] CRAN (R 4.0.3)                          
    callr            3.7.0    2021-04-20 [2] CRAN (R 4.0.3)                          
    checkmate        2.0.0    2020-02-06 [2] CRAN (R 4.0.3)                          
    class            7.3-19   2021-05-03 [4] CRAN (R 4.0.3)                          
    classInt         0.4-3    2020-04-07 [2] CRAN (R 4.0.3)                          
    cli              3.1.0    2021-10-27 [1] CRAN (R 4.0.3)                          
    codetools        0.2-18   2020-11-04 [4] CRAN (R 4.0.3)                          
    colorspace       2.0-2    2021-06-24 [2] CRAN (R 4.0.3)                          
 VP crayon           1.4.1    2021-10-29 [2] CRAN (R 4.0.3)                          
    DBI              1.1.1    2021-01-15 [2] CRAN (R 4.0.3)                          
    desc             1.4.0    2021-09-28 [2] CRAN (R 4.0.3)                          
    devtools         2.4.2    2021-06-07 [2] CRAN (R 4.0.3)                          
    digest           0.6.28   2021-09-23 [2] CRAN (R 4.0.3)                          
    dplyr          * 1.0.7    2021-06-18 [2] CRAN (R 4.0.3)                          
    e1071            1.7-9    2021-09-16 [2] CRAN (R 4.0.3)                          
 P  ellipsis         0.3.2    2021-04-29 [2] CRAN (R 4.0.3)                          
    evaluate         0.14     2019-05-28 [2] CRAN (R 4.0.3)                          
    fansi            0.5.0    2021-05-25 [2] CRAN (R 4.0.3)                          
    farver           2.1.0    2021-02-28 [2] CRAN (R 4.0.3)                          
    fastmap          1.1.0    2021-01-25 [2] CRAN (R 4.0.3)                          
    fs               1.5.0    2020-07-31 [2] CRAN (R 4.0.3)                          
 VP generics         0.1.0    2021-10-25 [2] CRAN (R 4.0.3)                          
    ggplot2        * 3.3.5    2021-06-25 [2] CRAN (R 4.0.3)                          
 VP glue             1.4.2    2021-11-30 [2] CRAN (R 4.0.3)                          
    grImport         0.9-4    2021-10-11 [2] CRAN (R 4.0.3)                          
    gtable           0.3.0    2019-03-25 [2] CRAN (R 4.0.3)                          
    hexbin           1.28.2   2021-01-08 [2] CRAN (R 4.0.3)                          
    htmltools        0.5.2    2021-08-25 [2] CRAN (R 4.0.3)                          
    jpeg             0.1-9    2021-07-24 [2] CRAN (R 4.0.3)                          
    KernSmooth       2.23-20  2021-05-03 [4] CRAN (R 4.0.5)                          
    knitr            1.36     2021-09-29 [2] CRAN (R 4.0.3)                          
    labeling         0.4.2    2020-10-20 [2] CRAN (R 4.0.3)                          
    landscapetools * 0.6.2    2021-11-30 [1] Github (ropensci/landscapetools@77d9d24)
    lattice        * 0.20-45  2021-09-22 [4] CRAN (R 4.1.1)                          
    latticeExtra     0.6-29   2019-12-19 [2] CRAN (R 4.0.3)                          
    lifecycle        1.0.1    2021-09-24 [2] CRAN (R 4.0.3)                          
    lsr            * 0.5.1    2021-09-20 [1] CRAN (R 4.0.3)                          
    magrittr         2.0.1    2020-11-17 [2] CRAN (R 4.0.3)                          
    memoise          2.0.0    2021-01-26 [2] CRAN (R 4.0.3)                          
    mobsim         * 0.2.0    2021-03-23 [1] CRAN (R 4.0.3)                          
    munsell          0.5.0    2018-06-12 [2] CRAN (R 4.0.3)                          
    NCmisc           1.1.6    2018-11-12 [2] CRAN (R 4.0.3)                          
    NinaR          * 0.2.2.3  2020-12-10 [2] Github (NINAnor/NinaR@77dd8d1)          
    NLMR           * 1.1      2021-11-30 [1] Github (ropensci/NLMR@3a1b03f)          
    oneimpact      * 0.1.0    2021-11-30 [1] local                                   
    pillar           1.6.4    2021-10-18 [2] CRAN (R 4.0.3)                          
    pkgbuild         1.2.0    2020-12-15 [2] CRAN (R 4.0.3)                          
    pkgconfig        2.0.3    2019-09-22 [2] CRAN (R 4.0.3)                          
    pkgload          1.2.3    2021-10-13 [2] CRAN (R 4.0.3)                          
    plyr             1.8.6    2020-03-03 [2] CRAN (R 4.0.3)                          
    png              0.1-7    2013-12-03 [2] CRAN (R 4.0.3)                          
    prettyunits      1.1.1    2020-01-24 [2] CRAN (R 4.0.3)                          
    processx         3.5.2    2021-04-30 [1] CRAN (R 4.0.3)                          
    proftools        0.99-3   2020-07-08 [2] CRAN (R 4.0.3)                          
    proxy            0.4-26   2021-06-07 [2] CRAN (R 4.0.3)                          
    ps               1.6.0    2021-02-28 [2] CRAN (R 4.0.3)                          
    purrr            0.3.4    2020-04-17 [2] CRAN (R 4.0.3)                          
    R6               2.5.1    2021-08-19 [2] CRAN (R 4.0.3)                          
    raster         * 3.5-2    2021-10-11 [2] CRAN (R 4.0.3)                          
    rasterVis      * 0.51.0   2021-10-11 [1] CRAN (R 4.0.3)                          
    RColorBrewer     1.1-2    2014-12-07 [2] CRAN (R 4.0.3)                          
    Rcpp             1.0.7    2021-07-07 [2] CRAN (R 4.0.3)                          
    remotes          2.4.1    2021-09-29 [2] CRAN (R 4.0.3)                          
    reshape2       * 1.4.4    2020-04-09 [2] CRAN (R 4.0.3)                          
    rgdal            1.5-27   2021-09-16 [2] CRAN (R 4.0.3)                          
    rlang            0.4.12   2021-10-18 [2] CRAN (R 4.0.3)                          
    rmarkdown      * 2.11     2021-09-14 [2] CRAN (R 4.0.3)                          
    rprojroot        2.0.2    2020-11-15 [2] CRAN (R 4.0.3)                          
    rstudioapi       0.13     2020-11-12 [2] CRAN (R 4.0.3)                          
    scales           1.1.1    2020-05-11 [2] CRAN (R 4.0.3)                          
    sessioninfo      1.1.1    2018-11-05 [2] CRAN (R 4.0.3)                          
    sf             * 1.0-4    2021-11-14 [1] CRAN (R 4.0.3)                          
    sp             * 1.4-6    2021-11-14 [1] CRAN (R 4.0.3)                          
    stringi          1.7.5    2021-10-04 [2] CRAN (R 4.0.3)                          
    stringr          1.4.0    2019-02-10 [2] CRAN (R 4.0.3)                          
 VP terra            1.4-11   2021-11-24 [2] CRAN (R 4.0.3)                          
    testthat         3.1.0    2021-10-04 [2] CRAN (R 4.0.3)                          
 VP tibble           3.1.5    2021-11-07 [2] CRAN (R 4.0.3)                          
    tidyselect       1.1.1    2021-04-30 [2] CRAN (R 4.0.3)                          
    units            0.7-2    2021-06-08 [2] CRAN (R 4.0.3)                          
    usethis          2.1.0    2021-10-16 [2] CRAN (R 4.0.3)                          
    utf8             1.2.2    2021-07-24 [2] CRAN (R 4.0.3)                          
    vctrs            0.3.8    2021-04-29 [2] CRAN (R 4.0.3)                          
    viridisLite      0.4.0    2021-04-13 [2] CRAN (R 4.0.3)                          
    withr            2.4.2    2021-04-18 [2] CRAN (R 4.0.3)                          
    xfun             0.27     2021-10-18 [2] CRAN (R 4.0.3)                          
    XML              3.99-0.8 2021-09-17 [2] CRAN (R 4.0.3)                          
    yaml             2.2.1    2020-02-01 [2] CRAN (R 4.0.3)                          
    zoo              1.8-9    2021-03-09 [2] CRAN (R 4.0.3)                          

[1] /home/NINA.NO/bernardo.brandao/R/x86_64-pc-linux-gnu-library/4.0
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

 V โ”€โ”€ Loaded and on-disk version mismatch.
 P โ”€โ”€ Loaded and on-disk path mismatch.

`util_extract_multibuffer` as a separate function

Hi,

discussing with @Nowosad by email, I was looking for a function in which I can calculate a more generic function based on raster values for multiple buffers around points. He pointed me to the show_shareplot() function.

So I started to build upon that. Currently it uses internally defined functions (.extract_multibuffer, that calls .share()) to create a data.frame (tibble, indeed) and plot it. Alternatively, it can also return the data.frame if return_df = TRUE.

I propose this internal function could be a separate function, in which one can calculate the landscape share (freq. of raster values). I extended this a little to allow (so far) the direct calculation of the relative frequency of raster values within each buffer (if rel_freq = TRUE) and a function (any, given by the user) of these values within each buffer (if fun is given).
I also made it more flexible the way the series of buffer sizes is created - now a vector of values can be passed to the buffer_width, and they are used if max_width = NULL. As an example, this might be useful when one wants to calculate the share from 250m to 50 km, but not for all increments of 250m, which can be quite computationally demanding.
I've put this as new function called util_extract_multibuffer(), which is found in the branch multibuffer in my fork of the repo, here: https://github.com/bniebuhr/landscapetools/tree/multibuffer
From my experience in landscape ecology, I think this can be quite useful, beyond just calculating the number or proportion of each raster class - and landscapetools a good place for that.

Based on that, a possibility is to set a new argument for this calculated data.frame to be a parameter in the show_shareplot function - in case this data.frame was already calculated through util_extract_multibuffer. I have also implemented that. So the main thing here would be to decouple both functions - show_shareplot() and the internal ones it uses - called here util_extract_buffer.

However, in this last case, if the output data.frame was calculated based on a function (parameter fun) instead of the "raw" landscape share, a different type of plot should be done. So maybe new function would be required here, instead of show_shareplot().

So I write this issue to raise this idea - you may test it through the branch multibuffer in my fork, and we can develop from that, if you think it is worth it.

Issues with `show_landscape()` for categorical rasters

Today, I started working on #17.
My first step is to make the new functions in the same fashion as existing ones, however I've got some issues with plotting a categorical raster:

library(landscapemetrics)
library(landscapetools)
library(raster)
#> Loading required package: sp
data("podlasie_ccilc")
podlasie_ccilc2 = as.factor(podlasie_ccilc)
# error 1
show_landscape(podlasie_ccilc, discrete = TRUE)
#> Error: Continuous value supplied to discrete scale
# error 2
show_landscape(podlasie_ccilc2, discrete = TRUE)
#> Error in names(x) <- value: 'names' attribute [1] must be the same length as the vector [0]

Created on 2019-02-17 by the reprex package (v0.2.1)

show_shareplot function cannot be found

Hi there! Just installed the landscapetools package off CRAN and immediately ran into this error:

show_shareplot(classified_landscape, new_point, 10, 50)

# Error in show_shareplot() : could not find function "show_shareplot"

Is this function missing from the CRAN version?

Thanks for your time :)

Session Info
setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio   

Packages ------------------------------------------------------------------------------
 package          * version date       lib source       
landscapetools   * 0.5.0   2019-02-25 [1] CRAN (R 4.0.2) 

Generate neutral landscapes that match exactly the extent (non-NA cells) of another raster

Hey,

I have a raster depicting a particular environmental variable (e.g. altitude, landcover, etc...). This raster has several NA cells in the edges. Let's imagine that I would like to incorporate this raster and a neutral landscape (NL) layer within a statistical framework. Both must have the same resolution and extent. However, because the environmental raster has NA cells in the edges, when I create a NL layer based on the extent of the previous raster, the output layer is larger. If I crop the NL layer to the same size of the environmental raster, I will necessarily loose information from the edges.

Please find below a reproducible code that illustrates my problem:

library(raster)
library(NLMR)

#create a raster
r<-raster(ncol=100, nrow=100, xmn=0,xmx=100,ymn=0,ymx=100)
values(r) <- runif(ncell(r), min=1,max=100)

#insert NA values in the edges
r[c(1:500, 9500:10000)]<-NA

#create a distance gradient landscape
dist.grad<-nlm_distancegradient(ncol=100, nrow=100,origin=c(0,1,0,1))

#assign the same extent as the environmental raster
dist.grad@extent<-extent(r)

#plot both layers
plot(dist.grad)
plot(r, add=T)

#if I mask the dist.grad layer to the exact size of r (i.e. not including NAs), I will loose information from #the edges in the NL layer

dist.grad1 <- mask(dist.grad, r)

I really appreciate the effort to make this possible :)

show_landscape coloring bug with ratified raster

I have just noticed a potential bug, when show_landscape() is used for a raster with classes defined by ratify(). Please see the reproducible example below:

Lets first look at the default map directly, without classification trough ratify():

show_landscape(landscapetools::classified_landscape, discrete=TRUE)

grafik

Now we classify the three land uses with different names, and execute show_landscape() with the default (wrong!) color scale:

# Ratify raster and define 3 example class names for landuse 1, 2 and 3:
ls <- raster::ratify(landscapetools::classified_landscape)
levels(ls)[[1]] = cbind(levels(ls)[[1]], 
                        c("Land Use 1" = "Bare (lu1)", "Land Use 2" = "Rainforest (lu2)", "Land Use 3" = "Agriculture (lu3)"))

# Show landscape with default (wrong!) fill scale:
show_landscape(ls, discrete=TRUE)

This produces the following map:
grafik
you can already see, that the legend order is the same if you look at the numbers in the brackets, which were the original land use numbers, but the coloring of the patches changed on the map.
Now we overwrite the default fill scale from show_landscape():

# Show landscape with overwritten (correct!) fill scale:
show_landscape(ls, discrete=TRUE) +
  scale_fill_viridis_d()

This produces the following map which has the correct legend order:
grafik

I assume, the error is due to the order of factors, where the ratify levels are defined.
Cheers, nldoc

Wrong result while using weighting in the util_classify function

I am unsure if this is a bug or just my expectations about this function are wrong. I want to classify the r raster into two classes having the same number of pixels. However, the result has more pixels of the second class (see a reprex below).

If it is a bug, I think it is inside of the util_calc_boundaries() function...

library(raster)
#> Loading required package: sp
library(NLMR)
library(landscapetools)

set.seed(2020-01-25)
r = nlm_planargradient(100, 100, direction = 90)
r2 = util_classify(r, weighting = c(0.5, 0.5))

freq(r2)
#>      value count
#> [1,]     1  4941
#> [2,]     2  5059

plot(r)

plot(r2)

Created on 2020-01-25 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> โ”€ Session info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  setting  value                          
#>  version  R version 3.6.2 (2019-12-12)   
#>  os       Fedora 31 (Workstation Edition)
#>  system   x86_64, linux-gnu              
#>  ui       X11                            
#>  language (EN)                           
#>  collate  en_US.UTF-8                    
#>  ctype    en_US.UTF-8                    
#>  tz       Europe/Warsaw                  
#>  date     2020-01-25                     
#> 
#> โ”€ Packages โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  package        * version    date       lib source                          
#>  assertthat       0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                  
#>  backports        1.1.5      2019-10-02 [1] CRAN (R 3.6.1)                  
#>  callr            3.4.0      2019-12-09 [1] CRAN (R 3.6.2)                  
#>  checkmate        1.9.4      2019-07-04 [1] CRAN (R 3.6.0)                  
#>  cli              2.0.1      2020-01-08 [1] CRAN (R 3.6.2)                  
#>  codetools        0.2-16     2018-12-24 [2] CRAN (R 3.6.2)                  
#>  crayon           1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                  
#>  curl             4.3        2019-12-02 [1] CRAN (R 3.6.2)                  
#>  desc             1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                  
#>  devtools         2.2.1      2019-09-24 [1] CRAN (R 3.6.1)                  
#>  digest           0.6.23     2019-11-23 [1] CRAN (R 3.6.1)                  
#>  ellipsis         0.3.0      2019-09-20 [1] CRAN (R 3.6.1)                  
#>  evaluate         0.14       2019-05-28 [1] CRAN (R 3.6.0)                  
#>  fansi            0.4.1      2020-01-08 [1] CRAN (R 3.6.2)                  
#>  fs               1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                  
#>  glue             1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                  
#>  highr            0.8        2019-03-20 [1] CRAN (R 3.6.0)                  
#>  htmltools        0.4.0      2019-10-04 [1] CRAN (R 3.6.1)                  
#>  httr             1.4.1      2019-08-05 [1] CRAN (R 3.6.0)                  
#>  knitr            1.27       2020-01-16 [1] CRAN (R 3.6.2)                  
#>  landscapetools * 0.6.0      2019-11-14 [1] local                           
#>  lattice          0.20-38    2018-11-04 [2] CRAN (R 3.6.2)                  
#>  magrittr         1.5        2014-11-22 [1] CRAN (R 3.6.0)                  
#>  memoise          1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                  
#>  mime             0.8        2019-12-19 [1] CRAN (R 3.6.2)                  
#>  NLMR           * 1.0        2020-01-23 [1] CRAN (R 3.6.2)                  
#>  pkgbuild         1.0.6      2019-10-09 [1] CRAN (R 3.6.1)                  
#>  pkgload          1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                  
#>  prettyunits      1.1.0      2020-01-09 [1] CRAN (R 3.6.2)                  
#>  processx         3.4.1      2019-07-18 [1] CRAN (R 3.6.0)                  
#>  ps               1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                  
#>  R6               2.4.1      2019-11-12 [1] CRAN (R 3.6.1)                  
#>  raster         * 3.0-11     2020-01-19 [1] Github (rspatial/raster@4988ed0)
#>  Rcpp             1.0.3      2019-11-08 [1] CRAN (R 3.6.1)                  
#>  remotes          2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                  
#>  rlang            0.4.2.9001 2020-01-19 [1] Github (r-lib/rlang@cdf1391)    
#>  rmarkdown        2.0        2019-12-12 [1] CRAN (R 3.6.2)                  
#>  rprojroot        1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                  
#>  sessioninfo      1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                  
#>  sp             * 1.3-2      2019-11-07 [1] CRAN (R 3.6.1)                  
#>  stringi          1.4.5      2020-01-11 [1] CRAN (R 3.6.2)                  
#>  stringr          1.4.0      2019-02-10 [1] CRAN (R 3.6.1)                  
#>  testthat         2.3.1      2019-12-01 [1] CRAN (R 3.6.2)                  
#>  usethis          1.5.1      2019-07-04 [1] CRAN (R 3.6.0)                  
#>  withr            2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                  
#>  xfun             0.12       2020-01-13 [1] CRAN (R 3.6.2)                  
#>  xml2             1.2.2      2019-08-09 [1] CRAN (R 3.6.0)                  
#>  yaml             2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                  
#> 
#> [1] /home/jn/R/x86_64-redhat-linux-gnu-library/3.6
#> [2] /usr/lib64/R/library
#> [3] /usr/share/R/library

util_facetplot color scales

different color scales for different facets - would allow to plot raster with different value scales next to each other for an easy overview of different env. data for a specific site for example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.