土壤剖面数据插值

本文最后更新于 2026年1月18日 晚上

背景介绍

在处理土壤数据时,由于不同研究的土壤采样深度各不相同,直接比较会导致偏差。为解决此问题,本研究采用了质量守恒样条函数(mass-preserving spline function)这一关键技术。该方法通过R语言的mpspline2包实现,可将所有不同深度的土壤剖面数据统一插值并计算到标准深度,以确保所有样点在同一深度标准下进行比较。

mpspline2包介绍

mpspline2包是对GSIF::mpspline()函数的独立重实现,专门用于将”质量守恒(mass-preserving)样条”应用于土壤属性数据。

对土壤剖面数据进行样条拟合(splining)是一种稳健的方法,可将离散(且常不连续)深度区间内测得的属性值,转换为沿深度方向连续的剖面估计。

安装方式

从CRAN安装

1
install.packages('mpspline2')

从GitHub安装

1
remotes::install_github("obrl-soil/mpspline2")

使用示例

基础示例

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
library(mpspline2)

dat <- data.frame(
"SID" = c(1, 1, 1, 1),
"UD" = c(0, 20, 40, 60),
"LD" = c(10, 30, 50, 70),
"VAL" = c(6, 4, 3, 10),
stringsAsFactors = FALSE
)

dat
#> SID UD LD VAL
#> 1 1 0 10 6
#> 2 1 20 30 4
#> 3 1 40 50 3
#> 4 1 60 70 10

# 运行插值
spl_dat <- mpspline_tidy(obj = dat, var_name = 'VAL')

# 查看插值结果
spl_dat$est_dcm
#> SID UD LD SPLINED_VALUE
#> 1.1 1 0 5 6.105160
#> 1.2 1 5 15 5.618341
#> 1.3 1 15 30 4.316876
#> 1.4 1 30 60 4.192058
#> 1.5 1 60 100 9.732400

完整实现流程

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## 0. 加载所需包
library(readxl)
library(dplyr)
library(mpspline2)
library(writexl)

## 1. 读取Excel数据
dat <- read_xlsx("filtered_data.xlsx")

## 2. 基本检查:确认关键字段存在
required_cols <- c(
"profile_id",
"upper_depth",
"lower_depth",
"ORGC"
)

missing_cols <- setdiff(required_cols, names(dat))
if (length(missing_cols) > 0) {
stop(paste("缺少必要字段:", paste(missing_cols, collapse = ", ")))
}

## 3. 整理为mpspline所需格式
# 注意:mpspline只关心profile_id / upper_depth / lower_depth / ORGC
dat_mps <- dat %>%
select(
profile_id,
upper_depth,
lower_depth,
ORGC,
longitude,
latitude,
date
) %>%
arrange(profile_id, upper_depth)

## 4. 设定目标标准深度层(cm)
# 示例:0–5, 5–15, 15–30 cm
target_depth <- c(0, 5, 15, 30)

## 5. 运行mpspline插值(自动对所有剖面)
res <- mpspline_tidy(
obj = dat_mps,
var_name = "ORGC",
lam = 0.1,
d = target_depth,
vlow = 0,
vhigh = 200
)

## 6. 提取插值结果并查看字段
soc_interp <- res$est_dcm

# 查看结果包含的列
print(names(soc_interp))

## 7. 合并经纬度和时间信息
site_info <- dat_mps %>%
distinct(profile_id, longitude, latitude, date)

final_result <- soc_interp %>%
left_join(site_info, by = "profile_id") %>%
arrange(profile_id, UD) # 按上深度排序

## 8. 导出为Excel
write_xlsx(
final_result,
path = "ORGC_mpspline_interpolated.xlsx"
)

## 9. 提示完成
message("mpspline插值完成,结果已保存为ORGC_mpspline_interpolated.xlsx")

数据组织格式

输入数据格式示例

profile_id upper_depth lower_depth ORGC longitude latitude date
1 0 5 1.2 116.397 39.916 2021
1 5 15 1.5 116.397 39.916 2021
1 15 30 1.8 116.397 39.916 2021
2 0 10 2.0 117.200 40.133 2021
2 10 30 2.3 117.200 40.133 2021

输出结果说明

最终输出的插值结果将包含以下关键字段,方便后续分析和应用:

  • profile_id:土壤剖面唯一标识符
  • UD:插值后的上深度(cm)
  • LD:插值后的下深度(cm)
  • SPLINED_VALUE:插值得到的土壤属性值
  • longitude:经度
  • latitude:纬度
  • date:采样日期

更多资源

关于mpspline2包的详细说明和参数解释,请参考mpspline2官方文档


土壤剖面数据插值
https://bingoodog.github.io/links/soil-surface-interpolation.html
作者
bin
发布于
2026年1月13日
许可协议