Introduction

I figure Markdown will be easier so that I can just demo what the script is doing without having to share data along with the script. But, happy to share data and the script if we need to go that route. Nothing exciting going on here, just some basic project setup.

library(stringr)
library(rgdal)
## Warning: package 'rgdal' was built under R version 4.0.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.0.3
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/u0942838/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/u0942838/Documents/R/win-library/4.0/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/u0942838/Documents/R/win-library/4.0/rgdal/proj
library(rgeos)
## rgeos version: 0.5-5, (SVN revision 640)
##  GEOS runtime version: 3.8.0-CAPI-1.13.1 
##  Linking to sp version: 1.4-2 
##  Polygon checking: TRUE
library(randomForest)
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
library(ranger)
## 
## Attaching package: 'ranger'
## The following object is masked from 'package:randomForest':
## 
##     importance
# set random seed
set.seed(1234)

# define input directories
main.dir <- "S:/ursa/campbell/CNH"
gedi.dir <- paste0(main.dir, "/GEDI")
gedi.dir.scale.1 <- paste0(gedi.dir, "/Real")
gedi.dir.scale.2 <- paste0(gedi.dir, "/Real_BENM")
gedi.dir.analysis <- paste0(gedi.dir, "/Analysis")
model.dir <- paste0(main.dir, "/Modeling")
uc.dir <- paste0(model.dir, "/Uncertainty/GEDI")

Read in airborne lidar data

This first data frame (df.1) contains airborne lidar structural metrics that were used to predict biomass at the local scale. The metrics are calculated within each GEDI footprint. Footprints are identified by their shot number “shot.num” field.

# read in footprint metrics, add "als" to the start of their column names
df.1 <- read.csv(paste0(gedi.dir.analysis, "/footprint_metrics_3000cm.csv"))
df.1 <- df.1[,c(1,6:ncol(df.1))]
colnames(df.1)[3:ncol(df.1)] <- paste0("als.", colnames(df.1)[3:ncol(df.1)])
colnames(df.1) <- str_replace_all(colnames(df.1), "_", ".")
colnames(df.1)[which(colnames(df.1) == "shot_num")] <- "shot.num"
df.1$shot.num <- as.character(df.1$shot.num)
head(df.1)
##            shot.num n.pts    als.cc    als.cd als.p.0 als.p.5 als.p.10 als.p.15
## 1 23550024100152228 10137 0.1871722 0.1730295    0.04  0.6300     0.89     1.02
## 2 23550000100152228 16048 0.1749235 0.1601446    0.02  0.4200     0.83     1.01
## 3 23550000300152232 18293 0.1773321 0.1605532    0.04  0.7400     0.98     1.13
## 4 23550000500152232 20725 0.1793475 0.1627503    0.05  0.6200     0.90     1.06
## 5 23550000700152232 28946 0.2118119 0.1891108    0.02  0.5165     0.88     1.06
## 6 23550000900152232 33527 0.1867704 0.1782146    0.00  0.1500     0.26     0.54
##   als.p.20 als.p.25 als.p.30 als.p.35 als.p.40 als.p.45 als.p.50 als.p.55
## 1     1.14     1.26     1.38     1.50     1.63     1.73     1.84     1.98
## 2     1.17     1.27     1.38     1.48     1.60     1.70     1.82     1.93
## 3     1.24     1.34     1.43     1.53     1.63     1.73     1.83     1.94
## 4     1.19     1.32     1.44     1.54     1.66     1.77     1.88     1.98
## 5     1.18     1.30     1.42     1.55     1.68     1.79     1.90     2.02
## 6     0.86     1.08     1.29     1.48     1.65     1.80     1.96     2.12
##   als.p.60 als.p.65 als.p.70 als.p.75 als.p.80 als.p.85 als.p.90 als.p.95
## 1     2.13     2.30    2.480   2.6700     2.90    3.123    3.400   3.8900
## 2     2.05     2.20    2.340   2.5100     2.66    2.850    3.040   3.3200
## 3     2.05     2.17    2.320   2.4600     2.67    2.860    3.170   3.6000
## 4     2.11     2.24    2.370   2.5275     2.68    2.860    3.093   3.4600
## 5     2.15     2.29    2.431   2.5975     2.78    3.010    3.320   3.6935
## 6     2.30     2.46    2.630   2.8200     3.01    3.240    3.580   4.0755
##   als.p.100    als.mh als.mh.ag als.skew als.skew.ag als.kurt als.kurt.ag
## 1      6.30 0.4963668  2.029718 2.150394   0.8339563 4.299392   1.0257531
## 2      4.95 0.4271099  1.885110 2.015646   0.2533658 3.041096  -0.1664849
## 3      5.06 0.4262406  1.954190 2.118246   0.5917054 3.712611   0.2830931
## 4      4.94 0.4316261  1.937083 2.007593   0.2656120 2.962176  -0.2591705
## 5      4.66 0.5199067  1.986958 1.820766   0.3213053 2.245442  -0.3265480
## 6      6.35 0.5229469  1.999184 2.101940   0.3703822 3.691192  -0.1896823
##   als.vrd.0.50 als.vrd.50.100 als.vrd.100.150 als.vrd.150.200 als.vrd.200.250
## 1    0.7643287     0.02505672      0.05119858      0.05050804      0.03669725
## 2    0.7862039     0.01987787      0.04798106      0.05028664      0.03782403
## 3    0.7885530     0.01607172      0.04908982      0.05340841      0.04017930
## 4    0.7860555     0.02016888      0.04381182      0.05100121      0.04159228
## 5    0.7509155     0.02179921      0.05171699      0.05454985      0.04770953
## 6    0.7762699     0.02207176      0.03233215      0.04107138      0.03963969
##   als.vrd.250.300 als.vrd.300.350 als.vrd.350.400 als.vrd.400.450
## 1      0.02910131      0.02170267     0.011936470     0.004932426
## 2      0.03227817      0.01863161     0.004548853     0.001620140
## 3      0.02525556      0.01470508     0.007434538     0.003935932
## 4      0.03001206      0.01708082     0.008540410     0.001254524
## 5      0.03340703      0.01986458     0.014129759     0.005423893
## 6      0.03561309      0.02392102     0.014734393     0.007426850
##   als.vrd.450.500 als.vnrd.0.50 als.vnrd.50.100 als.vnrd.100.150
## 1    0.0012824307             1      0.03174206       0.06090834
## 2    0.0007477567             1      0.02465986       0.05617978
## 3    0.0012573115             1      0.01997418       0.05750144
## 4    0.0004825090             1      0.02501646       0.05154113
## 5    0.0004836592             1      0.02821120       0.06273047
## 6    0.0035493781             1      0.02764701       0.03892280
##   als.vnrd.150.200 als.vnrd.200.250 als.vnrd.250.300 als.vnrd.300.350
## 1       0.05668106       0.03955343       0.03041237       0.02217742
## 2       0.05560532       0.04014550       0.03312444       0.01876137
## 3       0.05887670       0.04241445       0.02596819       0.01489480
## 4       0.05660276       0.04412367       0.03085624       0.01725819
## 5       0.06206029       0.05148375       0.03479544       0.02027075
## 6       0.04711397       0.04349391       0.03760630       0.02463750
##   als.vnrd.350.400 als.vnrd.400.450 als.vnrd.450.500 als.mi.b1 als.mi.b1.ag
## 1      0.012050593      0.004954910     0.0012866192  815.9076     281.5628
## 2      0.004559650      0.001621352     0.0007477567  764.1609     269.9974
## 3      0.007474170      0.003941318     0.0012574490  783.8776     253.2583
## 4      0.008555271      0.001255129     0.0004825090  815.7691     257.2924
## 5      0.014213727      0.005426517     0.0004836592  722.4081     264.7367
## 6      0.014948859      0.007478600     0.0035613815  746.6205     305.7609
##   als.mi.b2 als.mi.b2.ag als.mi.b3 als.mi.b3.ag als.sdi.b1 als.sdi.b1.ag
## 1  745.1183     356.3026        NA           NA   332.6547      153.9817
## 2  731.8723     368.8095  296.5883     133.1921   352.7364      131.1355
## 3  755.8638     341.3530  293.2914     138.6060   366.9536      120.0238
## 4  730.2492     345.4928  298.8658     139.9717   364.8449      117.4022
## 5  717.0822     355.4244  291.3111     140.8642   366.2332      126.1922
## 6  724.2978     365.5527  264.2503     151.3917   342.3209      183.4334
##   als.sdi.b2 als.sdi.b2.ag als.sdi.b3 als.sdi.b3.ag als.pi.b1.0 als.pi.b1.5
## 1   362.1247      209.2519         NA            NA          16          64
## 2   342.4202      195.9871   134.6285      54.10937          16          64
## 3   356.1154      189.0052   125.2472      53.89597          16          64
## 4   346.1234      186.7357   127.3334      57.52428          16          64
## 5   363.0082      200.3636   138.3772      59.77104          16          64
## 6   351.1210      204.3031   109.8386      73.36550          16          64
##   als.pi.b1.10 als.pi.b1.15 als.pi.b1.20 als.pi.b1.25 als.pi.b1.30 als.pi.b1.35
## 1           96          128          144          192        219.2          224
## 2           96          144          144          176        192.0          224
## 3           96          128          144          176        192.0          208
## 4          112          144          160          192        192.0          224
## 5          112          128          160          176        208.0          224
## 6          112          128          160          192        208.0          224
##   als.pi.b1.40 als.pi.b1.45 als.pi.b1.50 als.pi.b1.55 als.pi.b1.60 als.pi.b1.65
## 1          240          256          272          288          304          320
## 2          224          256          272          272          288          304
## 3          224          240          256          272          272          288
## 4          224          240          256          272          272          288
## 5          240          240          256          272          288          304
## 6          240          256          272          288          304          320
##   als.pi.b1.70 als.pi.b1.75 als.pi.b1.80 als.pi.b1.85 als.pi.b1.90 als.pi.b1.95
## 1          336          352          384          416          448        520.8
## 2          320          352          368          384          432        496.0
## 3          304          320          336          352          384        432.0
## 4          304          320          336          368          400        448.0
## 5          320          336          352          368          400        464.0
## 6          352          368          416          512          592        672.0
##   als.pi.b1.100 als.pi.b2.0 als.pi.b2.5 als.pi.b2.10 als.pi.b2.15 als.pi.b2.20
## 1          1024          16          64         80.0         99.2          144
## 2          1072          16          64         96.0        144.0          160
## 3          1232          16          64         80.0        112.0          144
## 4           880          16          64         80.0        112.0          144
## 5          1008          16          64         91.2        112.0          144
## 6          1184          16          64         80.0        112.0          144
##   als.pi.b2.25 als.pi.b2.30 als.pi.b2.35 als.pi.b2.40 als.pi.b2.45 als.pi.b2.50
## 1          176          208          240          272          304          352
## 2          196          240          272          304          352          384
## 3          176          224          256          288          320          336
## 4          176          224          256          288          320          352
## 5          176          208          256          288          320          368
## 6          192          224          256          304          336          368
##   als.pi.b2.55 als.pi.b2.60 als.pi.b2.65 als.pi.b2.70 als.pi.b2.75 als.pi.b2.80
## 1          384          416          464          496          528        560.0
## 2          416          432          464          496          528        560.0
## 3          368          400          416          448          496        524.8
## 4          384          416          448          464          496        528.0
## 5          400          416          448          480          512        544.0
## 6          400          432          464          496          528        560.0
##   als.pi.b2.85 als.pi.b2.90 als.pi.b2.95 als.pi.b2.100 als.pi.b3.0 als.pi.b3.5
## 1        592.0          624          688          1008          NA          NA
## 2        576.0          608          672           928          16          48
## 3        560.0          592          640          1104          16          64
## 4        559.2          592          640           864          16          48
## 5        576.0          608          672           992          16          48
## 6        592.0          640          704          1024          16          48
##   als.pi.b3.10 als.pi.b3.15 als.pi.b3.20 als.pi.b3.25 als.pi.b3.30 als.pi.b3.35
## 1           NA           NA           NA           NA           NA           NA
## 2           64           64           80           96          112          112
## 3           64           80           96           96          112          112
## 4           64           64           80           96          112          112
## 5           64           64           80           96          112          112
## 6           64           64           80           96          112          112
##   als.pi.b3.40 als.pi.b3.45 als.pi.b3.50 als.pi.b3.55 als.pi.b3.60 als.pi.b3.65
## 1           NA           NA           NA           NA           NA           NA
## 2          112          128          128          144          144          160
## 3          128          128          144          144          144          160
## 4          128          128          144          144          160          160
## 5          128          128          144          160          160          160
## 6          128          128          144          144          160          176
##   als.pi.b3.70 als.pi.b3.75 als.pi.b3.80 als.pi.b3.85 als.pi.b3.90 als.pi.b3.95
## 1           NA           NA           NA           NA           NA           NA
## 2          160          160          176          192          192          224
## 3          176          176          192          192          208          224
## 4          176          176          192          192          208          240
## 5          176          192          192          208          208          240
## 6          176          192          208          224          256          288
##   als.pi.b3.100
## 1            NA
## 2           336
## 3           304
## 4           368
## 5           368
## 6           400

