Selecting a certain metrics from stdmetrics #679
Replies: 4 comments 2 replies
-
I need a minimal reproducible example. The two functions seems to return exactly the same data (i fixed your code btw) library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile, filter = "-keep_random_fraction 0.5")
f1=function(X,Y, Z, Intensity, ReturnNumber,Classification) {
ans = stdmetrics(X,Y,Z,Intensity,ReturnNumber,Classification,dz=1, zmin=0)
ans = ans["zq25"]
return(ans)
}
prediction1 <- pixel_metrics(las, ~f1(X,Y, Z, Intensity, ReturnNumber,Classification), 10) # predicting model mapping
plot(prediction1, col = height.colors(50))
f=function(z) {
zq25 = quantile(z, c(0.25))
return(list(zq25 = zq25))
}
prediction2<-pixel_metrics(las, ~f(Z), res = 10)
plot(prediction2, col = height.colors(50)) |
Beta Was this translation helpful? Give feedback.
-
setwd("E:/Lidar_2022/R/trials")
las <- readLAS("E:/Lidar_2022/R/trials/16SFC262726.las")
dtm <- rasterize_terrain(las, res = 1, algorithm = tin(), keep_lowest = FALSE)
lasnorm <- normalize_height(las, dtm)
f1=function(X,Y, Z, Intensity, ReturnNumber,Classification) {
ans = stdmetrics(X,Y,Z,Intensity,ReturnNumber,Classification,dz=1, zmin=0)
ans = ans["zq25"]
return(list(ans))
}
prediction1 <- pixel_metrics(lasnorm, ~f1(X,Y, Z, Intensity, ReturnNumber,Classification), res =20) # predicting model mapping
plot(prediction1, col = height.colors(50)) # some plotting
f=function(z) {
zq25 = quantile(z, c(0.25))
return(list(zq25 = zq25))
}
prediction2<-pixel_metrics(lasnorm, ~f(Z), res = 20)
plot(prediction2, col = height.colors(50)) # some plotting When I run my code, function "f1" gives me an empty raster file, otherwise function "f" gives me a raster file with data within. |
Beta Was this translation helpful? Give feedback.
-
empty data vs non-empty data is not "different results". One is buggy, the other is correct. I already fixed your bug in my previous anwser. |
Beta Was this translation helpful? Give feedback.
-
Aha, Thanks for correcting it. As I want to use multiple metrics from "stdmetrics", I write my code as below. f=function(X,Y, Z, Intensity, ReturnNumber,Classification) {
ans = stdmetrics(X,Y,Z,Intensity,ReturnNumber,Classification,dz=1, zmin=0)
ans = ans[c("zmean", "zsd", "pzabove2","zq5","zq15","zq35","zq40","zq45","zq95","zpcum6","zpcum7","isd","ipcumzq10",
"ipcumzq30","ipcumzq90","p1th","p2th")]
volume = -16.18216 + 0.1314547 * ans$zmean + 0.5586847 * ans$zsd + 0.05094551 * ans$pzabove2 - 0.8545914 * ans$zq5 - 3.435632 * ans$zq15 + 0.05012992 * ans$zq35 + 0.07849599 * ans$zq40 + 0.003158031 * ans$zq45 + 5.12619*10^(-5) * ans$zq95 - 0.004623234 * ans$zpcum6 - 0.01141505 * ans$zpcum7 + 6.68966*10^(-5) * ans$isd + 0.03436324 * ans$ipcumzq10 + 0.02746617 * ans$ipcumzq30 + 0.2301962 * ans$ipcumzq90 - 0.06276224 * ans$p1th + 0.0969937 * ans$p2th
lambda = 0.3030303
return((lambda*volume+1)^(1/lambda)) #<- I edited this part from # return(list((lambda*volume+1)^(1/lambda)))
}
prediction <- pixel_metrics(lasnorm, ~f(X,Y, Z, Intensity, ReturnNumber,Classification), 2) # predicting model mapping
plot(prediction, col = height.colors(50)) Are these codes look okay? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I tried to use certain metrics from "stdmetrics" metrics.
I know there are different ways like selecting certain metrics or defining certain metrics.
However, I got a different result when I tried both ways.
I believe the below codes should give me the same results.
But I don't know why. And I am not sure the first code is correct.
#1
#2
Beta Was this translation helpful? Give feedback.
All reactions