我如何在 R 中按位置和纬度 运行 thornthwaite 函数(计算标准降水指数)?

How do I run a thornthwaite function (which computes standard precipitation index) by location and latitude in R?

我有以下数据:

dat <- read.table(text="
  id YEAR    MONTH   TMED    PRCP    lat
   1  1986    1      -14.5    2.3    42.4863
   1  1986    2      -13.9    5.7    42.4863
   2  1986    1      -12.9    7.2    42.46
   2  1986    2      -11.6    19.7   42.46", header=TRUE)

其中

我需要 运行 R 中的以下函数来计算每个位置的 SPEI 指数(标准降水-蒸散指数):

library(SPEI)

dat$PET <- thornthwaite(dat$TMED, dat$lat[1])

dat$BAL <- dat$PRCP-dat$PET

spei1 <- spei(dat$BAL, scale = 1)

dat$spei1=l

此代码适用于一个位置。但我需要对纬度和位置进行循环。一个问题是,latitude 应该作为一个数字(而不是 list/variable)进入函数 thornthwaite

为了我的生态大师,我试了一下Thornthwaite equation,这个实现看起来有点奇怪。不管它在这里看起来如何,该方程需要的不仅仅是平均温度和纬度作为输入。它实际上需要给定月份的平均日照长度,但这可以根据纬度和日期计算,并且 thornthwaite() 通过假设第一个数据点代表一月来获取日期,其余数据点按顺序排列。 Thornthwaite 方程还取决于年度热指数,这意味着您需要全年的月温度平均值。 thornthwaite() 通过聚合您提供的温度向量来解决这个问题。

总而言之,要使 thornthwaite() 正常工作,您需要按顺序从 1 月开始并至少跨越一年的月平均温度序列。因此,该函数将无法处理您提供的数据。

我建议您确保您的系列足够长,并将其拆分为每个位置的单独 data.frames。您可以为此使用 split() (split(dat, dat$id))。

?thornthwaite 中有几个示例,其中一个演示了它在时间序列上的应用,如果您的序列不是从 1 月开始的,则很有用。

我制作了一个模型来展示一种可能的方法:
(请注意,即使数据不涵盖整年,该函数也会 return 值,这些值将非常不可靠。)

dat <- read.table(text="
  id YEAR    MONTH   TMED    PRCP    lat
   1  1986    1     -14.5    2.3    42.4863
   1  1986    2     -13.9    5.7    42.4863
   1  1986    3     -10.5    2.3    42.4863
   1  1986    4      -7.9    5.7    42.4863
   1  1986    5      -4.5    2.3    42.4863
   1  1986    6       0.9    5.7    42.4863
   1  1986    7      10.5    2.3    42.4863
   1  1986    8      17.9    5.7    42.4863
   2  1986    1     -12.9    7.2    42.46
   2  1986    2     -11.6   19.7    42.46
   2  1986    3      -8.9    7.2    42.46
   2  1986    4      -5.9    7.2    42.46
   2  1986    5       1.6   19.7    42.46
   2  1986    6      12.9    7.2    42.46
   2  1986    7      21.6   19.7    42.46
   2  1986    8      25.6   19.7    42.46", header=TRUE)

dat.s <- split(dat, dat$id)

lapply(dat.s, function(x) thornthwaite(x$TMED, x$lat[1]))