Read in GEDI data

There are two main types of GEDI metrics, Level 2A (l2a) and Level 2B (l2b). These CSV files have metrics associated with each footprint contained within df.1.

# read in gedi 2a and 2b metrics csv files
df.2 <- read.csv(paste0(gedi.dir.scale.1, "/l2a_metrics_cnh_20200921.csv"))
df.3 <- read.csv(paste0(gedi.dir.scale.1, "/l2b_metrics_cnh_20200921.csv"))

# change all column names to replace underscores with periods
colnames(df.2) <- str_replace_all(colnames(df.2), "_", ".")
colnames(df.3) <- str_replace_all(colnames(df.3), "_", ".")

# add "gedi" to beginning of all gedi predictors
colnames(df.2)[10:ncol(df.2)] <- paste0("gedi.", colnames(df.2)[10:ncol(df.2)])
colnames(df.3)[12:ncol(df.3)] <- paste0("gedi.", colnames(df.3)[12:ncol(df.3)])

# change column names for df.2 and df.3 to match df.1
colnames(df.2)[which(colnames(df.2) == "shot.number")] <- "shot.num"
colnames(df.3)[which(colnames(df.3) == "shot.number")] <- "shot.num"

# change them to character
df.2$shot.num <- as.character(df.2$shot.num)
df.3$shot.num <- as.character(df.3$shot.num)

# print the first few rows of each
head(df.2)
##       beam          shot.num degrade.flag quality.flag delta.time sensitivity
## 1 BEAM0000 23550007900152148            0            1   42987580   0.9412481
## 2 BEAM0000 23550008100152148            0            1   42987580   0.9318883
## 3 BEAM0000 23550008300152152            0            1   42987580   0.9316657
## 4 BEAM0000 23550008500152152            0            1   42987580   0.9296457
## 5 BEAM0000 23550008700152152            0            1   42987580   0.9447677
## 6 BEAM0000 23550008900152152            0            1   42987580   0.9412529
##   solar.elevation lat.lowestmode lon.lowestmode gedi.elev.highestreturn
## 1        7.698283       37.80390      -110.1511                1805.347
## 2        7.698581       37.80357      -110.1506                1810.891
## 3        7.698879       37.80324      -110.1501                1816.936
## 4        7.699178       37.80290      -110.1496                1819.310
## 5        7.699476       37.80257      -110.1491                1822.997
## 6        7.699775       37.80224      -110.1487                1823.650
##   gedi.elev.lowestmode gedi.rh0 gedi.rh1 gedi.rh2 gedi.rh3 gedi.rh4 gedi.rh5
## 1             1799.993    -4.04    -3.66    -3.36    -3.10    -2.92    -2.73
## 2             1805.987    -5.12    -4.67    -4.34    -4.08    -3.85    -3.66
## 3             1812.144    -4.45    -4.04    -3.74    -3.48    -3.29    -3.10
## 4             1815.079    -4.04    -3.66    -3.33    -3.10    -2.92    -2.73
## 5             1818.355    -4.19    -3.74    -3.36    -3.10    -2.92    -2.73
## 6             1819.120    -4.00    -3.59    -3.29    -3.03    -2.84    -2.69
##   gedi.rh6 gedi.rh7 gedi.rh8 gedi.rh9 gedi.rh10 gedi.rh11 gedi.rh12 gedi.rh13
## 1    -2.58    -2.47    -2.32    -2.20     -2.13     -2.02     -1.94     -1.87
## 2    -3.48    -3.33    -3.18    -3.07     -2.95     -2.84     -2.73     -2.62
## 3    -2.95    -2.80    -2.69    -2.54     -2.47     -2.35     -2.24     -2.17
## 4    -2.58    -2.43    -2.32    -2.20     -2.13     -2.02     -1.94     -1.87
## 5    -2.58    -2.43    -2.32    -2.20     -2.09     -2.02     -1.90     -1.83
## 6    -2.54    -2.39    -2.28    -2.17     -2.09     -1.98     -1.90     -1.83
##   gedi.rh14 gedi.rh15 gedi.rh16 gedi.rh17 gedi.rh18 gedi.rh19 gedi.rh20
## 1     -1.75     -1.68     -1.60     -1.57     -1.49     -1.42     -1.34
## 2     -2.54     -2.43     -2.35     -2.28     -2.17     -2.09     -2.02
## 3     -2.09     -1.98     -1.90     -1.83     -1.75     -1.68     -1.64
## 4     -1.79     -1.72     -1.64     -1.57     -1.49     -1.46     -1.38
## 5     -1.75     -1.68     -1.60     -1.53     -1.49     -1.42     -1.34
## 6     -1.75     -1.68     -1.60     -1.53     -1.46     -1.42     -1.34
##   gedi.rh21 gedi.rh22 gedi.rh23 gedi.rh24 gedi.rh25 gedi.rh26 gedi.rh27
## 1     -1.31     -1.23     -1.19     -1.12     -1.08     -1.01     -0.97
## 2     -1.94     -1.87     -1.79     -1.75     -1.68     -1.60     -1.53
## 3     -1.57     -1.49     -1.46     -1.38     -1.31     -1.27     -1.19
## 4     -1.34     -1.27     -1.23     -1.16     -1.12     -1.08     -1.01
## 5     -1.31     -1.23     -1.19     -1.16     -1.08     -1.04     -0.97
## 6     -1.31     -1.23     -1.19     -1.12     -1.08     -1.04     -0.97
##   gedi.rh28 gedi.rh29 gedi.rh30 gedi.rh31 gedi.rh32 gedi.rh33 gedi.rh34
## 1     -0.89     -0.86     -0.82     -0.74     -0.71     -0.67     -0.63
## 2     -1.46     -1.42     -1.34     -1.27     -1.23     -1.16     -1.12
## 3     -1.16     -1.12     -1.04     -1.01     -0.93     -0.89     -0.86
## 4     -0.97     -0.93     -0.89     -0.82     -0.78     -0.74     -0.71
## 5     -0.93     -0.89     -0.86     -0.78     -0.74     -0.71     -0.67
## 6     -0.93     -0.89     -0.82     -0.78     -0.74     -0.71     -0.67
##   gedi.rh35 gedi.rh36 gedi.rh37 gedi.rh38 gedi.rh39 gedi.rh40 gedi.rh41
## 1     -0.56     -0.52     -0.48     -0.44     -0.37     -0.33     -0.29
## 2     -1.04     -0.97     -0.93     -0.86     -0.82     -0.74     -0.71
## 3     -0.78     -0.74     -0.71     -0.67     -0.59     -0.56     -0.52
## 4     -0.67     -0.63     -0.59     -0.52     -0.48     -0.44     -0.41
## 5     -0.63     -0.56     -0.52     -0.48     -0.44     -0.41     -0.37
## 6     -0.59     -0.56     -0.52     -0.48     -0.44     -0.41     -0.37
##   gedi.rh42 gedi.rh43 gedi.rh44 gedi.rh45 gedi.rh46 gedi.rh47 gedi.rh48
## 1     -0.26     -0.18     -0.14     -0.11     -0.07     -0.03      0.00
## 2     -0.63     -0.59     -0.52     -0.48     -0.41     -0.37     -0.29
## 3     -0.48     -0.41     -0.37     -0.33     -0.29     -0.26     -0.18
## 4     -0.37     -0.33     -0.29     -0.26     -0.22     -0.18     -0.14
## 5     -0.33     -0.26     -0.22     -0.18     -0.14     -0.11     -0.07
## 6     -0.33     -0.26     -0.22     -0.18     -0.14     -0.11     -0.07
##   gedi.rh49 gedi.rh50 gedi.rh51 gedi.rh52 gedi.rh53 gedi.rh54 gedi.rh55
## 1      0.07      0.11      0.14      0.18      0.22      0.29      0.33
## 2     -0.26     -0.18     -0.14     -0.11     -0.03      0.00      0.07
## 3     -0.14     -0.11     -0.07     -0.03      0.03      0.07      0.11
## 4     -0.11     -0.07     -0.03      0.00      0.03      0.07      0.11
## 5     -0.03      0.00      0.03      0.07      0.14      0.18      0.22
## 6     -0.03      0.00      0.03      0.07      0.14      0.18      0.22
##   gedi.rh56 gedi.rh57 gedi.rh58 gedi.rh59 gedi.rh60 gedi.rh61 gedi.rh62
## 1      0.37      0.41      0.48      0.52      0.56      0.59      0.67
## 2      0.11      0.18      0.22      0.29      0.33      0.41      0.44
## 3      0.14      0.18      0.26      0.29      0.33      0.37      0.41
## 4      0.14      0.18      0.22      0.26      0.29      0.33      0.41
## 5      0.26      0.29      0.33      0.37      0.41      0.44      0.52
## 6      0.26      0.29      0.33      0.37      0.41      0.44      0.52
##   gedi.rh63 gedi.rh64 gedi.rh65 gedi.rh66 gedi.rh67 gedi.rh68 gedi.rh69
## 1      0.71      0.74      0.82      0.86      0.89      0.97      1.01
## 2      0.52      0.56      0.63      0.67      0.74      0.78      0.86
## 3      0.48      0.52      0.56      0.59      0.67      0.71      0.74
## 4      0.44      0.48      0.52      0.56      0.59      0.63      0.67
## 5      0.56      0.59      0.63      0.67      0.74      0.78      0.82
## 6      0.56      0.59      0.63      0.67      0.74      0.78      0.82
##   gedi.rh70 gedi.rh71 gedi.rh72 gedi.rh73 gedi.rh74 gedi.rh75 gedi.rh76
## 1      1.08      1.12      1.19      1.23      1.31      1.34      1.42
## 2      0.89      0.97      1.01      1.08      1.16      1.19      1.27
## 3      0.82      0.86      0.89      0.97      1.01      1.08      1.12
## 4      0.74      0.78      0.82      0.86      0.89      0.97      1.01
## 5      0.86      0.93      0.97      1.01      1.08      1.12      1.16
## 6      0.86      0.93      0.97      1.01      1.08      1.12      1.19
##   gedi.rh77 gedi.rh78 gedi.rh79 gedi.rh80 gedi.rh81 gedi.rh82 gedi.rh83
## 1      1.49      1.57      1.60      1.68      1.75      1.83      1.90
## 2      1.34      1.42      1.46      1.53      1.60      1.68      1.75
## 3      1.19      1.23      1.31      1.38      1.42      1.49      1.57
## 4      1.04      1.12      1.16      1.23      1.27      1.34      1.42
## 5      1.23      1.27      1.34      1.42      1.46      1.53      1.60
## 6      1.23      1.31      1.34      1.42      1.49      1.53      1.60
##   gedi.rh84 gedi.rh85 gedi.rh86 gedi.rh87 gedi.rh88 gedi.rh89 gedi.rh90
## 1      1.98      2.09      2.17      2.28      2.35      2.47      2.58
## 2      1.83      1.90      2.02      2.09      2.17      2.28      2.39
## 3      1.64      1.72      1.79      1.87      1.98      2.05      2.17
## 4      1.46      1.53      1.60      1.68      1.75      1.83      1.94
## 5      1.68      1.75      1.83      1.90      1.98      2.05      2.17
## 6      1.68      1.75      1.83      1.90      2.02      2.09      2.20
##   gedi.rh91 gedi.rh92 gedi.rh93 gedi.rh94 gedi.rh95 gedi.rh96 gedi.rh97
## 1      2.73      2.84      2.99      3.18      3.36      3.55      3.81
## 2      2.50      2.62      2.73      2.88      3.07      3.25      3.48
## 3      2.28      2.39      2.54      2.69      2.88      3.07      3.33
## 4      2.02      2.13      2.24      2.39      2.54      2.69      2.92
## 5      2.28      2.39      2.50      2.65      2.80      2.99      3.21
## 6      2.32      2.43      2.54      2.69      2.84      3.03      3.21
##   gedi.rh98 gedi.rh99 gedi.rh100
## 1      4.15      4.60       5.35
## 2      3.74      4.15       4.90
## 3      3.63      4.04       4.79
## 4      3.18      3.55       4.23
## 5      3.48      3.89       4.64
## 6      3.48      3.85       4.53
head(df.3)
##       beam          shot.num algorithmrun.flag l2b.quality.flag delta.time
## 1 BEAM0000 23550007900152148                 1                1   42987580
## 2 BEAM0000 23550008100152148                 1                1   42987580
## 3 BEAM0000 23550008300152152                 1                1   42987580
## 4 BEAM0000 23550008500152152                 1                1   42987580
## 5 BEAM0000 23550008700152152                 1                1   42987580
## 6 BEAM0000 23550008900152152                 1                1   42987580
##   sensitivity solar.elevation latitude.lastbin latitude.bin0 longitude.lastbin
## 1   0.9412481        7.698283         37.80390      37.80390         -110.1511
## 2   0.9318883        7.698581         37.80357      37.80357         -110.1506
## 3   0.9316657        7.698879         37.80323      37.80324         -110.1501
## 4   0.9296457        7.699178         37.80290      37.80290         -110.1496
## 5   0.9447677        7.699476         37.80257      37.80257         -110.1492
## 6   0.9412529        7.699775         37.80224      37.80224         -110.1487
##   longitude.bin0 gedi.elev.highestreturn gedi.elev.lowestmode   gedi.pai
## 1      -110.1511                1805.347             1799.993 0.18924421
## 2      -110.1506                1810.891             1805.987 0.02768178
## 3      -110.1501                1816.936             1812.144 0.03807665
## 4      -110.1496                1819.310             1815.079 0.08509696
## 5      -110.1491                1822.997             1818.355 0.11969749
## 6      -110.1487                1823.650             1819.120 0.13578381
##   gedi.fhd.normal gedi.omega gedi.pgap.theta gedi.cover
## 1        1.553638          1       0.9096580 0.09028049
## 2        1.082759          1       0.9862452 0.01374548
## 3        1.596079          1       0.9811291 0.01885812
## 4        1.373797          1       0.9583162 0.04165540
## 5        1.428055          1       0.9418685 0.05809183
## 6        1.352983          1       0.9343182 0.06563703

