average_by_group: average_by_group

Description Usage Arguments Value Examples

View source: R/average_by_group.R

Description

Average multiple matrices or rasters within groups.

Usage

1
average_by_group(metadata, img_list, id, grouping_var, round_val = NULL)

Arguments

metadata

A dataframe denoting the grouping of different images.

img_list

List or stack of numeric temperature matrices or rasters.

id

Name of the metadata variable that identifies unique images. Should match element names in the image list.

grouping_var

The name of the metadata variable that denotes the grouping of images.

round_val

Number of decimals to round to (optional).

Value

If img_list is supplied as a list of matrices, returns a new list of matrices with one element for each unique value of the grouping variable.

If img_list is supplied as a raster stack, returns a new raster stack with one raster for each unique value of the grouping variable.

Grouping variables with no matching images are dropped.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Load raw data
raw_dat <- flir_raw$raw_dat
camera_params <- flir_raw$camera_params
metadata <- flir_metadata

# Batch convert
img_list <- batch_convert(raw_dat, write_results = FALSE)

# With list of matrices -----------------------------------------------------

# Average matrices in list
avg_list <- average_by_group(metadata = metadata,
                             img_list = img_list,
                             id = "photo_no",
                             grouping_var = "rep_id")
                             
# With raster stack ---------------------------------------------------------

# Coerce matrix list to raster stack
mat_stack <- stack_imgs(img_list)

# Average in raster stack
avg_stack <- average_by_group(metadata = metadata,
                              img_list = mat_stack,
                              id = "photo_no",
                              grouping_var = "rep_id")
# Plot
raster::plot(avg_stack)

# Compare to invididual pics
# Photos 8565 and 8583 were averaged to make T7P1
# Photos 8589 and 8613 were averaged to make T7P2

allstack <- raster::stack(mat_stack, avg_stack)
if (requireNamespace("rasterVis", quietly = TRUE)){
    rasterVis::levelplot(allstack,
                        layout=c(2, 3),
                        index.cond=list(c(1, 3, 2, 4, 5, 6)))
}
                    

rasenior/PatchStatsFLIR documentation built on Oct. 28, 2020, 11:53 p.m.