Giter Site home page Giter Site logo

ropensci / nlmr Goto Github PK

View Code? Open in Web Editor NEW
65.0 14.0 17.0 138.96 MB

📦 R package to simulate neutral landscape models 🏔

Home Page: https://ropensci.github.io/NLMR/

R 75.69% C++ 21.23% TeX 3.07%
r spatial landscape-ecology neutral-landscape-model rstats r-package peer-reviewed

nlmr's People

Contributors

achubaty avatar actions-user avatar bitbacchus avatar csim063 avatar jeroen avatar maelle avatar marcosci avatar mattfrit avatar mhesselbarth avatar rekyt avatar rubak avatar yomoseco avatar z3tt 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  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  avatar

nlmr's Issues

nlm_gaussianfield

ropensci/software-review#188 (comment):

See above issues with setting the random seed in nlm_fBm

Setting the mean value of the field doesn't work because of the line pred_raster <- pred_raster - raster::cellStats(pred_raster, "min"). Is there a purpose for this line of code? Removing this produces Gaussian random field surfaces with the given mean.

Add lower = 0 to the checks for resolution, mag_var and nug

Some additions to the documentation could improve the usability of this function. I would recommend further explanation of what each of the variance parameters do, in a way that the implications for the generated surface can be interpreted. My understanding of these are that:

mag_var sets the variation of the broad landscape
nug sets the variation within the scale of autocorr_range: low nug values will produce a highly spatially autocorrelated surface and high nug values a rougher surface.
Missing a reference, which would be useful for users to get a better understanding of how this function works.

nlm_polylands

ropensci/software-review#188 (comment):

I wonder if this would be simpler split into two functions for each of the options. I understand the thinking behind keeping them as one, but as there are no shared outputs, and few shared parameters, they may make more sense separately.

Some more information about what each of the parameters does here would be useful. For example, parameter R for option 2 is described as the interaction radius. I assumed this was related to the size of the landscape, so put in a value of 3 (so assuming that cells within a distance of 3 cells from each other are interacting). This causes the function to hang. It's the spatstat::rStrauss(200, gamma = g, R = R) that is doing this, and I found that it wouldn't run for me for a value of R > 0.1 (using g = 0.5).

like with nlm_neigh, rescale doesn't make sense here.

Expanding Gaussian Fields function

In spatial models the spatial field is often assumed to arise from a Matern covariance function. Would it be possible to allow the user to choose the model used to simulate the Gaussian Fields?

Update pubs

Somehow I am not able to create a new branch so here is a copy of the updated rmd. Also made the style consistent for all refs.

---
output: github_document
---

