Coder Social home page Coder Social logo

Comments (10)

mhesselbarth avatar mhesselbarth commented on August 22, 2024 1

Actually all possible options (level, metric, type, what, ...) needs to be NULL. Definitely worth to mention. I will update the documentation next week.

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Oh...we forgot to adapt sample_lsm() to the new structure how metrics are selected (basically list_lsm()). However, list_lsm() doesn't has the option what = "all" anymore, but all metrics are selected if nothing is specified at all. Do we want to bring back the "all" option?

Anyways, should work now (ddfa819)

library(landscapemetrics)
data("landscape")
points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
points_sp <- sp::SpatialPoints(points)
sample_lsm(landscape,
           points = points_sp, 
           size = 15)

from landscapemetrics.

Nowosad avatar Nowosad commented on August 22, 2024

Thanks @mhesselbarth.
Bringing back the all option is not necessary, but it would be nice to add info that what = NULL means all metrics are calculated...

from landscapemetrics.

Nowosad avatar Nowosad commented on August 22, 2024

One more question:
sample_lsm() with return_plots = TRUE gives a tibble with two list columns - one for the landscape summary and one with new rasters. Why is that? Shouldn't it be just the same output as the first one, but with one additional column for rasters?

library(landscapemetrics)
points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
sample_lsm(landscape, points = points, size = 15, what = "lsm_l_np")
#> # A tibble: 3 x 8
#>   layer plot_id level     class    id metric value percentage_inside
#>   <int>   <int> <chr>     <int> <int> <chr>  <dbl>             <dbl>
#> 1     1       1 landscape    NA    NA np         8              80. 
#> 2     1       2 landscape    NA    NA np         7              74.7
#> 3     1       3 landscape    NA    NA np         7              64.
sample_lsm(landscape, points = points, size = 15, what = "lsm_l_np", return_plots = TRUE)
#> # A tibble: 3 x 4
#>   layer plot_id metrics          raster_sample_plots
#>   <int>   <int> <list>           <list>             
#> 1     1       1 <tibble [1 × 8]> <S4: RasterLayer>  
#> 2     1       2 <tibble [1 × 8]> <S4: RasterLayer>  
#> 3     1       3 <tibble [1 × 8]> <S4: RasterLayer>

Created on 2019-01-19 by the reprex package (v0.2.1)

from landscapemetrics.

Nowosad avatar Nowosad commented on August 22, 2024

(Btw, the name return_plots could be confusing - I assume it would give some kind of figure as an output. How about using return_rasters instead?)

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Sounds good!

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Done (11df79e)

from landscapemetrics.

Nowosad avatar Nowosad commented on August 22, 2024

One more question:
sample_lsm() with return_plots = TRUE gives a tibble with two list columns - one for the landscape summary and one with new rasters. Why is that? Shouldn't it be just the same output as the first one, but with one additional column for rasters?

library(landscapemetrics)
points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
sample_lsm(landscape, points = points, size = 15, what = "lsm_l_np")
#> # A tibble: 3 x 8
#>   layer plot_id level     class    id metric value percentage_inside
#>   <int>   <int> <chr>     <int> <int> <chr>  <dbl>             <dbl>
#> 1     1       1 landscape    NA    NA np         8              80. 
#> 2     1       2 landscape    NA    NA np         7              74.7
#> 3     1       3 landscape    NA    NA np         7              64.
sample_lsm(landscape, points = points, size = 15, what = "lsm_l_np", return_plots = TRUE)
#> # A tibble: 3 x 4
#>   layer plot_id metrics          raster_sample_plots
#>   <int>   <int> <list>           <list>             
#> 1     1       1 <tibble [1 × 8]> <S4: RasterLayer>  
#> 2     1       2 <tibble [1 × 8]> <S4: RasterLayer>  
#> 3     1       3 <tibble [1 × 8]> <S4: RasterLayer>

Created on 2019-01-19 by the reprex package (v0.2.1)

@mhesselbarth @marcosci and what do you think about that?

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

The reason why we nested the tibble was that I thought it becomes quite tricky if you select e.g. a patch-level metric and a class-level metric. In this case, you don't know the number of rows the resulting tibble has because that depends on the number of patches and classes in each sample plot.

But actually, using the plot_id this is straightforward. So IMHO, we could just return the tibble with an extra row (see 9630236; @marcosci please revert if you don't like that).

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Please reopen if someone is not happy with the solution

> points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
> sample_lsm(landscape, points = points, size = 15, what = c("lsm_c_ca", "lsm_l_np"), return_raster = TRUE)
# A tibble: 12 x 9
   layer plot_id level     class    id metric  value percentage_inside raster_sample_plots
   <int>   <int> <chr>     <int> <int> <chr>   <dbl>             <dbl> <list>             
 1     1       1 class         1    NA ca     0.0044              80.  <S4: RasterLayer>  
 2     1       1 class         2    NA ca     0.0051              80.  <S4: RasterLayer>  
 3     1       1 class         3    NA ca     0.0085              80.  <S4: RasterLayer>  
 4     1       1 landscape    NA    NA np     8                   80.  <S4: RasterLayer>  
 5     1       2 class         1    NA ca     0.0016              74.7 <S4: RasterLayer>  
 6     1       2 class         2    NA ca     0.0054              74.7 <S4: RasterLayer>  
 7     1       2 class         3    NA ca     0.0098              74.7 <S4: RasterLayer>  
 8     1       2 landscape    NA    NA np     7                   74.7 <S4: RasterLayer>  
 9     1       3 class         1    NA ca     0.0006              64.  <S4: RasterLayer>  
10     1       3 class         2    NA ca     0.0038              64.  <S4: RasterLayer>  
11     1       3 class         3    NA ca     0.01                64.  <S4: RasterLayer>  
12     1       3 landscape    NA    NA np     7                   64.  <S4: RasterLayer> 

from landscapemetrics.

Related Issues (20)

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.