Merge the three data frames together and filter

In order to link ALS to GEDI metrics, I need to first merge the tables together. They’re linked based on the shared “shot.num” field. Then, some quick filtering.

# merge them together
df <- merge(df.1, df.2)
df <- merge(df, df.3)

# get rid of bad points
df <- df[df$quality.flag == 1 & df$l2b.quality.flag == 1,]

# get rid of rows with na values
df <- df[complete.cases(df),]

# print the first few rows
head(df)
##            shot.num     beam delta.time sensitivity solar.elevation
## 1 23550000100152228 BEAM0000   42987581   0.9362459        7.722781
## 2 23550000100152712 BEAM0000   42987585   0.9221157        7.867496
## 3 23550000300152232 BEAM0000   42987581   0.9355166        7.723080
## 4 23550000300152712 BEAM0000   42987585   0.9238452        7.867795
## 5 23550000500152232 BEAM0000   42987581   0.9416424        7.723378
## 6 23550000500152712 BEAM0000   42987585   0.9169669        7.868093
##   gedi.elev.highestreturn gedi.elev.lowestmode  n.pts    als.cc    als.cd
## 1                1946.024             1941.606  16048 0.1749235 0.1601446
## 2                2439.756             2433.466 112901 0.5019777 0.4010239
## 3                1948.486             1944.405  18293 0.1773321 0.1605532
## 4                2440.234             2434.393 108949 0.5699298 0.4216744
## 5                1951.415             1947.559  20725 0.1793475 0.1627503
## 6                2441.118             2434.716  75810 0.5251198 0.4038122
##   als.p.0 als.p.5 als.p.10 als.p.15 als.p.20 als.p.25 als.p.30 als.p.35
## 1    0.02    0.42     0.83     1.01     1.17     1.27     1.38     1.48
## 2   -0.15    0.32     0.99     1.21     1.40     1.58     1.75     1.92
## 3    0.04    0.74     0.98     1.13     1.24     1.34     1.43     1.53
## 4    0.01    0.82     1.11     1.28     1.45     1.61     1.77     1.93
## 5    0.05    0.62     0.90     1.06     1.19     1.32     1.44     1.54
## 6    0.00    0.94     1.18     1.37     1.55     1.72     1.90     2.07
##   als.p.40 als.p.45 als.p.50 als.p.55 als.p.60 als.p.65 als.p.70 als.p.75
## 1     1.60     1.70     1.82     1.93     2.05     2.20     2.34   2.5100
## 2     2.09     2.26     2.42     2.59     2.76     2.93     3.11   3.3000
## 3     1.63     1.73     1.83     1.94     2.05     2.17     2.32   2.4600
## 4     2.10     2.24     2.40     2.54     2.69     2.85     3.01   3.1800
## 5     1.66     1.77     1.88     1.98     2.11     2.24     2.37   2.5275
## 6     2.22     2.38     2.54     2.70     2.87     3.05     3.23   3.4200
##   als.p.80 als.p.85 als.p.90 als.p.95 als.p.100    als.mh als.mh.ag  als.skew
## 1     2.66     2.85    3.040     3.32      4.95 0.4271099  1.885110 2.0156458
## 2     3.51     3.75    4.040     4.53      6.99 1.2257991  2.472866 0.9114223
## 3     2.67     2.86    3.170     3.60      5.06 0.4262406  1.954190 2.1182461
## 4     3.36     3.58    3.840     4.24      6.39 1.2372192  2.421213 0.7204498
## 5     2.68     2.86    3.093     3.46      4.94 0.4316261  1.937083 2.0075934
## 6     3.63     3.87    4.140     4.52      6.02 1.2309522  2.592396 0.8120000
##   als.skew.ag   als.kurt als.kurt.ag als.vrd.0.50 als.vrd.50.100
## 1   0.2533658  3.0410961 -0.16648489    0.7862039     0.01987787
## 2   0.3099793 -0.2585767  0.02274202    0.5333434     0.02135499
## 3   0.5917054  3.7126106  0.28309306    0.7885530     0.01607172
## 4   0.1453689 -0.7656600 -0.28571843    0.5083663     0.01928425
## 5   0.2656120  2.9621757 -0.25917047    0.7860555     0.02016888
## 6   0.1198931 -0.6917900 -0.51843651    0.5396650     0.01312492
##   als.vrd.100.150 als.vrd.150.200 als.vrd.200.250 als.vrd.250.300
## 1      0.04798106      0.05028664      0.03782403      0.03227817
## 2      0.06239094      0.07122169      0.07495062      0.07227571
## 3      0.04908982      0.05340841      0.04017930      0.02525556
## 4      0.07048252      0.07920220      0.08461757      0.08226785
## 5      0.04381182      0.05100121      0.04159228      0.03001206
## 6      0.05997889      0.06856615      0.07419865      0.07107242
##   als.vrd.300.350 als.vrd.350.400 als.vrd.400.450 als.vrd.450.500 als.vnrd.0.50
## 1      0.01863161     0.004548853     0.001620140    0.0007477567     1.0000000
## 2      0.06314382     0.048174950     0.027147678    0.0121433823     0.9999336
## 3      0.01470508     0.007434538     0.003935932    0.0012573115     1.0000000
## 4      0.06974823     0.046122498     0.025635848    0.0097385015     1.0000000
## 5      0.01708082     0.008540410     0.001254524    0.0004825090     1.0000000
## 6      0.06364596     0.050455085     0.034217122    0.0180978763     1.0000000
##   als.vnrd.50.100 als.vnrd.100.150 als.vnrd.150.200 als.vnrd.200.250
## 1      0.02465986       0.05617978       0.05560532       0.04014550
## 2      0.03849593       0.10109941       0.10346780       0.09819325
## 3      0.01997418       0.05750144       0.05887670       0.04241445
## 4      0.03654739       0.11783752       0.11693204       0.11105356
## 5      0.02501646       0.05154113       0.05660276       0.04412367
## 6      0.02374305       0.09788178       0.10063502       0.09820696
##   als.vnrd.250.300 als.vnrd.300.350 als.vnrd.350.400 als.vnrd.400.450
## 1       0.03312444       0.01876137      0.004559650      0.001621352
## 2       0.08649840       0.07025999      0.050876947      0.027871238
## 3       0.02596819       0.01489480      0.007474170      0.003941318
## 4       0.09744828       0.07631357      0.048039694      0.026007039
## 5       0.03085624       0.01725819      0.008555271      0.001255129
## 6       0.08598101       0.07149207      0.053635280      0.035097214
##   als.vnrd.450.500 als.mi.b1 als.mi.b1.ag als.mi.b2 als.mi.b2.ag als.mi.b3
## 1     0.0007477567  764.1609     269.9974  731.8723     368.8095  296.5883
## 2     0.0123135233  459.4542     219.2522  453.4682     316.5222  203.1045
## 3     0.0012574490  783.8776     253.2583  755.8638     341.3530  293.2914
## 4     0.0097828593  413.7068     204.4048  402.5627     294.8912  162.6384
## 5     0.0004825090  815.7691     257.2924  730.2492     345.4928  298.8658
## 6     0.0182250501  461.5116     197.9051  437.1192     299.2065  178.7925
##   als.mi.b3.ag als.sdi.b1 als.sdi.b1.ag als.sdi.b2 als.sdi.b2.ag als.sdi.b3
## 1     133.1921   352.7364      131.1355   342.4202      195.9871  134.62850
## 2     133.5203   360.1560      129.4848   317.1272      195.9312  148.35967
## 3     138.6060   366.9536      120.0238   356.1154      189.0052  125.24719
## 4     127.2127   336.8019      106.5820   284.1033      184.4893   92.36589
## 5     139.9717   364.8449      117.4022   346.1234      186.7357  127.33340
## 6     125.9178   369.2799      103.7008   306.2320      189.9243  103.40484
##   als.sdi.b3.ag als.pi.b1.0 als.pi.b1.5 als.pi.b1.10 als.pi.b1.15 als.pi.b1.20
## 1      54.10937          16          64           96          144          144
## 2      66.71624          16          48           80           96          112
## 3      53.89597          16          64           96          128          144
## 4      59.12824          16          48           80           96          112
## 5      57.52428          16          64          112          144          160
## 6      59.34024          16          48           64           96          112
##   als.pi.b1.25 als.pi.b1.30 als.pi.b1.35 als.pi.b1.40 als.pi.b1.45 als.pi.b1.50
## 1          176          192          224          224          256          272
## 2          144          160          176          192          208          208
## 3          176          192          208          224          240          256
## 4          128          144          160          176          192          208
## 5          192          192          224          224          240          256
## 6          128          144          160          176          192          208
##   als.pi.b1.55 als.pi.b1.60 als.pi.b1.65 als.pi.b1.70 als.pi.b1.75 als.pi.b1.80
## 1          272          288          304          320          352          368
## 2          224          240          240          256          272          288
## 3          272          272          288          304          320          336
## 4          208          224          240          256          256          272
## 5          272          272          288          304          320          336
## 6          208          224          240          240          256          272
##   als.pi.b1.85 als.pi.b1.90 als.pi.b1.95 als.pi.b1.100 als.pi.b2.0 als.pi.b2.5
## 1          384          432          496          1072          16          64
## 2          304          320          400          1104          16          48
## 3          352          384          432          1232          16          64
## 4          288          304          352          1120          16          48
## 5          368          400          448           880          16          64
## 6          272          288          320           960          16          48
##   als.pi.b2.10 als.pi.b2.15 als.pi.b2.20 als.pi.b2.25 als.pi.b2.30 als.pi.b2.35
## 1           96          144          160          196          240          272
## 2           64           96          112          144          176          208
## 3           80          112          144          176          224          256
## 4           64           80          112          144          160          192
## 5           80          112          144          176          224          256
## 6           64           80          112          128          160          192
##   als.pi.b2.40 als.pi.b2.45 als.pi.b2.50 als.pi.b2.55 als.pi.b2.60 als.pi.b2.65
## 1          304          352          384          416          432          464
## 2          240          272          304          336          368          400
## 3          288          320          336          368          400          416
## 4          224          256          272          304          336          368
## 5          288          320          352          384          416          448
## 6          208          240          272          304          336          384
##   als.pi.b2.70 als.pi.b2.75 als.pi.b2.80 als.pi.b2.85 als.pi.b2.90 als.pi.b2.95
## 1          496          528        560.0        576.0          608          672
## 2          432          464        496.0        544.0          592          656
## 3          448          496        524.8        560.0          592          640
## 4          400          432        464.0        512.0          560          624
## 5          464          496        528.0        559.2          592          640
## 6          416          448        480.0        528.0          576          624
##   als.pi.b2.100 als.pi.b3.0 als.pi.b3.5 als.pi.b3.10 als.pi.b3.15 als.pi.b3.20
## 1           928          16          48           64           64           80
## 2          1056          16          48           48           64           80
## 3          1104          16          64           64           80           96
## 4          1088          16          48           48           64           64
## 5           864          16          48           64           64           80
## 6           880          16          48           48           64           64
##   als.pi.b3.25 als.pi.b3.30 als.pi.b3.35 als.pi.b3.40 als.pi.b3.45 als.pi.b3.50
## 1           96          112          112          112          128          128
## 2           80           96           96          112          112          128
## 3           96          112          112          128          128          144
## 4           80           96           96          112          112          128
## 5           96          112          112          128          128          144
## 6           80           96           96          112          112          128
##   als.pi.b3.55 als.pi.b3.60 als.pi.b3.65 als.pi.b3.70 als.pi.b3.75 als.pi.b3.80
## 1          144          144          160          160          160          176
## 2          128          144          160          160          176          192
## 3          144          144          160          176          176          192
## 4          128          144          144          160          160          176
## 5          144          160          160          176          176          192
## 6          128          144          144          160          160          176
##   als.pi.b3.85 als.pi.b3.90 als.pi.b3.95 als.pi.b3.100 degrade.flag
## 1          192          192          224           336            0
## 2          208          224          240           448            0
## 3          192          208          224           304            0
## 4          192          208          224           400            0
## 5          192          208          240           368            0
## 6          192          208          224           368            0
##   quality.flag lat.lowestmode lon.lowestmode gedi.rh0 gedi.rh1 gedi.rh2
## 1            1       37.77660      -110.1106    -3.89    -3.51    -3.25
## 2            1       37.61505      -109.8719    -3.59    -3.25    -2.99
## 3            1       37.77627      -110.1101    -4.19    -3.81    -3.48
## 4            1       37.61472      -109.8715    -3.78    -3.44    -3.18
## 5            1       37.77594      -110.1096    -4.11    -3.70    -3.40
## 6            1       37.61438      -109.8710    -3.85    -3.48    -3.18
##   gedi.rh3 gedi.rh4 gedi.rh5 gedi.rh6 gedi.rh7 gedi.rh8 gedi.rh9 gedi.rh10
## 1    -2.99    -2.80    -2.65    -2.50    -2.39    -2.24    -2.17     -2.05
## 2    -2.77    -2.58    -2.43    -2.28    -2.17    -2.05    -1.94     -1.83
## 3    -3.21    -3.03    -2.84    -2.65    -2.50    -2.39    -2.28     -2.17
## 4    -2.95    -2.77    -2.62    -2.47    -2.35    -2.20    -2.09     -2.02
## 5    -3.14    -2.95    -2.77    -2.62    -2.47    -2.35    -2.24     -2.13
## 6    -2.95    -2.77    -2.58    -2.43    -2.28    -2.17    -2.05     -1.94
##   gedi.rh11 gedi.rh12 gedi.rh13 gedi.rh14 gedi.rh15 gedi.rh16 gedi.rh17
## 1     -1.98     -1.87     -1.79     -1.72     -1.64     -1.60     -1.53
## 2     -1.75     -1.68     -1.60     -1.53     -1.46     -1.38     -1.31
## 3     -2.05     -1.98     -1.87     -1.79     -1.72     -1.64     -1.57
## 4     -1.90     -1.83     -1.72     -1.64     -1.57     -1.49     -1.42
## 5     -2.05     -1.98     -1.87     -1.79     -1.72     -1.64     -1.60
## 6     -1.83     -1.75     -1.64     -1.57     -1.49     -1.42     -1.34
##   gedi.rh18 gedi.rh19 gedi.rh20 gedi.rh21 gedi.rh22 gedi.rh23 gedi.rh24
## 1     -1.46     -1.42     -1.34     -1.31     -1.23     -1.19     -1.12
## 2     -1.23     -1.19     -1.12     -1.08     -1.01     -0.97     -0.89
## 3     -1.49     -1.46     -1.38     -1.34     -1.27     -1.23     -1.16
## 4     -1.34     -1.27     -1.19     -1.12     -1.04     -1.01     -0.93
## 5     -1.53     -1.46     -1.42     -1.34     -1.31     -1.23     -1.19
## 6     -1.27     -1.19     -1.12     -1.04     -1.01     -0.93     -0.86
##   gedi.rh25 gedi.rh26 gedi.rh27 gedi.rh28 gedi.rh29 gedi.rh30 gedi.rh31
## 1     -1.08     -1.04     -0.97     -0.93     -0.89     -0.86     -0.78
## 2     -0.86     -0.78     -0.74     -0.71     -0.63     -0.59     -0.56
## 3     -1.12     -1.08     -1.01     -0.97     -0.93     -0.89     -0.82
## 4     -0.86     -0.82     -0.74     -0.67     -0.63     -0.56     -0.52
## 5     -1.16     -1.08     -1.04     -1.01     -0.97     -0.89     -0.86
## 6     -0.82     -0.74     -0.67     -0.63     -0.56     -0.52     -0.44
##   gedi.rh32 gedi.rh33 gedi.rh34 gedi.rh35 gedi.rh36 gedi.rh37 gedi.rh38
## 1     -0.74     -0.71     -0.67     -0.63     -0.59     -0.56     -0.52
## 2     -0.48     -0.44     -0.41     -0.37     -0.29     -0.26     -0.22
## 3     -0.78     -0.74     -0.71     -0.67     -0.63     -0.59     -0.56
## 4     -0.44     -0.41     -0.33     -0.29     -0.22     -0.14     -0.11
## 5     -0.82     -0.78     -0.74     -0.71     -0.67     -0.59     -0.56
## 6     -0.41     -0.33     -0.29     -0.22     -0.18     -0.11     -0.07
##   gedi.rh39 gedi.rh40 gedi.rh41 gedi.rh42 gedi.rh43 gedi.rh44 gedi.rh45
## 1     -0.44     -0.41     -0.37     -0.33     -0.29     -0.26     -0.22
## 2     -0.18     -0.11     -0.07     -0.03      0.00      0.07      0.11
## 3     -0.48     -0.44     -0.41     -0.37     -0.33     -0.29     -0.26
## 4     -0.03      0.00      0.07      0.11      0.18      0.22      0.29
## 5     -0.52     -0.48     -0.44     -0.41     -0.37     -0.33     -0.29
## 6     -0.03      0.03      0.07      0.14      0.18      0.26      0.29
##   gedi.rh46 gedi.rh47 gedi.rh48 gedi.rh49 gedi.rh50 gedi.rh51 gedi.rh52
## 1     -0.18     -0.14     -0.11     -0.07     -0.03      0.00      0.03
## 2      0.14      0.18      0.22      0.29      0.33      0.37      0.44
## 3     -0.22     -0.18     -0.14     -0.11     -0.07     -0.03      0.00
## 4      0.33      0.41      0.44      0.52      0.59      0.63      0.71
## 5     -0.26     -0.22     -0.18     -0.14     -0.11     -0.07     -0.03
## 6      0.37      0.41      0.48      0.52      0.59      0.63      0.71
##   gedi.rh53 gedi.rh54 gedi.rh55 gedi.rh56 gedi.rh57 gedi.rh58 gedi.rh59
## 1      0.07      0.11      0.14      0.18      0.22      0.26      0.29
## 2      0.48      0.52      0.56      0.63      0.67      0.74      0.78
## 3      0.03      0.07      0.11      0.14      0.18      0.22      0.26
## 4      0.74      0.82      0.89      0.93      1.01      1.08      1.12
## 5      0.00      0.03      0.07      0.11      0.14      0.18      0.22
## 6      0.78      0.82      0.89      0.93      1.01      1.08      1.12
##   gedi.rh60 gedi.rh61 gedi.rh62 gedi.rh63 gedi.rh64 gedi.rh65 gedi.rh66
## 1      0.37      0.41      0.44      0.48      0.52      0.56      0.59
## 2      0.82      0.89      0.93      1.01      1.04      1.12      1.19
## 3      0.29      0.33      0.37      0.41      0.44      0.48      0.52
## 4      1.19      1.27      1.31      1.38      1.46      1.53      1.60
## 5      0.26      0.29      0.33      0.37      0.41      0.44      0.48
## 6      1.19      1.27      1.34      1.42      1.46      1.53      1.60
##   gedi.rh67 gedi.rh68 gedi.rh69 gedi.rh70 gedi.rh71 gedi.rh72 gedi.rh73
## 1      0.63      0.67      0.74      0.78      0.82      0.86      0.89
## 2      1.23      1.31      1.38      1.46      1.53      1.60      1.68
## 3      0.56      0.59      0.63      0.71      0.74      0.78      0.82
## 4      1.64      1.72      1.79      1.87      1.94      2.02      2.09
## 5      0.52      0.56      0.63      0.67      0.71      0.74      0.78
## 6      1.68      1.75      1.83      1.90      1.98      2.05      2.13
##   gedi.rh74 gedi.rh75 gedi.rh76 gedi.rh77 gedi.rh78 gedi.rh79 gedi.rh80
## 1      0.97      1.01      1.04      1.12      1.16      1.23      1.27
## 2      1.75      1.83      1.94      2.02      2.13      2.20      2.32
## 3      0.86      0.93      0.97      1.01      1.04      1.12      1.16
## 4      2.17      2.24      2.32      2.39      2.47      2.54      2.65
## 5      0.82      0.86      0.93      0.97      1.01      1.08      1.12
## 6      2.24      2.32      2.39      2.47      2.58      2.65      2.73
##   gedi.rh81 gedi.rh82 gedi.rh83 gedi.rh84 gedi.rh85 gedi.rh86 gedi.rh87
## 1      1.34      1.38      1.46      1.53      1.60      1.68      1.75
## 2      2.43      2.54      2.65      2.80      2.92      3.03      3.18
## 3      1.23      1.27      1.34      1.38      1.46      1.53      1.60
## 4      2.73      2.80      2.88      2.99      3.07      3.18      3.25
## 5      1.16      1.23      1.27      1.34      1.42      1.46      1.53
## 6      2.84      2.92      3.03      3.10      3.21      3.33      3.44
##   gedi.rh88 gedi.rh89 gedi.rh90 gedi.rh91 gedi.rh92 gedi.rh93 gedi.rh94
## 1      1.83      1.90      1.98      2.09      2.20      2.32      2.47
## 2      3.33      3.44      3.59      3.74      3.93      4.08      4.26
## 3      1.68      1.75      1.83      1.94      2.02      2.13      2.24
## 4      3.36      3.48      3.59      3.70      3.81      3.96      4.11
## 5      1.60      1.68      1.75      1.83      1.94      2.02      2.17
## 6      3.55      3.66      3.78      3.93      4.04      4.19      4.38
##   gedi.rh95 gedi.rh96 gedi.rh97 gedi.rh98 gedi.rh99 gedi.rh100
## 1      2.62      2.80      3.03      3.33      3.74       4.41
## 2      4.45      4.68      4.94      5.24      5.65       6.29
## 3      2.39      2.58      2.77      3.03      3.40       4.08
## 4      4.26      4.45      4.64      4.90      5.24       5.84
## 5      2.28      2.43      2.62      2.84      3.18       3.85
## 6      4.56      4.79      5.01      5.31      5.72       6.40
##   algorithmrun.flag l2b.quality.flag latitude.lastbin latitude.bin0
## 1                 1                1         37.77660      37.77660
## 2                 1                1         37.61505      37.61505
## 3                 1                1         37.77627      37.77627
## 4                 1                1         37.61471      37.61472
## 5                 1                1         37.77594      37.77594
## 6                 1                1         37.61438      37.61438
##   longitude.lastbin longitude.bin0   gedi.pai gedi.fhd.normal gedi.omega
## 1         -110.1106      -110.1106 0.10241848        1.474927          1
## 2         -109.8719      -109.8719 0.32282248        1.650281          1
## 3         -110.1101      -110.1101 0.09158891        1.388859          1
## 4         -109.8715      -109.8715 0.43680799        1.593343          1
## 5         -110.1096      -110.1096 0.04019950        1.527447          1
## 6         -109.8710      -109.8710 0.48957416        1.634861          1
##   gedi.pgap.theta gedi.cover
## 1       0.9500467 0.04991928
## 2       0.8508484 0.14904997
## 3       0.9552085 0.04476102
## 4       0.8036810 0.19618529
## 5       0.9800875 0.01989896
## 6       0.7827406 0.21711142

