Giter Club home page Giter Club logo

lidrmetrics's Introduction

lidRmetrics

Additional point cloud metrics for use with *_metric functions in the lidR package.

The package serves as a companion to the lidR package and offers a variety of functions for calculating different types of point cloud metrics. These include metrics_basic() for basic information about the point cloud, metrics_percentiles() for height percentiles, metrics_percabove() and metrics_dispersion() for characterizing the vertical structure. Additionally, metrics_echo() and metrics_echo2() provide information on the number and proportion of different return types, while metrics_interval() calculates the percentage of points by horizontal layers. More complex metrics such as metrics_kde and metrics_voxels() are also included. A comprehensive list of metrics and their corresponding functions can be found in the table below.

These individual functions serve as building blocks that can be combined to create various sets of metrics. The package includes three examples of such metric sets.

Installation

You can install the most recent version of the package by executing the code below:

devtools::install_github("ptompalski/lidRmetrics")
library(lidRmetrics)

Example usage

All of the functions in lidRmetrics are designed to be used with one of the *_metrics functions in the lidR package (e.g. pixel_metrics()).

For example:

library(lidR)
library(lidRmetrics)

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile, select = "*", filter = "-keep_random_fraction 0.5")

# you can run any metrics_* function with cloud_metrics()
m1 <- cloud_metrics(las, ~metrics_basic(Z))

# or you can run one of the metric sets in pixel_metrics()
m2 <- pixel_metrics(las, ~metrics_set2(Z, ReturnNumber, NumberOfReturns), res = 20)

# each metrics_* function has a convenient shortcut to run it with default parameters: 
m3 <- pixel_metrics(las, .metrics_set3, res = 20)

Please take a look at the vignette to learn more about creating customized metric sets.

List of metrics

Important: Is there a specific metric that you feel is missing from the package? If you have any suggestions or know of a metric you’d like to see included, please let me know! You can submit an issue or create a pull request on the repository.

Simple descriptive statistics - metrics_basic()

  • n - total number of returns
  • zmin, zmax, zmean, zvar, zsd, zcv, zskew, zkurt - elevation maximum, minimum, mean, standard deviation, coefficient of variation, skewness, and kurtosis

Height percentiles - metrics_percentiles()

  • zq1
  • zq5
  • zq10
  • ,
  • zq90,
  • zq95,
  • zq99

Proportion of returns above threshold height - metrics_percabove()

Proportion of returns above a user-defined threshold. By default, percent of returns above mean elevation, above 2 and 5 m are calculated.

  • pzabovemean
  • pzabove2
  • pzabove5
  • pzabove*

Vertical structure - metrics_dispersion()

  • ziqr - interquartile distance
  • zMADmean, zMADmedian - mean absolute deviation (MAD) from the mean and the median
  • CRR - canopy relief ratio ((mean - min) / (max – min))
  • zentropy, VCI - normalized Shannon diversity index, Vertical Complexity Index

see: van Ewijk, K. Y., Treitz, P. M., & Scott, N. A. (2011). Characterizing Forest Succession in Central Ontario using LAS-derived Indices. Photogrammetric Engineering and Remote Sensing, 77(3), 261-269

Cumulative point density - metrics_canopydensity()

Canopy density metrics as defined by Woods et al. 2008. Elevation range is divided into 10 equal intervals, and the cumulative proportion of returns in each interval is calculated. For example, zpcum3 is a cumulative percentage of returns located in lower 30% of maximum elevation. The results for the last (topmost) layer is not reported as it always equal to 100%. The number of layers (default = 10) can be specified by the user.

  • zpcum1
  • zpcum2
  • ...,
  • zpcum8
  • zpcum9

See: M. Woods, K. Lim, and P. Treitz. Predicting forest stand variables from LiDAR data in the Great Lakes – St. Lawrence forest of Ontario. The Forestry Chronicle. 84(6): 827-839.

L-moments metrics - metrics_Lmoments()

  • L1, L2, L3, L4 - 1st, 2nd, 3rd, and 4th L-moment
  • Lskew - L-moment skewness
  • Lkurt - L-moment kurtosis
  • Lcoefvar - L-moment coefficient of variation

