Skip to content

Commit

Permalink
Merge branch 'master' into devel
Browse files Browse the repository at this point in the history
# Conflicts:
#	DESCRIPTION
#	NEWS.md
  • Loading branch information
Jean-Romain committed Nov 8, 2023
2 parents 7b355f4 + 6d9e64e commit d97f0f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Following the retirement of `rgdal` and `sp` we removed the dependence to `sp` a
4. Change: the function `extent` was removed in consequence of (3) because it was inherited from `raster` and returned an object `Extent` from `raster`.
5. Change: functions `crs`, `crs<-`, `projection`, `projection<-`, `wkt` and `area` inherited from `raster` are now generic. This may create clash with the `raster` package but anyway `raster` should no longer be used.

### Fixes

- Fix: [#726](https://github.com/r-lidar/lidR/issues/726) character palette causes error in plot.

## lidR v4.0.4 (Release date: 2023-09-07)

- Fix: interpolation of NA pixels failed when a single pixel is missing [#684](https://github.com/r-lidar/lidR/issues/684)
Expand Down
40 changes: 18 additions & 22 deletions R/metrics_stdmetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -550,30 +550,29 @@ rumple_index.numeric <- function(x, y = NULL, z = NULL, ...)
#' @rdname nstdmetrics
gap_fraction_profile = function(z, dz = 1, z0 = 2)
{
bk <- seq(floor((min(z) - z0)/dz)*dz + z0, ceiling((max(z) - z0)/dz)*dz + z0, dz)

if (length(bk) <= 1)
zrange = range(z)
if (z0 < zrange[1])
z0 = floor((zrange[1]- z0)/dz)*dz + z0

if (z0 >= zrange[2])
return(data.frame(z = numeric(0), gf = numeric(0)))

histogram <- graphics::hist(z, breaks = bk, plot = F)

bk <- seq(z0, ceiling((zrange[2] - z0)/dz)*dz + z0, dz)

histogram <- graphics::hist(z, breaks = c(-Inf, bk), plot = F)
h <- histogram$mids
p <- histogram$counts/sum(histogram$counts)

p <- c(p, 0)

p <- histogram$counts

cs <- cumsum(p)
i <- data.table::shift(cs)/cs
i <- cs[1:(length(cs)-1)]/cs[2:length(cs)]

i[is.na(i)] = 0

i[is.nan(i)] = NA

z = h #[-1]
i = i[-length(i)] #[-c(1, length(i))]

return(data.frame(z = z[z > z0], gf = i[z > z0]))

z = h[-1]

return(data.frame(z = z, gf = i))
}


#' @param k numeric. is the extinction coefficient
#' @examples
#' z <- c(rnorm(1e4, 25, 6), rgamma(1e3, 1, 8)*6, rgamma(5e2, 5,5)*10)
Expand All @@ -588,10 +587,7 @@ LAD = function(z, dz = 1, k = 0.5, z0 = 2) # (Bouvier et al. 2015)
{
ld <- gap_fraction_profile(z, dz, z0)

if (nrow(ld) <= 2)
return(data.frame(z = numeric(0), lad = numeric(0)))

if (anyNA(ld))
if (nrow(ld) == 0)
return(data.frame(z = numeric(0), lad = numeric(0)))

lad <- ld$gf
Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ plot.LAS = function(x, y, ...,
has_col <- color %in% names(x)
use_rgb <- color == "RGB"
has_rgb <- all(c("R", "G", "B") %in% names(x))
autocol <- is.character(pal) && pal == "auto"
autocol <- is.character(pal) && length(pal) == 1 && pal == "auto"

# Error handling
assert_is_a_bool(clear_artifacts)
Expand Down

0 comments on commit d97f0f7

Please sign in to comment.