Split the data into training and validation

This is kind of a weird step… I kept this in here just to maintain consistency with my original scale 2 biomass modeling procedure. It doesn’t have any major significance to this new uncertainty analysis, but I figured it would be good to be consistent. So, I kept it in.

# split into training and validation
sample.train <- sample(seq(1,nrow(df)), 0.5*nrow(df), replace = F)
df.train <- df[sample.train,]
df.valid <- df[-sample.train,]
dim(df.train)
## [1] 4830  248
dim(df.valid)
## [1] 4831  248

Predict biomass for the regional scale training data

Let the fun begin! Now I’ll be reading in a random forest model that was used to link field data to airborne lidar data to map biomass on the local scale (within the ALS boxes). Note that the “predict.all” argument creates a matrix of n x m dimensions, where each row ([i…n]) represents the new data being predicted and each column ([j…m]) represents the predictions for each of the trees in the forest.

# read in live biomass random forest model
rf.1 <- readRDS(paste0(model.dir, "/rf_model_live_biomass_rel_no_steve.rds"))
rf.1
## 
## Call:
##  randomForest(formula = bio.rel ~ ., data = df[c(y.col.rel, x.cols.rel)],      ntree = 10000, importance = T) 
##                Type of random forest: regression
##                      Number of trees: 10000
## No. of variables tried at each split: 1
## 
##           Mean of squared residuals: 195.8464
##                     % Var explained: 74.14
# predict biomass among each decision tree in the forest
biomass.all <- predict(rf.1, 
                       newdata = list(vrd.0.50 = df.train$als.vrd.0.50,
                                      cd = df.train$als.cd,
                                      mi.b2 = df.train$als.mi.b2,
                                      mh = df.train$als.mh), 
                       predict.all = T)
