Coder Social home page Coder Social logo

Comments (5)

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Hey,

Thanks for finding this. I think the argument does not get passed on properly. I will try to fix this

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Okay, should be fixed in c5336d1

library(terra)
library(landscapemetrics)

#Create a 10 by 10 raster in which all cells are 1
r = rast(ncol=10, nrow=10)
values(r) = 1

#Randomly assign some of the values to NA
set.seed(123)  # For reproducibility
na_matrix = matrix(runif(100) < 0.8, nrow=10, ncol=10)

# Apply NA values to the raster based on the NA matrix
values(r)[na_matrix] = NA

#Assign crs
crs(r) = "EPSG:32633"

# show landscape patch ids
show_patches(landscape = r, class = 1, directions = 4, labels = TRUE)
#> $layer_1

# calculate the area
area_df <- lsm_p_area(landscape = r, directions = 4)

# get raster layer with values
area_ras <- spatialize_lsm(r, what = "lsm_p_area", directions = 4)

# those should be identical and four unique values
unique(area_df$value)
#> [1] 0.2592 0.1296 0.0648 0.1944
unique(area_ras$layer_1$lsm_p_area[])
#>       value
#> [1,]     NA
#> [2,] 0.1296
#> [3,] 0.0648
#> [4,] 0.2592
#> [5,] 0.1944

# this seems to be correct now
plot(area_ras$layer_1$lsm_p_area, col = viridis::viridis(n = 4, option = "E"))

# compare to function by the package
show_lsm(landscape = r, what = "lsm_p_area", class = 1, directions = 4, labels = TRUE)
#> $layer_1

Created on 2024-02-29 with reprex v2.1.0

Could you please try to install the Github version and see if results are correct now.

from landscapemetrics.

MStuhlmacher avatar MStuhlmacher commented on August 22, 2024

Great, thank you! It's on my list to try the updated version and report back

from landscapemetrics.

MStuhlmacher avatar MStuhlmacher commented on August 22, 2024

I installed the Github version and re-ran my code from above and it now works as expected. Thanks for solving that so quickly!

from landscapemetrics.

mhesselbarth avatar mhesselbarth commented on August 22, 2024

Cool 👍 Will close this, please re-open if needed

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.