r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
614 stars 134 forks source link

Calculation of pulse, point density off? #784

Open Silviculturalist opened 1 month ago

Silviculturalist commented 1 month ago

Is it expected that the calculation of the pulse, point density / m**2 does not align with the manual calculation?

library(lidR)
LASfile = system.file("extdata","example.laz",package='rlas')
las = readLAS(LASfile)
las = retrieve_pulses(las)
summary(las)

my_metrics <- function(pulseID)
{
  return(list(nPulses = length(unique(pulseID))))
}

result = cloud_metrics(las,~my_metrics(pulseID))
result$nPulses/area(las)

summary(las) provides pulse density as 2.63 pulses/m2 whereas manual calculation gives 2.83?

Jean-Romain commented 1 month ago

The summary looks only at pre-computed number of first return while retrieve_pulse used the gpstime attribute in order to compute the exact pulse ID of each point. This way if you have a 2nd or 3rd return only without the first one (e.g. on the edge of the dataset) you still get a pulse.

The difference should be minimal in most cases but here you chose an extraordinary tiny dataset (30 points) where a single point difference can change a lot the final value.

Silviculturalist commented 1 month ago

Yes, difference is minimal, noticed some decimal differences on my real dataset. Small dataset here only as reprex. Maybe it can be clarified in your documentation for summary function ?

Something like - # pulses, first return only?