We try to maintain a list here of publications that have used the `nlmr` package. If you have used `nlmr` in your own work, we would love to hear from you. Please [file an issue on GitHub](https://github.com/marcosci/nlmr/issues/new/) so we can add your work to this list.

* Betts MG, Wolf C, Pfeifer M, Banks-Leite C., [...], Young R, Ewers RM (2019) Extinction filters mediate the global effects of habitat fragmentation on animals. Science 366(6470):1236-1239. [10.1126/science.aax9387](https://doi.org/10.1126/science.aax9387)
* Fletcher R, Fortin MJ (2018) Land-Cover Pattern and Change. In: Spatial Ecology and Conservation Modeling. Springer, Cham. DOI: [10.1007/978-3-030-01989-1_3](https://doi.org/10.1007/978-3-030-01989-1_3)
* Hesselbarth MHK, Sciaini M, With K, Wiegand K, Nowosad J (2019) landscapemetrics: an open‐source R tool to calculate landscape metrics. Ecography 42(10):1648-1657.  DOI: [10.1111/ecog.04617](https://doi.org/10.1111/ecog.04617)
* Langhammer M, Thober J, Lange M, Frank K, Grimm V (2019) Agricultural Landscape Generators for Simulation Models: A Review of Existing Solutions and an Outline of Future Directions. Ecological Modelling 393:135–51. [10.1016/j.ecolmodel.2018.12.010](https://doi.org/10.1016/j.ecolmodel.2018.12.010)
* Nowosad J, Stepinski T (2018). Information-theoretical approach to measuring landscape complexity. DOI: [10.1101/383281](https://doi.org/10.1101/383281)
* Poggi S, Papaïx J, Lavigne C et al. (2018) Issues and challenges in landscape models for agriculture: from the representation of agroecosystems to the design of management strategies. Landscape Ecology 33(10):1679-1690. DOI: [10.1007/s10980-018-0699-8](https://doi.org/10.1007/s10980-018-0699-8)
* Scherer C, Radchuk V, Franz M, Thulke H-H, Lange M, Grimm V, Kramer-Schadt S (accepted) Moving infections: Individual movement decisions drive disease persistence in spatially structured landscapes. Oikos.
* Sciaini M, Fritsch M, Scherer C, Simpkins CE (2018) NLMR and landscapetools: An integrated environment for simulating and modifying neutral landscape models in R. Methods Ecology and Evolution 9(11):2240-2248. DOI: [10.1111/2041-210X.13076](https://doi.org/10.1111/2041-210X.13076)

nlm_mosaic

ropensci/software-review#188 (comment):

The collect stage overwrites the first step, need to change the for loop on line 91 to for (i in 2:n) (can also remove the i <- 2 from line 86)

In addition, so more information about how these work, and when you would use them would be useful.

nlm_planargradient bug when nrow != ncol

On my machine, when simulating a planar gradient landscape using nlm_planargradient() , if nrow != ncol, I get a landscape where the values are shuffled, thereby producing an incorrect result:

# When nrow == ncol, it works perfectly
l = nlm_planargradient(ncol=10, nrow = 10)
show_landscape(l)

planargradient_nrowEncol

# When nrow != ncol, the values are shuffled
l2 = nlm_planargradient(ncol=10, nrow = 9)
show_landscape(l2)

planargradient_nrowNEncol

I checked out the function and flipped the logic for the byrow parameter when creating col_index and row_index, and this seemed to solve the problem. Note the comments at the end of lines 12 and 13.

New function:

r.nlm_planargradient = function (ncol, nrow, resolution = 1, direction = NA, rescale = TRUE) 
{
  checkmate::assert_count(ncol, positive = TRUE)
  checkmate::assert_count(nrow, positive = TRUE)
  checkmate::assert_numeric(direction)
  checkmate::assert_logical(rescale)
  if (is.na(direction)) {
    direction <- stats::runif(1, 0, 360)
  }
  eastness <- sin((pi/180) * direction)
  southness <- cos((pi/180) * direction) * -1
  col_index <- matrix(0:(ncol - 1), nrow, ncol, byrow = TRUE) # This didn't have byrow (assume FALSE)
  row_index <- matrix(0:(nrow - 1), nrow, ncol, byrow = FALSE) # This was set to TRUE
  gradient_matrix <- (southness * row_index + eastness * col_index)
  gradient_raster <- raster::raster(gradient_matrix)
  raster::extent(gradient_raster) <- c(0, ncol(gradient_raster) * 
                                         resolution, 0, nrow(gradient_raster) * resolution)
  if (rescale == TRUE) {
    gradient_raster <- util_rescale(gradient_raster)
  }
  return(gradient_raster)
}

I used this new function here and it worked:

l3 = r.nlm_planargradient(ncol = 10, nrow = 9)
show_landscape(l3)

planargradient_ncolNEnrowFIXED

Also, it would be great if you could add user_seed like you have for some of the other functions.

Otherwise, thanks for a fantastic package!!

Session Info
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] viridis_0.5.1        viridisLite_0.3.0    landscapetools_0.5.0 raster_3.0-7         sp_1.3-1            
[6] NLMR_0.4.2           dplyr_0.8.3          oSCR_0.42.0         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       rstudioapi_0.10  magrittr_1.5     munsell_0.5.0    tidyselect_0.2.5 colorspace_1.4-1 lattice_0.20-38 
 [8] R6_2.4.0         rlang_0.4.0      tools_3.6.1      parallel_3.6.1   grid_3.6.1       gtable_0.3.0     checkmate_1.9.4 
[15] digest_0.6.21    lazyeval_0.2.2   assertthat_0.2.1 tibble_2.1.3     crayon_1.3.4     gridExtra_2.3    ggplot2_3.2.1   
[22] purrr_0.3.2      codetools_0.2-16 glue_1.3.1       labeling_0.3     compiler_3.6.1   pillar_1.4.2     scales_1.0.0    
[29] backports_1.1.4  pkgconfig_2.0.3 

Vignettes

ropensci/software-review#188 (comment):

Vignettes: There are a number of vignettes and not all are finished and it appears the primary utilitiy for some of them is to populate sections the project website. Having these unfinished vignettes on CRAN and as part of the installed package should be avoided. I would like to see just the "getstarted" vignette, and, when completed, the "background" vignette. I am not sure if this will solve the issue, but perhaps adding the vignettes you don't want pushed to CRAN to .Rbuildignore will allow you to build the package for submission but still use those vignettes for the website. Just a guess on my part that this will work.
Also, in "getstarted", I'd drop the raster section. It is useful, but beyond scope of this vignette.

-> finishing background vignette

Failure building pkgdown

Build log: https://dev.ropensci.org/job/NLMR/lastBuild/console

Writing 'articles/index.html'
Reading 'vignettes/articles/nlm_software_heritage.Rmd'
Writing 'articles/articles/nlm_software_heritage.html'
Reading 'vignettes/articles/overview_tips.Rmd'
Error : callr subprocess failed: At least one layer must contain all faceting variables: `id`.
* Plot is missing `id`
* Layer 1 is missing `id`
Error: callr subprocess failed: callr subprocess failed: At least one layer must contain all faceting variables: `id`.
* Plot is missing `id`
* Layer 1 is missing `id`
Execution halted
Build step 'Execute shell' marked build as failure

Fix spatstat import

NLMR was taken down from CRAN because the spatstat package was split into several sub-packages with their last major release a few weeks back.

Instead of importing spatstat, now the specific sub-packages need to be imported which are spatstat.geom and spatstat.core for NLMR.

I created a pull request that should fix this (#72)

nlm_randomcluster -> nlm_neigh

ropensci/software-review#188 (comment):

The neighbourhood input is an integer here, whereas it was method names in nlm_neigh. It would be helpful to unify this (and the spelling of neighbourhood - one US, one British English). My preference would be the numbers, because I always forget the names and it's less to type!

Nomenclature

Find a proper nomenclature - maybe one that orders everything into NLM and helper functions?

plot() doesn't work anymore

If i just use the code of the vignette to plot a virtual landscape, I get an error. eg:
x <- NLMR::nlm_random(20,20)
plot(x)

Error in as.double(y) :
cannot coerce type 'S4' to vector of type 'double'

nlm_gaussianfield doesn't work properly

Hello! I used the parameter autocorr_range of nlm_gaussianfield function to set different max range but get very similar results (especially x.3,x.4,x.5,x.6 in the plot below). Does "autocorr_range" work properly?

x.1 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=5,user_seed=2021) 
x.2 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=10,user_seed=2021) 
x.3 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=20,user_seed=2021) 
x.4 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=30,user_seed=2021) 
x.5 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=40,user_seed=2021) 
x.6 <- nlm_gaussianfield(ncol=50, nrow=50, autocorr_range=50,user_seed=2021) 
varstack <- stack(x.1,x.2,x.3,x.4,x.5,x.6)
names(varstack) <- c("x.01","x.02","x.03","x.04","x.05","x.06")
show_landscape(varstack,n_col=3)

produce

image

Thanks!

nlm_gaussianfield()

General pattern changes when increasing the range of autocorrelation:

library(NLMR)
#> Warning: Paket 'NLMR' wurde unter R Version 3.4.3 erstellt

gfs <- as.list(20)

suppressWarnings(
  for (i in 1:20) {
    set.seed(1)
    gfs[i] <- nlm_gaussianfield(ncol = 50, nrow = 50, mag_var = 3, nug = 0.01, autocorr_range = i)
  }
)

util_facetplot(gfs)

Created on 2018-03-16 by the reprex package (v0.2.0).

One would expect the same general pattern with increasing clustering (as one would decrease the resolution) but the pattern changes (i.e. same pattern for facets 1:8, 9:14, 15:20). Not sure if this is a bug or what we expect the algorithm to do - for me it seems unlogical.

(Edit: I used the CRAN version of NLMR to easily plot the facet of all nlms, but the outcome is exactly the same with the dev version.)

Makevars flags do not work

Hi Marco,

I just have seen, that the makevars does not work. One can not overwrite the CXX_STD compiler, but you can overwrite the one which builds the package by PKG_CXX_STD. However, the 11 standard is already the default compiler, but if you plan to change to another standard, the above flag will make it compile.

Cheers, Johannes

nlm_planargradient

ropensci/software-review#188 (comment):

The call to nlm_planargradient (L66) is misspecified. It should be
gradient_raster <- nlm_planargradient(ncol, nrow, direction = direction)

or

gradient_raster <- nlm_planargradient(ncol, nrow, resolution, direction)

or change the order of the arguments to nlm_planargradient

Facet plot

RasterStack/List of Raster -> raster2tibble -> facet_* plot

Landscape heterogeneity index

Error in randomElement

The rasterize function in randomElement sometimes throws the error:

Error in if (x2a < rxmn) { : missing value where TRUE/FALSE needed

... don't know why, we have to check that

nlm_mpd

ropensci/software-review#188 (comment):

Generally really clearly explained - more detail on what effect changing rand_dev has on the end landscape would be useful. From some experimenting, it looks like it just changes the overall variance of the landscape

nlmr package removed from CRAN

Hello,

When I tried to install the nlmr package, I discovered that it had been removed from CRAN.

Having a lot of trouble to install the package from the source file, I would like to know if someone has a solution to propose me to install it on Rstudio !

Best,

Landscape optimization

Would be nice to have the functionality of LG (http://www.lg.ethz.ch/).
Would also mean that we need landscapemetrics and NLMR as dependencies, as well as the GenAlg package.

Any opinions? Or another package for that?

nlm_neigh

ropensci/software-review#188 (comment):

Additional checks: set lower and upper values in the assert_numeric statement for p_neigh and p_empty; check neighborhood contains the accepted values; check proportions sums to 1.

Note on the last one - it's important because if proportions do not sum to 1, then the remaining cells are assigned to class 0, meaning that proportions = c(0.1, 0.1, 0.1) would result in a landscape with 80% class 0 and 10% the other two.

Because the categories are integers, it doesn't make sense to rescale the raster for this function. I would suggest defaulting to FALSE or getting rid of the option altogether.

rev(proportions) on line 91 means that the proportions are assigned to the categories backwards. e.g. nlm_neigh(ncol = 50, nrow = 50, p_neigh = 0.5, p_empty = 0.5, categories = 2, proportions = c(0.75, 0.25)) will result in a landscape where 25% is assigned to 0 and 75% to 1. This could be confusing when the proportions are closer.

nlm_fbm

ropensci/software-review#188 (comment):

nlm_fbm:

Add in checkmate::assert_true(fract_dim > 0).

The code checks that fract_dim is < 2, but the help file states that this parameter is including 2 - fract_dim = numeric in (0, 2]

Values of fract_dim between ~1.56 and ~1.99 generate an error. This is caused by the RandomFields::RFsimulate function.

If this function is run with a random seed, it holds onto it until a new seed is set. This can be fixed by removing the if (!is.null(user_seed)) statement. The default user_seed = NULL will set the seed back to NA.

Metrics

Implement more metric functions

  • Fractal dimension
  • Hurst
  • Lacunarity
  • ... ?

Error in randomClusterNLM()

Get the following error message Error in if (x2a < rxmn) { : missing value where TRUE/FALSE needed when running randomClusterNLM().

Issue only appears to occur when function is run with nCol = 100 and nRow = 100.

nlm_curds & nlm_wheys

ropensci/software-review#188 (comment):

No checkmate tests at the beginning.

There is borrowed code between these two. It might make sense to combine them (with a wheys T/F option), or to use the nlm_curds function inside nlm_wheys instead of repeating the code.

These seem quite different in the way they are written to the other functions. Primarily in that the others all specify nrow, ncol, resolution, whereas these specify extent. Is it possible to harmonise these?

random multi band raster stack

Hello,

NLMR is a great package and perfect for a variety of random landscapes. I just stumbled across a small issue:

I try to create random multi-band stacks were the band values are corresponding e.g. if low value in raster A always high values in raster B, similar to an actual remote sensing multi-band raster stack.

Have you already had a similar issue and could provide a way how to achieve it? thanks

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.