dim(biomass.all)
## NULL

Read in the full GEDI-biomass random forest model

Recall that I’ve been using the “VSURF” variable selection technique to simplify and improve my random forest models throughout this analysis. Since VSURF takes such a long time to run, I’m just going to load in the full regional-scale RF model that already had the predictor variables refined. This ensures that the same predictor variables are being fed into the new random forest models.

# read in original gedi biomass rf model
rf.gd <- readRDS(paste0(model.dir, "/rf_model_landsat_vs_gedi_20210210_gd.rds"))
preds.gd <- rownames(rf.gd$importance)
x.cols.gd <- which(colnames(df.train) %in% preds.gd)
colnames(df.train)[x.cols.gd]
##  [1] "gedi.elev.highestreturn" "gedi.elev.lowestmode"   
##  [3] "gedi.rh1"                "gedi.rh89"              
##  [5] "gedi.rh91"               "gedi.rh92"              
##  [7] "gedi.rh93"               "gedi.rh94"              
##  [9] "gedi.rh99"               "gedi.rh100"             
## [11] "gedi.fhd.normal"         "gedi.pgap.theta"

Read in all of the regional-scale GEDI data

Up until this point, all of the data has been local scale. All within the ALS boxes. Now, in order to make predictions on the regional scale, I need to read in GEDI metrics for all of the footprints within Bears Ears National Monument. …And a bunch of little cleanup things.

# read in gedi 2a and 2b metrics csv files
df.gd.1 <- read.csv(paste0(gedi.dir.scale.2, "/l2a_metrics_cnh_20210214.csv"))
df.gd.2 <- read.csv(paste0(gedi.dir.scale.2, "/l2b_metrics_cnh_20210214.csv"))

# change all column names to replace underscores with periods
colnames(df.gd.1) <- str_replace_all(colnames(df.gd.1), "_", ".")
colnames(df.gd.2) <- str_replace_all(colnames(df.gd.2), "_", ".")

# add "gedi" to beginning of all gedi predictors
colnames(df.gd.1)[10:ncol(df.gd.1)] <- paste0("gedi.", colnames(df.gd.1)[10:ncol(df.gd.1)])
colnames(df.gd.2)[12:ncol(df.gd.2)] <- paste0("gedi.", colnames(df.gd.2)[12:ncol(df.gd.2)])

