R scripts for automated voxelization and Plant Area Density (PAD) calculation from LiDAR data using AMAPVox.
Extract Plant Area Density (PAD) from your RiSCAN project in three simple steps.
Best for: Quick testing, parameter exploration, initial runs
# Fast preview run (10-15 minutes)
# Uses 10% of shots, 1m voxels
CONFIG_XML=configs/LSS_2021_07_core_preview.xml Rscript scripts/run_voxelization_batch.R
# Then compute PAD from preview voxels
VOX_PATH=data/voxel/LSS_2021_07_core_preview.vox Rscript scripts/get_voxel_pad.RSpeed improvements:
- 10% decimation (vs 50%) β 5x faster
- 1.0m voxels (vs 0.5m) β 8x fewer voxels
- Expected time: 10-15 minutes
Best for: Final analysis, publication-quality results
# Step 1: Voxelize the RiSCAN project (full resolution, ~30-45 minutes)
Rscript scripts/run_voxelization_batch.R
# Step 2: Compute PAD from voxels
VOX_PATH=data/voxel/LSS_2021_07_core.vox Rscript scripts/get_voxel_pad.R
# Step 3 (optional): Analyze PAD data
VOX_FILE=data/voxel/voxel_with_pad.vox Rscript scripts/example_pad_analysis.RProcessing time: 30-45 minutes
Best for: First-time users, exploring parameters, visual feedback
# Launches GUI, then computes PAD after you save the voxel file
CREATE_VOX=true Rscript scripts/get_voxel_pad.RBest for: When you already have a .vox file
VOX_PATH=path/to/your.vox Rscript scripts/get_voxel_pad.Rβ R scripts for voxelization and PAD computation β XML configuration for RiSCAN projects β DTM generation from LAS/LAZ point clouds β Multi-threaded processing support β Comprehensive documentation
- Reads RiSCAN project (up to 66 scan positions)
- Processes all scans with their transformations
- Computes transmittance and attenuation per voxel
- Outputs:
.voxfile (~100MB)
Processing time: 10-60 minutes (depends on point density and settings)
- Reads voxel file
- Computes PAD from transmittance/attenuation
- Uses spherical leaf angle distribution
- Outputs:
.voxfile with PAD variables
Processing time: < 1 minute
- Generates Digital Terrain Model from LAS/LAZ point clouds
- Multi-threaded ground classification (PMF/CSF algorithms)
- Exports DTM in ESRI ASCII grid format
- See
scripts/DTM_README.mdfor details
Usage:
THREADS=16 ALGORITHM=csf Rscript scripts/create_dtm.R input.las output.asc- Reads voxel file with PAD
- Computes Plant Area Index (PAI)
- Generates statistics and summaries
- Exports sample data to CSV
Processing time: < 1 minute
Two configurations are provided:
configs/LSS_2021_07_core_preview.xml - Fast preview
- 1.0m voxel resolution
- 10% decimation (10% of shots)
- ~5-10 minute processing time
- Good for testing and exploration
configs/LSS_2021_07_core.xml - Full resolution
- 0.5m voxel resolution
- 50% decimation (50% of shots)
- ~20-40 minute processing time (with 3 parallel tasks)
- Good for final analysis
Control CPU usage with environment variables:
# Recommended: Balanced performance (16 cores)
NUM_TASKS=2 THREADS_PER_TASK=8 Rscript scripts/run_voxelization_batch.R
# Conservative: Most stable (8 cores, default)
NUM_TASKS=1 THREADS_PER_TASK=8 Rscript scripts/run_voxelization_batch.R
# Aggressive: May be unstable with some datasets (24 cores)
NUM_TASKS=3 THREADS_PER_TASK=8 Rscript scripts/run_voxelization_batch.R- The native RXP library has thread safety issues at very high parallelism
- Using >24 threads (e.g., NUM_TASKS=2 THREADS_PER_TASK=14) may cause JVM crashes
- Recommended max: NUM_TASKS=3 with THREADS_PER_TASK=8 (24 cores total)
- Safe default: NUM_TASKS=1 with THREADS_PER_TASK=8 (8 cores total)
Edit config XML file to adjust resolution:
<!-- High resolution (0.5m voxels, slower): -->
<voxelspace ... resolution="(0.5, 0.5, 0.5)" split="(240, 240, 400)" ... />
<!-- Medium resolution (1.0m voxels, faster): -->
<voxelspace ... resolution="(1.0, 1.0, 1.0)" split="(120, 120, 200)" ... />
<!-- Low resolution (2.0m voxels, very fast): -->
<voxelspace ... resolution="(2.0, 2.0, 2.0)" split="(60, 60, 100)" ... />Note: split must match spatial extent divided by resolution.
<!-- Full data (slowest, most accurate): -->
<parameters decimation-factor="1.0" />
<!-- Half data (balanced): -->
<parameters decimation-factor="0.5" />
<!-- 10% data (fastest, good for preview): -->
<parameters decimation-factor="0.1" />Only the minimum variables needed for PAD are enabled by default:
number_of_shots- pulse count per voxelmean_angle- mean beam angleestimated_transmittance- transmittance estimateattenuation_fpl_unbiased_mle- Free Path Length attenuationattenuation_ppl_mle- Path Length attenuationground_distance- height above ground (requires DTM)
Enable additional variables in configs/LSS_2021_07_core.xml as needed.
data/voxel/
βββ LSS_2021_07_core.vox # Voxelization output
βββ voxel_with_pad.vox # With PAD variables added
After running get_voxel_pad.R, your voxel file will contain:
pad_transmittance- PAD from transmittancepad_attenuation_FPL_unbiasedMLE- PAD from Free Path Lengthpad_attenuation_PPL_MLE- PAD from Path Length
All in units of mΒ²/mΒ³ (plant area per volume)
Symptom: Process crashes with "fatal error", "SIGSEGV", or creates hs_err_pid*.log
Cause: Native RXP library has thread safety issues at high parallelism (>24 threads)
Solution: Reduce parallel tasks:
# Use default safe settings (8 cores)
Rscript scripts/run_voxelization_batch.R
# Or specify explicitly
NUM_TASKS=1 THREADS_PER_TASK=8 Rscript scripts/run_voxelization_batch.RDo NOT use: NUM_TASKS Γ THREADS_PER_TASK > 24
Solution: Increase Java heap size (default is 8GB):
# Edit scripts/run_voxelization_batch.R, line 96:
jvm.options = "-Xms16384m" # 16GB instead of 8GBOr reduce voxel resolution:
<!-- In XML config, change from 0.5m to 1.0m -->
<voxelspace ... resolution="(1.0, 1.0, 1.0)" split="(120, 120, 200)" ... /># Check Java installation
java -version
# Should show Java 8+ (64-bit)
# If not installed, install Java 8 or higherMake sure run_voxelization_batch.R completed successfully and check the output path.
Your voxelization settings may not have enabled these variables. Check the XML configuration.
If you have problems with the DTM file:
- Check that it's in proper ESRI ASCII grid format
- Verify the file with
head data/dtm/your_dtm.asc - See
scripts/DTM_README.mdfor creating valid DTM files
scripts/README.md- Detailed script documentationscripts/DTM_README.md- DTM generation guide- AMAPVox documentation: https://amapvox.org
- R package help:
?AMAPVox::plantAreaDensity - PAD estimators paper: https://doi.org/10.23708/1AJNMP
- Visualize PAD: Use ggplot2 to plot vertical profiles
- Compute LAI: Use
AMAPVox::plantAreaIndex() - Export data: Use
data.table::fwrite()for CSV export - 3D visualization: Use the AMAPVox 3D viewer
See scripts/example_pad_analysis.R for examples.
- R (3.6+)
- R packages: AMAPVox, data.table
- For DTM generation: lidR, terra, future
- Java (8+, 64-bit) for AMAPVox
Scripts are provided as-is for use with AMAPVox. See AMAPVox license at https://amapvox.org