Metrics based on leaf area density - metrics_lad()

lad_max, lad_mean, lad_cv, lad_min, lad_sum

Interval metrics - metrics_interval()

Interval metrics - proportion of returns between specified elevation intervals. Default intervals are: 0, 0.15, 2, 5, 10, 20, and 30.

  • pz_below_0 - proportion of returns below 0
  • pz_0.0.15 - proportion of returns between 0 and 0.15 m
  • pz_0.15.2
  • pz_2.5
  • pz_5.10
  • pz_10.20
  • pz_20.30
  • pz_above_30 - proportion of returns above 30

Number and proportion of returns by echo types - metrics_echo()

  • n_first, n_intermediate, n_last, n_single, n_multiple - Number of returns by echo types (First, Intermediate, Last; and Single, Multiple)
  • p_first, p_intermediate, p_last, p_single, p_multiple - Proportion of returns by echo types (First, Intermediate, Last; and Single, Multiple)
  • ratio_last_first, ratio_intermediate_first, ratio_multiple_single - Ratios of return counts

Number of points by return number - metrics_echo2()

  • n_return_1 - total number of 1st returns
  • n_return_2 - total number of 2nd returns
  • n_return_* - total number of * returns

A wrapper function for the rumple metric - metrics_rumple()

A wrapper of the lidR::rumple_index() function that allows to calculate rumple index without the need for CHM, and can be used directly in the e.g. pixel_metrics function. The function combines the two required steps, i.e. creating a surface model, and calculating rumple index, into one. Top surface is created using highest points within each pixel.

  • rumple

Metrics calculated using voxels - metrics_voxels()

A set of metrics calculated in a voxel space. For convenience, a point cloud is converted to a voxel space on the fly, without the need of using additional processing steps. Note, that because of the additional computation required to convert a point cloud to voxels, calculating voxel-based metrics is markedly slower than other metrics_* functions.

  • vn - total number of voxels
  • vFRall, vFRcanopy - filled ratio; FRall - a ratio between the number of filled voxels and all voxels located in the maximum extent of the point cloud. In case of FRcanopy empty voxels above the canopy are excluded in the calculations.
  • vzrumple - vertical rumple
  • vzsd, vzcv - voxel elevation standard deviation and coefficient of variation
  • OpenGapSpace, ClosedGapSpace, Euphotic, Oligophotic - Canopy volume classes based on Lefsky et al 1999

See: Lefsky, M. A., Cohen, W. B., Acker, S. A., Parker, G. G., Spies, T. A., & Harding, D. (1999). Lidar Remote Sensing of the Canopy Structure and Biophysical Properties of Douglas-Fir Western Hemlock Forests. Remote Sensing of Environment, 70(3), 339–361. doi:10.1016/S0034-4257(99)00052-8

Metrics based on kernel density estimation - metrics_kde()

Kernel density estimation (KDE) applied to the distribution of point cloud elevation (Z). KDE allows to create a probability density function (using a Guassian kernel). The density function is then used to detect peaks (function maxima), and attributes of those maxima. Based on similar metric available in Fusion (see references), with significant differences in the list of output statistics as well as the default bandwidth used when estimating kernel density.

  • kde_peaks_count - number of detected distribution maxima (peaks)
  • kde_peak1_elev - elevation (height) corresponding to the 1st peak
  • kde_peak2_elev - elevation (height) corresponding to the 2nd peak
  • kde_peak1_value - kernel density value at 1st peak
  • kde_peak2_value - kernel density value at 2nd peak
  • kde_peak1_diff - distance (height difference) between peaks 1 and 2
  • kde_peak2_diff - distance (height difference) between peaks 2 and 3

See: McGaughey, R.J., 2021. FUSION/LDV: Software for LIDAR Data Analysis and Visualization. http://forsys.cfr.washington.edu/software/fusion/FUSION_manual.pdf

Height of median energy - metrics_HOME()

  • HOME - calculations based on LAStools’ implementation of the HOME metric.

See: http://lastools.org/download/lascanopy_README.txt

GLCM (Grey-Level Co-Occurence Matrix) metrics of a canopy height model (CHM) - metrics_texture()