# change column names for df.2 and df.3 to match df.1
colnames(df.gd.1)[which(colnames(df.gd.1) == "shot.number")] <- "shot.num"
colnames(df.gd.2)[which(colnames(df.gd.2) == "shot.number")] <- "shot.num"

# change them to character
df.gd.1$shot.num <- as.character(df.gd.1$shot.num)
df.gd.2$shot.num <- as.character(df.gd.2$shot.num)

# merge them together
df.gd <- merge(df.gd.1, df.gd.2, by = "shot.num", suffixes = c("", ".rm"))

# get rid of bad points
df.gd <- df.gd[df.gd$quality.flag == 1 & df.gd$l2b.quality.flag == 1,]

# get rid of duplicate fields
df.gd <- df.gd[,-grep("\\.rm", colnames(df.gd))]

# print the first few rows
head(df.gd)
##            shot.num     beam degrade.flag quality.flag delta.time sensitivity
## 1 23550000100151992 BEAM0000            0            1   42987579   0.9452723
## 3 23550000100152228 BEAM0000            0            1   42987581   0.9362459
## 4 23550000100152348 BEAM0000            0            1   42987582   0.9362535
## 5 23550000100152472 BEAM0000            0            1   42987583   0.9463900
## 6 23550000100152592 BEAM0000            0            1   42987584   0.9525461
## 7 23550000100152712 BEAM0000            0            1   42987585   0.9221157
##   solar.elevation lat.lowestmode lon.lowestmode gedi.elev.highestreturn
## 1        7.650408       37.85712      -110.2303                1568.018
## 3        7.722781       37.77660      -110.1106                1946.024
## 4        7.758953       37.73627      -110.0509                2074.835
## 5        7.795084       37.69590      -109.9912                2371.058
## 6        7.831322       37.65550      -109.9315                2332.401
## 7        7.867496       37.61505      -109.8719                2439.756
##   gedi.elev.lowestmode gedi.rh0 gedi.rh1 gedi.rh2 gedi.rh3 gedi.rh4 gedi.rh5
## 1             1562.889    -4.82    -4.38    -4.04    -3.74    -3.51    -3.33
## 3             1941.606    -3.89    -3.51    -3.25    -2.99    -2.80    -2.65
## 4             2070.717    -5.39    -4.97    -4.64    -4.34    -4.11    -3.89
## 5             2365.517    -3.93    -3.51    -3.21    -2.99    -2.80    -2.65
## 6             2307.728    -4.71    -4.30    -3.96    -3.70    -3.44    -3.25
## 7             2433.466    -3.59    -3.25    -2.99    -2.77    -2.58    -2.43
##   gedi.rh6 gedi.rh7 gedi.rh8 gedi.rh9 gedi.rh10 gedi.rh11 gedi.rh12 gedi.rh13
## 1    -3.14    -2.99    -2.84    -2.73     -2.58     -2.47     -2.39     -2.28
## 3    -2.50    -2.39    -2.24    -2.17     -2.05     -1.98     -1.87     -1.79
## 4    -3.70    -3.55    -3.36    -3.25     -3.10     -2.99     -2.88     -2.77
## 5    -2.50    -2.35    -2.24    -2.13     -2.05     -1.94     -1.87     -1.79
## 6    -3.07    -2.88    -2.73    -2.58     -2.43     -2.32     -2.20     -2.05
## 7    -2.28    -2.17    -2.05    -1.94     -1.83     -1.75     -1.68     -1.60
##   gedi.rh14 gedi.rh15 gedi.rh16 gedi.rh17 gedi.rh18 gedi.rh19 gedi.rh20
## 1     -2.17     -2.09     -2.02     -1.94     -1.87     -1.79     -1.72
## 3     -1.72     -1.64     -1.60     -1.53     -1.46     -1.42     -1.34
## 4     -2.65     -2.58     -2.47     -2.39     -2.32     -2.20     -2.13
## 5     -1.72     -1.64     -1.57     -1.49     -1.42     -1.34     -1.31
## 6     -1.94     -1.83     -1.72     -1.64     -1.53     -1.42     -1.34
## 7     -1.53     -1.46     -1.38     -1.31     -1.23     -1.19     -1.12
##   gedi.rh21 gedi.rh22 gedi.rh23 gedi.rh24 gedi.rh25 gedi.rh26 gedi.rh27
## 1     -1.64     -1.57     -1.49     -1.42     -1.38     -1.31     -1.23
## 3     -1.31     -1.23     -1.19     -1.12     -1.08     -1.04     -0.97
## 4     -2.05     -1.98     -1.90     -1.83     -1.75     -1.68     -1.64
## 5     -1.23     -1.19     -1.12     -1.08     -1.01     -0.97     -0.89
## 6     -1.23     -1.16     -1.04     -0.97     -0.89     -0.78     -0.71
## 7     -1.08     -1.01     -0.97     -0.89     -0.86     -0.78     -0.74
##   gedi.rh28 gedi.rh29 gedi.rh30 gedi.rh31 gedi.rh32 gedi.rh33 gedi.rh34
## 1     -1.19     -1.12     -1.04     -1.01     -0.93     -0.89     -0.82
## 3     -0.93     -0.89     -0.86     -0.78     -0.74     -0.71     -0.67
## 4     -1.57     -1.49     -1.42     -1.38     -1.31     -1.27     -1.19
## 5     -0.86     -0.82     -0.74     -0.71     -0.67     -0.63     -0.56
## 6     -0.63     -0.56     -0.48     -0.37     -0.29     -0.22     -0.14
## 7     -0.71     -0.63     -0.59     -0.56     -0.48     -0.44     -0.41
##   gedi.rh35 gedi.rh36 gedi.rh37 gedi.rh38 gedi.rh39 gedi.rh40 gedi.rh41
## 1     -0.78     -0.71     -0.67     -0.59     -0.56     -0.48     -0.44
## 3     -0.63     -0.59     -0.56     -0.52     -0.44     -0.41     -0.37
## 4     -1.16     -1.08     -1.04     -0.97     -0.93     -0.86     -0.82
## 5     -0.52     -0.48     -0.44     -0.41     -0.33     -0.29     -0.26
## 6     -0.07      0.00      0.11      0.18      0.26      0.33      0.41
## 7     -0.37     -0.29     -0.26     -0.22     -0.18     -0.11     -0.07
##   gedi.rh42 gedi.rh43 gedi.rh44 gedi.rh45 gedi.rh46 gedi.rh47 gedi.rh48
## 1     -0.41     -0.33     -0.29     -0.22     -0.18     -0.14     -0.07
## 3     -0.33     -0.29     -0.26     -0.22     -0.18     -0.14     -0.11
## 4     -0.74     -0.71     -0.67     -0.59     -0.56     -0.48     -0.44
## 5     -0.22     -0.18     -0.11     -0.07     -0.03      0.00      0.03
## 6      0.52      0.59      0.67      0.74      0.86      0.93      1.01
## 7     -0.03      0.00      0.07      0.11      0.14      0.18      0.22
##   gedi.rh49 gedi.rh50 gedi.rh51 gedi.rh52 gedi.rh53 gedi.rh54 gedi.rh55
## 1     -0.03      0.03      0.07      0.11      0.18      0.22      0.29
## 3     -0.07     -0.03      0.00      0.03      0.07      0.11      0.14
## 4     -0.41     -0.33     -0.29     -0.26     -0.18     -0.14     -0.11
## 5      0.07      0.14      0.18      0.22      0.26      0.29      0.33
## 6      1.12      1.19      1.31      1.38      1.49      1.57      1.68
## 7      0.29      0.33      0.37      0.44      0.48      0.52      0.56
##   gedi.rh56 gedi.rh57 gedi.rh58 gedi.rh59 gedi.rh60 gedi.rh61 gedi.rh62
## 1      0.33      0.37      0.44      0.48      0.56      0.59      0.67
## 3      0.18      0.22      0.26      0.29      0.37      0.41      0.44
## 4     -0.07      0.00      0.03      0.07      0.14      0.18      0.22
## 5      0.41      0.44      0.48      0.52      0.59      0.63      0.67
## 6      1.79      1.90      2.02      2.13      2.24      2.39      2.50
## 7      0.63      0.67      0.74      0.78      0.82      0.89      0.93
##   gedi.rh63 gedi.rh64 gedi.rh65 gedi.rh66 gedi.rh67 gedi.rh68 gedi.rh69
## 1      0.71      0.78      0.82      0.89      0.93      1.01      1.04
## 3      0.48      0.52      0.56      0.59      0.63      0.67      0.74
## 4      0.29      0.33      0.37      0.44      0.48      0.52      0.59
## 5      0.71      0.78      0.82      0.86      0.93      0.97      1.04
## 6      2.65      2.80      2.99      3.18      3.40      3.66      3.96
## 7      1.01      1.04      1.12      1.19      1.23      1.31      1.38
##   gedi.rh70 gedi.rh71 gedi.rh72 gedi.rh73 gedi.rh74 gedi.rh75 gedi.rh76
## 1      1.12      1.16      1.23      1.31      1.34      1.42      1.49
## 3      0.78      0.82      0.86      0.89      0.97      1.01      1.04
## 4      0.63      0.71      0.74      0.78      0.86      0.89      0.97
## 5      1.08      1.16      1.19      1.27      1.31      1.38      1.46
## 6      4.34      4.90      5.57      6.32      7.11      7.82      8.57
## 7      1.46      1.53      1.60      1.68      1.75      1.83      1.94
##   gedi.rh77 gedi.rh78 gedi.rh79 gedi.rh80 gedi.rh81 gedi.rh82 gedi.rh83
## 1      1.53      1.60      1.68      1.75      1.83      1.90      1.98
## 3      1.12      1.16      1.23      1.27      1.34      1.38      1.46
## 4      1.04      1.08      1.16      1.19      1.27      1.34      1.42
## 5      1.53      1.60      1.68      1.75      1.83      1.90      1.98
## 6      9.36     10.29     11.26     12.24     13.14     13.92     14.63
## 7      2.02      2.13      2.20      2.32      2.43      2.54      2.65
##   gedi.rh84 gedi.rh85 gedi.rh86 gedi.rh87 gedi.rh88 gedi.rh89 gedi.rh90
## 1      2.05      2.13      2.20      2.32      2.39      2.50      2.62
## 3      1.53      1.60      1.68      1.75      1.83      1.90      1.98
## 4      1.49      1.57      1.64      1.72      1.79      1.87      1.98
## 5      2.09      2.20      2.28      2.39      2.54      2.65      2.80
## 6     15.35     16.09     16.84     17.52     18.04     18.53     19.05
## 7      2.80      2.92      3.03      3.18      3.33      3.44      3.59
##   gedi.rh91 gedi.rh92 gedi.rh93 gedi.rh94 gedi.rh95 gedi.rh96 gedi.rh97
## 1      2.73      2.84      2.99      3.14      3.29      3.48      3.70
## 3      2.09      2.20      2.32      2.47      2.62      2.80      3.03
## 4      2.05      2.17      2.28      2.43      2.54      2.73      2.92
## 5      2.95      3.10      3.25      3.44      3.66      3.89      4.15
## 6     19.58     20.14     20.70     21.22     21.71     22.20     22.68
## 7      3.74      3.93      4.08      4.26      4.45      4.68      4.94
##   gedi.rh98 gedi.rh99 gedi.rh100 algorithmrun.flag l2b.quality.flag
## 1      4.00      4.41       5.12                 1                1
## 3      3.33      3.74       4.41                 1                1
## 4      3.14      3.48       4.11                 1                1
## 5      4.45      4.86       5.54                 1                1
## 6     23.21     23.81      24.67                 1                1
## 7      5.24      5.65       6.29                 1                1
##   latitude.lastbin latitude.bin0 longitude.bin0 longitude.lastbin   gedi.pai
## 1         37.85712      37.85712      -110.2303         -110.2303 0.07016369
## 3         37.77660      37.77660      -110.1106         -110.1106 0.10241848
## 4         37.73627      37.73627      -110.0509         -110.0509 0.01360321
## 5         37.69590      37.69590      -109.9912         -109.9912 0.18111534
## 6         37.65550      37.65550      -109.9315         -109.9315 0.51559538
## 7         37.61505      37.61505      -109.8719         -109.8719 0.32282248
##   gedi.fhd.normal gedi.omega gedi.pgap.theta  gedi.cover
## 1       1.5531045          1       0.9655033 0.034473203
## 3       1.4749274          1       0.9500467 0.049919281
## 4       0.6365142          1       0.9932169 0.006778512
## 5       1.5353090          1       0.9133653 0.086575717
## 6       3.1434364          1       0.7726158 0.227229327
## 7       1.6502810          1       0.8508484 0.149049968

