separate_flags: Separate flag masks

View source: R/satfile_funcs.R

separate_flagsR Documentation

Separate flag masks

Description

Given a vector or matrix of quality flags using the bit string system for flags, and the indices of the bits to use (starting at 1, for bit0), separate the flag mask into individual flags.

Usage

separate_flags(flags, which_bits)

Arguments

flags

Matrix or vector of flags

which_bits

Bit masks to retrieve, starting at 0 (bit 0 value = 2^0 = 1)

Value

List, in the same order as which_bits, where each list item is a logical matrix or vector (same size as "flags") that contains only the information for a particular bit

Examples

# load example SGLI dataset containing real data, their quality flags, and flag descriptions
data("example02_GC1SG1_202109031518L33309_L2SG_IWPRK_2000")
data("sgli_flag_df")
flag_dat <- example02_GC1SG1_202109031518L33309_L2SG_IWPRK_2000$flags
# subset to see a quick example
flag_dat <- flag_dat[1:100]
# bits to retrieve
bits <- c(0:5,8)
bit_names <- sgli_flag_df$name[sgli_flag_df$bit %in% bits]
# try splitting flags in vector format
sfl <- separate_flags(flag_dat, bits)
sfl <- do.call(cbind,sfl)
colnames(sfl) <- bit_names
sfl
# now try it in matrix format
flag_dat <- matrix(flag_dat,nrow=10)
sfl <- separate_flags(flag_dat, bits)
# plot the STRAYLIGHT flag
names(sfl) <- bit_names
raster::spplot(raster::raster(sfl$STRAYLIGHT))


BIO-RSG/oceancolouR documentation built on April 30, 2024, 7:54 a.m.