Skip to contents

Turns twelve monthly mean daily rates into one annual mean daily rate in the same units: npp = sum_m rate_m * days_m / days_in_year, where a month without a retrieval (NA: polar night, ice, no data) contributes 0 and days_in_year is 365 or 366 for a leap year. A cell with no retrieval in ANY month stays NA (land, permanent no-data) rather than becoming a zero, so land is never painted as zero production. n_valid counts the months with a retrieval, so the share of a year a cell was observed travels with its rate.

Usage

vgpm_annual_integrate(monthly, year)

Arguments

monthly

a SpatRaster of 12 layers, the monthly mean daily rates in month order (January first), NA = no retrieval.

year

integer; the calendar year of the twelve months (sets days_m and leap years).

Value

a 2-layer SpatRaster: npp (the annual mean daily rate) and n_valid (0-12).

Details

Because the result is still a mean daily rate, nothing downstream changes units: with twelve observed months it equals the day-weighted mean of the months (and, for equal-length months, the plain mean the old recipe used); with six months of 100 and six of NA it is 100 * days(those six) / 365, not 100.

Examples

if (FALSE) { # \dontrun{
m <- terra::rast(replicate(12, matrix(100, 2, 2), simplify = FALSE) |> lapply(terra::rast))
vgpm_annual_integrate(m, 2019)
} # }