Uncertainty analysis

Now to the fun part! Took a while to get here, but hopefully the journey thus far has been somewhat painless. So, the process here is (1) run a for loop with 100 iterations; (2) on each loop select a random tree from the 10,000 original trees; (3) use the decision tree-based biomass predictions from that random tree as the values for the regional-scale predictive model’s training data; (4) build random forest model; (5) apply random forest model to all GEDI footprins at the regional scale; (6) add results to a data frame where each column represents the ith prediction (where i is in [1…100]).

# begin uncertainty loop
for (i in seq(1,100)){
   
   # print status
   print(paste0(Sys.time(), " Iteration: ", i, "/100"))
   
   # random tree selection
   rand.tree <- sample(seq(1,10000), 1)
   
   # add biomass column to table
   df.train$biomass <- biomass.all$individual[,rand.tree]
   y.col.gd <- grep("biomass", colnames(df.train))
   
   # generate random forest model
   rf.gd.i <- ranger(x = df.train[,x.cols.gd],
                     y = df.train[,y.col.gd],
                     num.threads = 24)
   
   # generate prediction
   pred.gd.i <- predict(object = rf.gd.i, 
                        data = df.gd,
                        num.threads = 24)
   
   # create results data frame
   if (i == 1){
      results.df <- data.frame(bio = pred.gd.i$predictions)
      colnames(results.df) <- paste0("bio.", str_pad(i, 3, "left", "0"))
   } else {
      results.df.temp <- data.frame(bio = pred.gd.i$predictions)
      colnames(results.df.temp) <- paste0("bio.", str_pad(i, 3, "left", "0"))
      results.df <- cbind(results.df, results.df.temp)
   }
   
}
## [1] "2021-02-15 18:05:18 Iteration: 1/100"
## [1] "2021-02-15 18:05:20 Iteration: 2/100"
## [1] "2021-02-15 18:05:22 Iteration: 3/100"
## [1] "2021-02-15 18:05:24 Iteration: 4/100"
## [1] "2021-02-15 18:05:26 Iteration: 5/100"
## [1] "2021-02-15 18:05:28 Iteration: 6/100"
## [1] "2021-02-15 18:05:30 Iteration: 7/100"
## [1] "2021-02-15 18:05:31 Iteration: 8/100"
## [1] "2021-02-15 18:05:33 Iteration: 9/100"
## [1] "2021-02-15 18:05:35 Iteration: 10/100"
## [1] "2021-02-15 18:05:36 Iteration: 11/100"
## [1] "2021-02-15 18:05:38 Iteration: 12/100"
## [1] "2021-02-15 18:05:40 Iteration: 13/100"
## [1] "2021-02-15 18:05:42 Iteration: 14/100"
## [1] "2021-02-15 18:05:43 Iteration: 15/100"
## [1] "2021-02-15 18:05:45 Iteration: 16/100"
## [1] "2021-02-15 18:05:47 Iteration: 17/100"
## [1] "2021-02-15 18:05:49 Iteration: 18/100"
## [1] "2021-02-15 18:05:50 Iteration: 19/100"
## [1] "2021-02-15 18:05:52 Iteration: 20/100"
## [1] "2021-02-15 18:05:54 Iteration: 21/100"
## [1] "2021-02-15 18:05:56 Iteration: 22/100"
## [1] "2021-02-15 18:05:58 Iteration: 23/100"
## [1] "2021-02-15 18:05:59 Iteration: 24/100"
## [1] "2021-02-15 18:06:01 Iteration: 25/100"
## [1] "2021-02-15 18:06:03 Iteration: 26/100"
## [1] "2021-02-15 18:06:05 Iteration: 27/100"
## [1] "2021-02-15 18:06:07 Iteration: 28/100"
## [1] "2021-02-15 18:06:08 Iteration: 29/100"
## [1] "2021-02-15 18:06:10 Iteration: 30/100"
## [1] "2021-02-15 18:06:12 Iteration: 31/100"
## [1] "2021-02-15 18:06:14 Iteration: 32/100"
## [1] "2021-02-15 18:06:15 Iteration: 33/100"
## [1] "2021-02-15 18:06:17 Iteration: 34/100"
## [1] "2021-02-15 18:06:19 Iteration: 35/100"
## [1] "2021-02-15 18:06:21 Iteration: 36/100"
## [1] "2021-02-15 18:06:22 Iteration: 37/100"
## [1] "2021-02-15 18:06:24 Iteration: 38/100"
## [1] "2021-02-15 18:06:26 Iteration: 39/100"
## [1] "2021-02-15 18:06:28 Iteration: 40/100"
## [1] "2021-02-15 18:06:30 Iteration: 41/100"
## [1] "2021-02-15 18:06:31 Iteration: 42/100"
## [1] "2021-02-15 18:06:33 Iteration: 43/100"
## [1] "2021-02-15 18:06:35 Iteration: 44/100"
## [1] "2021-02-15 18:06:37 Iteration: 45/100"
## [1] "2021-02-15 18:06:38 Iteration: 46/100"
## [1] "2021-02-15 18:06:40 Iteration: 47/100"
## [1] "2021-02-15 18:06:42 Iteration: 48/100"
## [1] "2021-02-15 18:06:44 Iteration: 49/100"
## [1] "2021-02-15 18:06:46 Iteration: 50/100"
## [1] "2021-02-15 18:06:47 Iteration: 51/100"
## [1] "2021-02-15 18:06:49 Iteration: 52/100"
## [1] "2021-02-15 18:06:51 Iteration: 53/100"
## [1] "2021-02-15 18:06:53 Iteration: 54/100"
## [1] "2021-02-15 18:06:55 Iteration: 55/100"
## [1] "2021-02-15 18:06:56 Iteration: 56/100"
## [1] "2021-02-15 18:06:58 Iteration: 57/100"
## [1] "2021-02-15 18:07:00 Iteration: 58/100"
## [1] "2021-02-15 18:07:02 Iteration: 59/100"
## [1] "2021-02-15 18:07:04 Iteration: 60/100"
## [1] "2021-02-15 18:07:05 Iteration: 61/100"
## [1] "2021-02-15 18:07:07 Iteration: 62/100"
## [1] "2021-02-15 18:07:09 Iteration: 63/100"
## [1] "2021-02-15 18:07:11 Iteration: 64/100"
## [1] "2021-02-15 18:07:13 Iteration: 65/100"
## [1] "2021-02-15 18:07:14 Iteration: 66/100"
## [1] "2021-02-15 18:07:16 Iteration: 67/100"
## [1] "2021-02-15 18:07:18 Iteration: 68/100"
## [1] "2021-02-15 18:07:20 Iteration: 69/100"
## [1] "2021-02-15 18:07:22 Iteration: 70/100"
## [1] "2021-02-15 18:07:23 Iteration: 71/100"
## [1] "2021-02-15 18:07:25 Iteration: 72/100"
## [1] "2021-02-15 18:07:27 Iteration: 73/100"
## [1] "2021-02-15 18:07:29 Iteration: 74/100"
## [1] "2021-02-15 18:07:31 Iteration: 75/100"
## [1] "2021-02-15 18:07:33 Iteration: 76/100"
## [1] "2021-02-15 18:07:35 Iteration: 77/100"
## [1] "2021-02-15 18:07:37 Iteration: 78/100"
## [1] "2021-02-15 18:07:39 Iteration: 79/100"
## [1] "2021-02-15 18:07:40 Iteration: 80/100"
## [1] "2021-02-15 18:07:42 Iteration: 81/100"
## [1] "2021-02-15 18:07:44 Iteration: 82/100"
## [1] "2021-02-15 18:07:46 Iteration: 83/100"
## [1] "2021-02-15 18:07:48 Iteration: 84/100"
## [1] "2021-02-15 18:07:49 Iteration: 85/100"
## [1] "2021-02-15 18:07:51 Iteration: 86/100"
## [1] "2021-02-15 18:07:53 Iteration: 87/100"
## [1] "2021-02-15 18:07:55 Iteration: 88/100"
## [1] "2021-02-15 18:07:57 Iteration: 89/100"
## [1] "2021-02-15 18:07:59 Iteration: 90/100"
## [1] "2021-02-15 18:08:01 Iteration: 91/100"
## [1] "2021-02-15 18:08:03 Iteration: 92/100"
## [1] "2021-02-15 18:08:04 Iteration: 93/100"
## [1] "2021-02-15 18:08:06 Iteration: 94/100"
## [1] "2021-02-15 18:08:08 Iteration: 95/100"
## [1] "2021-02-15 18:08:10 Iteration: 96/100"
## [1] "2021-02-15 18:08:12 Iteration: 97/100"
## [1] "2021-02-15 18:08:14 Iteration: 98/100"
## [1] "2021-02-15 18:08:15 Iteration: 99/100"
## [1] "2021-02-15 18:08:17 Iteration: 100/100"
# print the first few rows
head(results.df)
##    bio.001  bio.002   bio.003  bio.004  bio.005   bio.006   bio.007  bio.008
## 1 22.27942 14.69435  16.29243 24.42585 18.63741  13.52442  21.48355 15.99506
## 2 19.67346 18.06148  22.78708 22.23714 20.96765  18.66953  21.30550 21.61167
## 3 22.32043 15.29182  17.27637 26.80939 27.09408  21.93075  24.48354 19.91888
## 4 38.30301 50.68184  42.09266 44.64103 43.00299  43.12307  55.97270 42.71188
## 5 93.18372 91.91603 100.42045 92.81934 69.93090 101.17317 102.64011 94.75933
## 6 61.79691 63.59656  58.69741 61.35101 51.17896  68.92859  69.92156 57.42127
##    bio.009   bio.010  bio.011  bio.012  bio.013  bio.014  bio.015  bio.016
## 1 13.96174  15.55612 10.23473 13.17932 19.67915 20.55815 16.30947 14.71733
## 2 21.69136  16.35749 16.17454 18.43933 20.84688 22.89881 16.57677 16.07537
## 3 29.26300  18.49460 20.06500 17.80887 18.68490 22.36958 20.17746 19.05247
## 4 40.08709  61.37381 39.24650 41.57294 50.04086 36.43035 43.74516 43.02401
## 5 95.67208 119.61810 92.86856 71.45976 57.44527 87.54457 97.52655 84.97316
## 6 64.90551  61.80667 58.60606 55.18776 62.27910 60.61659 64.19792 65.05772
##    bio.017   bio.018  bio.019  bio.020  bio.021  bio.022  bio.023   bio.024
## 1 17.79169  13.54247 10.59542 12.51206 10.41354 18.70886 15.77924  10.82601
## 2 22.43536  19.10542 14.64626 18.01027 16.52926 17.79113 20.63946  17.32949
## 3 28.16950  18.98964 17.08459 21.87694 14.13509 19.27543 24.38472  21.70721
## 4 52.81015  40.36746 35.21710 52.02150 34.04377 37.50186 37.34300  51.25030
## 5 98.10719 104.29236 70.67203 88.40856 93.70741 92.23106 98.29841 114.92519
## 6 74.00279  69.74147 60.55424 61.12187 57.18725 50.40022 57.99546  60.74018
##     bio.025   bio.026   bio.027   bio.028   bio.029   bio.030  bio.031  bio.032
## 1  21.11047  14.91864  19.94166  13.62953  12.41264  19.63164 16.86713 16.02432
## 2  17.67301  20.09337  18.08309  18.26131  19.13612  22.60352 23.61832 19.19966
## 3  20.04320  19.70440  21.70357  15.23396  22.04460  26.10356 23.33769 23.17656
## 4  47.95770  30.22659  40.69955  32.36373  46.90784  58.18023 39.13856 41.47660
## 5 107.08367 116.80866 114.46630 105.25831 100.26027 120.80177 61.52974 70.19684
## 6  69.89214  52.46016  55.03279  55.72411  63.66523  68.52009 59.59483 68.28460
##    bio.033  bio.034  bio.035   bio.036   bio.037   bio.038  bio.039  bio.040
## 1 16.12001 15.09365 17.92440  15.04401  14.46048  16.25425 13.36001 17.01762
## 2 18.52417 19.50970 23.35378  23.35836  18.10660  17.76099 22.84247 20.17864
## 3 24.31364 24.28219 33.78836  26.16699  16.72675  22.20043 23.91846 19.51582
## 4 43.78143 45.85303 65.22213  41.33831  38.49141  46.68495 45.69466 42.51943
## 5 91.98395 95.12019 96.84261 111.27543 101.91780 102.15168 91.05243 97.07201
## 6 51.62628 62.27898 56.57526  65.48147  59.50346  49.60086 58.41665 59.35197
##    bio.041  bio.042   bio.043   bio.044   bio.045  bio.046  bio.047  bio.048
## 1 15.32653 17.83774  14.98512  13.23351  19.71306 14.18766 19.19883 22.07051
## 2 21.54980 21.20763  17.49358  19.93035  18.40353 16.97543 21.80805 16.51714
## 3 24.38711 21.80136  15.86516  16.98510  20.81463 22.48475 21.90159 25.00329
## 4 42.29064 40.39438  38.76559  41.47974  41.76744 42.42495 42.50748 43.36957
## 5 95.94444 75.80407 109.99540 112.56553 100.15087 93.79495 95.32137 92.30963
## 6 80.82509 63.08265  63.20048  72.41501  43.42142 66.14537 66.06722 64.19578
##    bio.049   bio.050   bio.051  bio.052   bio.053  bio.054  bio.055  bio.056
## 1 15.60341  12.85010  13.85454 14.99372  20.61366 15.70558 14.03981 19.76506
## 2 17.01641  20.27299  19.03070 16.16495  17.46214 21.51782 20.97093 22.58615
## 3 28.99752  20.95218  23.15393 17.64862  27.50688 17.85761 22.92188 28.49433
## 4 35.93395  42.64741  54.58366 38.59008  43.43309 35.77066 37.88066 52.59915
## 5 94.24258 115.97963 103.57497 92.11172 113.45427 72.31846 92.75175 97.75204
## 6 67.55216  45.72222  45.13451 69.62119  64.73214 64.87823 60.30550 70.42214
##    bio.057   bio.058  bio.059  bio.060  bio.061  bio.062   bio.063  bio.064
## 1 12.65260  15.94730 20.18167 21.41485 21.03852 17.93279  14.24408 22.78163
## 2 20.65803  20.68827 19.56374 19.91202 16.37755 21.20169  21.19216 17.70838
## 3 17.91187  20.58456 23.16687 27.29638 22.34213 24.61986  23.39299 16.81495
## 4 38.16268  43.85243 38.80042 48.52832 48.92231 53.66292  40.88470 36.29896
## 5 91.27437 100.18869 97.61591 76.73630 83.02156 91.60900 115.91778 90.23199
## 6 58.37456  75.95444 53.26628 53.11362 73.26924 57.10876  46.63388 51.74185
##    bio.065   bio.066   bio.067   bio.068  bio.069  bio.070   bio.071   bio.072
## 1 12.50898  13.31710  18.99229  16.04515 16.21263 15.48293  15.11614  15.16355
## 2 19.56605  16.58078  17.04673  17.87390 17.99271 22.61681  16.67882  20.00172
## 3 23.18931  15.12274  24.00154  21.37842 21.54464 23.85917  24.34550  18.48380
## 4 37.29983  46.87274  44.73380  37.60421 50.45423 40.86087  42.52895  56.74804
## 5 90.35514 105.07277 119.47328 101.82945 80.21257 93.56618 103.93218 103.32690
## 6 55.56784  56.35817  71.74525  50.91766 63.36610 58.89260  73.94270  68.51988
##     bio.073  bio.074  bio.075   bio.076   bio.077  bio.078   bio.079   bio.080
## 1  15.63544 11.32852 13.76141  12.58680  15.86381 20.80643  16.96262  18.94878
## 2  18.59388 17.63387 18.58002  20.87530  16.80975 19.98526  17.90559  17.62397
## 3  21.32837 16.86766 18.81511  28.05110  19.04308 26.64106  20.92642  22.46722
## 4  49.35506 37.13137 44.55576  64.79188  36.60140 56.69034  44.79138  39.49292
## 5 103.44050 93.82135 89.20792 100.28633 101.40723 79.98124 103.83589 108.13968
## 6  58.51923 61.26432 44.55950  62.92634  41.95543 68.64588  58.73192  59.73399
##    bio.081   bio.082  bio.083   bio.084  bio.085  bio.086  bio.087   bio.088
## 1 15.50052  13.64986 17.88680  11.66330 14.53277 14.57883 22.58310  25.07212
## 2 23.92169  16.85074 21.35305  16.42704 20.66761 20.41321 25.36220  22.02092
## 3 20.91271  18.54515 25.45126  21.20827 20.35056 26.99380 25.43650  21.98372
## 4 36.97373  46.38558 56.92459  36.08261 38.66915 40.37893 40.98408  42.74167
## 5 84.19984 100.84547 84.67672 105.88689 84.86401 99.40741 87.80978 105.97454
## 6 58.01823  65.13457 60.76739  67.17963 54.64972 66.81767 60.25108  50.48793
##    bio.089  bio.090  bio.091   bio.092  bio.093  bio.094  bio.095   bio.096
## 1 18.59785 22.22894 16.20806  14.20707 14.02582 18.52680 15.55398   7.48998
## 2 21.98616 19.41517 18.96764  23.55896 16.85858 22.09469 17.07118  16.53038
## 3 20.54857 22.78202 23.96982  22.02145 29.03539 17.40119 20.61280  18.25974
## 4 42.14656 39.84997 44.00885  44.27109 40.39790 49.67918 40.62339  36.34454
## 5 84.27423 91.42249 96.14705 116.90336 98.52951 98.94345 84.66121 102.24258
## 6 69.76470 67.33392 64.39218  54.34470 57.85073 56.04324 58.13443  61.94140
##    bio.097  bio.098   bio.099  bio.100
## 1 11.60516 18.13500  19.54418 23.48656
## 2 17.51103 22.25513  17.25299 20.91889
## 3 21.57258 27.92126  19.54092 34.58831
## 4 53.07158 43.40369  45.67832 45.90342
## 5 87.27844 91.90942 118.45712 82.70336
## 6 60.62625 59.20814  66.20542 59.68364