glcm_mean, glcm_variance, glcm_autoCorrelation, glcm_cProminence, glcm_cShade, glcm_cTendency, glcm_contrast, glcm_correlation, glcm_differenceEntropy, glcm_dissimilarity, glcm_energy, glcm_entropy, glcm_homogeneity1, glcm_homogeneity2, glcm_IDMN, glcm_IDN, glcm_inverseVariance, glcm_maxProb, glcm_sumAverage, glcm_sumEntropy, glcm_sumVariance

Requires the {ForestTools} package (https://github.com/andrew-plowright/ForestTools). ForestTools::glcm() function is used to calculate the GLCM statistics (see package manual for details)

Benchmarking

The processing time required for each function in the package varies, sometimes significantly, depending on the calculations involved. The figure below presents the average processing time for each metrics_* function included in the package. This benchmark was conducted using the “Megaplot.laz” dataset from the lidR package, with iterative calls to the pixel_metrics() function. It’s important to note that the results of this benchmark are dependent on the workstation’s specifications and should be considered as a relative indication of the processing time required.

The figure below presents the average processing time for each metrics_set* function.

lidrmetrics's People

Contributors

ptompalski avatar tgoodbody avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lidrmetrics's Issues

fix warnings in `metrics_rumple`

e.g.: In as.data.table.list(x, keep.rownames = keep.rownames, ... : Item 3 has 330 rows but longest item has 348; recycled with remainder.

Lower resolutions causing an error for metrics_set2

Hello, this is a useful package. I especially find the Lefsky metrics useful when gridded. I get an error when I try lower resolutions (res <15) for metrics_set2. Is there a way around this?

`library(lidR)
library(lidRmetrics)

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)

m3 <- grid_metrics(las, ~metrics_set2(X, Y, Z), res = 10)

Error in [.data.table(las@data, , if (!anyNA(.BY)) c(eval(call)), by = cells) :
Column 68 of result for group 292 is type 'double' but expecting type 'integer'. Column types must be consistent for each group.
In addition: There were 21 warnings (use warnings() to see them)
`

Fix table formating in readme

overall table width is too wide. Column widths don't make any sense either.
Setting column widths in kable (modifying the output html code) doesn't work.

Perhaps the best would be to just replace the table with a list or some nicely formatted text.

Error with metrics_set3()

Hello,

I'm running into an error while running lidRmetrics::metrics_set3() within lidR::pixel_metrics() on a single height-normalized LAZ point cloud tile that I can't quite figure out. In a nutshell, this is what the script is doing:

las <- readLAS(laz.file) # laz.file is a path to a height-normalized tile of LAZ data
rast.mets <- pixel_metrics(
  las,  
  ~lidRmetrics::metrics_set3(
    x = X,
    y = Y,
    z = Z,
    i = Intensity,
    ReturnNumber = ReturnNumber,
    NumberOfReturns = NumberOfReturns,
    threshold = c(1,3), 
    zintervals = c(0,0.5,1,2,4,8),
    pixel_size = 1,
    vox_size = 1
  ),
  res = 30
)

Here's the error and full traceback:

Error in `[.data.table`(las@data, , if (!anyNA(.BY)) lidRmetrics::metrics_set3(x = X, :
j doesn't evaluate to the same number of columns for each group

9. `[.data.table`(las@data, , if (!anyNA(.BY)) lidRmetrics::metrics_set3(x = X,
y = Y, z = Z, i = Intensity, ReturnNumber = ReturnNumber,
NumberOfReturns = NumberOfReturns, threshold = c(1, 3), zintervals = c(0,
0.5, 1, 2, 4, 8), pixel_size = 1, vox_size = 1), by = .(cells, ... at <text>#1

8. las@data[, if (!anyNA(.BY)) lidRmetrics::metrics_set3(x = X,
y = Y, z = Z, i = Intensity, ReturnNumber = ReturnNumber,
NumberOfReturns = NumberOfReturns, threshold = c(1, 3), zintervals = c(0,
0.5, 1, 2, 4, 8), pixel_size = 1, vox_size = 1), by = .(cells, ... at <text>#1

7. eval(parse(text = cmd))

6. eval(parse(text = cmd))

5. metrics_classic(las, call, grp, filter)

4. template_metrics.LAS(las, func, template, ...)

3. template_metrics(las, func, template, ...)

2. pixel_metrics.LAS(las.hgt, ~lidRmetrics::metrics_set3(x = X,
y = Y, z = Z, i = Intensity, ReturnNumber = ReturnNumber,
NumberOfReturns = NumberOfReturns, threshold = c(1, 3), zintervals = c(0,
0.5, 1, 2, 4, 8), pixel_size = 1, vox_size = 1), res = 30)

1. pixel_metrics(las.hgt, ~lidRmetrics::metrics_set3(x = X, y = Y,
z = Z, i = Intensity, ReturnNumber = ReturnNumber, NumberOfReturns = NumberOfReturns,
threshold = c(1, 3), zintervals = c(0, 0.5, 1, 2, 4, 8),
pixel_size = 1, vox_size = 1), res = 30)

Looks like the issue may be with the lidRmetrics::metrics_canopydensity() function? But <text>#1 appears to link to a commit that seems to have specifically addressed the number of columns issue at the core of the error. Furthermore, when I run metrics_canopydensity() directly, I don't get the same error. So, I'm a bit stumped -- any insights?

I'm running R v4.3.1, lidR v4.1.1 and have the latest version of lidRmetrics installed from GitHub.

If it's useful, you can access the tile in question here: https://drive.google.com/file/d/1pyCh90Phan5_J19LB-hCLEZoRkh1FUQf/view?usp=sharing. I've been able to run the function successfully on several other tiles of comparable data.

Thanks!
Mickey

make examples consistent across functions

Each example section should include

  • simple examples using lidR::cloud_metrics()
  • simple examples using lidR::pixel_metrics()
  • more complex example using lidR::pixel_metrics()
  • example using lidR::crown_metrics()
  • example using plot_metrics()

Error using metrics_set2 in pixel_metrics function with modified arguments

Hello!

I am running into a few issues using your metrics_set2() function within the lidR pixel_metrics() function. I was able to successfully use it when using cloud_metrics() on a series of small point clouds, clipped to the extent of some field plots, as follows:

plot.mets <- cloud_metrics(plot.laz, ~metrics_set2(x = X,
                                                   y = Y,
                                                   z = Z,
                                                   zmin = 0.5,
                                                   zintervals = c(0,0.5,1,2,4,8)))

However, when I try using the metrics_set2() function in pixel_metrics(), I get errors. I've tried a few different approaches... First, I tried it with a single LAZ file:

pix.mets <- pixel_metrics(test.las, ~metrics_set2(x = X,
                                                  y = Y,
                                                  z = Z,
                                                  zmin = 0.5,
                                                  zintervals = c(0,0.5,1,2,4,8)),
                          res = 25)

I receive the following error: Error in filter(., Z >= zmin) : object 'Z' not found. FWIW, I get the same error when I remove the ~ in front of metrics_set2(). When I put Z in quotation marks (i.e., defining it as a character variable), I get the following error: Error in z - zmean : non-numeric argument to binary operator. Interestingly, when I remove some of the function argments, and simplify it as below (per your example in the documentation), it runs without issue:

pix.mets <- pixel_metrics(test.las, ~metrics_set2(X,Y,Z),
                          res = 25)

The same thing applies when I run it on a LAScatalog -- with just ~metrics_set2(X,Y,Z) it works fine but when I define additional parameters, it says object 'Z' not found. When I run it in parallel using plan(multisession, workers = 12L), I do have to explicitly define ~lidRmetrics::metrics_set2() instead of just ~metrics_set2(), otherwise it returns could not find function "metrics_set2". But, other than that, the same issue of not being able to define additional function arguments persists.

FWIW, I recognize that your library was developed for use with the older grid_metrics() function, so I tried to run it with that, and I'm getting the same errors.

I'm using R v4.0.5, lidR v4.0.1, and lidRmetrics v0.0.1, on a Windows OS.

Thanks in advance for any help you can provide!

fix `metrics_texture`

function currently not exported.
Recent changes in andrew-plowright/ForestTools package could cause the function to fail.

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.