l4_process: Process GEDI level 4 data.

View source: R/l4_process.R

l4_processR Documentation

Process GEDI level 4 data.

Description

Perform the entire processing chain of extracting, clipping and exporting GEDI data. See here for more documentation on GEDI L4 data. This is the main function of the package. It perform all operations in chunks of files in parallel. It runs in order l4_getmulti, l4_clip, l4_convert to each chunk.

Usage

l4_process(
  gediL4_path,
  nfile = NULL,
  clip = NULL,
  epsg = NULL,
  prefix = "chunk",
  outdir = NULL,
  ext = NULL,
  parallel = T,
  ncore = NULL,
  add_col = NULL,
  tct = NULL
)

Arguments

gediL4_path

List or vector of character path to GEDI level4A h5 file.

nfile

Numeric : number of file processed at time. It affect the numbers of total chunks in which files will be split. Default to NULL.

clip

An object from which an extent can be obtained (xmin, xmax, ymin, ymax). Currently could be a path to a shp or tif file, an object of class sf, a Raster* object, a SpatRaster, SpatVector, or a numeric vector of coordinates.

epsg

Numeric: destination EPSG code. Default to NULL.

prefix

Character: prefix name for exported chunks. Default to "chunk".

outdir

Character: directory in which to save output files. If it doesn't exist it will be created.

ext

Character: extension of vector files to be saved.

parallel

Logical: if TRUE (default) the chain process are executed in parallel. In this case the function try to guess the best number of cores to use based based on the maximum available and the number of files to be processed.

ncore

Numeric: numbers of core to be used if the maximum core available is less than the length of gediL4_path Default to the number of cores available minus one.

add_col

Character vector of extra datasets names to cbind to the default output. Names already present will be dropped.

tct

Numeric: tree cover threshold to filter GEDI data.

Details

The function use by default usegeometry=TRUE in l4_clip This is usually the desired behavior for the function. If parallel=TRUE, the function will try to guess the best number of cores to be used in l4_getmulti and in the chunks loop, based on the maximum cores available and the length of gediL4_path. The user can override the number of core used in l4_getmulti with ..., by specifying the argument ncore. This will also affect the number of cores used to loop over chunks. Usually, the number of cores used by default is the best option, modifying it can slow down the function. See ?l4_getmulti for columns specification of the output. For downloading more detailed information on GEDI Level 4A data (version 2) see product data dictionary. Note that by default, the function will drop all footprints in which agbd<0. These observations are considered sensor errors.

Value

A vector of file paths inside outdir. Outputs will be written as outdir/prefix_x_y.ext, where x and y are the first and last file number in that chunk and ext is the extension specified by the parameter ext.

See Also

l4_getmulti, l4_clip, l4_convert

Examples


outdir = tempdir()
l4_zip <- system.file("extdata",
                     c("GEDI04_A_2020036151358_O06515_02_T00198_02_002_01_V002.zip"
                     ),
                     package="GEDI4R")
#Unzipping GEDI level4A data
l4 <- unzip(l4_zip,exdir = outdir)
#create 4 copy of GEDI file to test the function
file.copy(from=l4,to=paste0(tools::file_path_sans_ext(l4),"_copy",1:4,".h5"))
#path to Shapefile for clipping the data
bound <- system.file("extdata","bound4326.shp",package="GEDI4R")
#path to GEDI files
l4_path <- list.files(outdir,pattern = "h5",full.names = T)
#proces all files in chunk each of 2 files, in sequence
l4_data <- l4_process(l4_path,nfile=2,clip=bound,epsg=4326,outdir=outdir,ext="shp",parallel=F,prefix = "ex")
file.remove(list.files(outdir,full.names = T, pattern = "ex"))
#in parallel
l4_data <- l4_process(l4_path,nfile=2,clip=bound,epsg=4326,outdir=outdir,ext="shp",parallel=T)
file.remove(list.files(outdir,full.names = T, pattern = "ex"))

VangiElia/GEDI4R documentation built on April 8, 2023, 6:13 p.m.