Summarize the results

Using that results data frame (“results.df”) generate a new dataframe with summary statistics. And write the outputs to a shapefile.

# create results data frame
summary.df <- df.gd[,c("shot.num", "latitude.bin0", "longitude.bin0")]
summary.df$bio.pred <- predict(rf.gd, df.gd)
summary.df$uc.mean <- apply(results.df, 1, mean)
summary.df$uc.sd <- apply(results.df, 1, sd)
summary.df$uc.cv <- summary.df$uc.sd / summary.df$uc.mean
summary.df$uc.q05 <- apply(results.df, 1, FUN = function(x) quantile(x, 0.05))
summary.df$uc.q95 <- apply(results.df, 1, FUN = function(x) quantile(x, 0.95))

# write results to shapefile
summary.spdf <- SpatialPointsDataFrame(coords = summary.df[,c("longitude.bin0",
                                                              "latitude.bin0")],
                                       data = summary.df,
                                       proj4string = CRS("+init=epsg:4326"))
writeOGR(summary.spdf, uc.dir, "gedi_biomass_pred_pts_summary_lidar_boxes_top_4", "ESRI Shapefile", overwrite_layer = T)
## Warning in writeOGR(summary.spdf, uc.dir,
## "gedi_biomass_pred_pts_summary_lidar_boxes_top_4", : Field names abbreviated for
## ESRI Shapefile driver

Drink a cocktail and ponder why the results look weird

That’s it!