How to interpolate soil depth values using "Spline"? Or using the "aqp" package?

Asked

Viewed 177 times

1

Hello, I would like to interpolate the soil depth values in the columns "top" and "bottom", (every 5 units) in the soil data, for example in the dataframe:

id_num    id_name horiz  top bottom  K   Mg   Ca CEC_7 ex_Ca_to_Mg sand silt clay   CF
1          colusa    A   0      12 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
2          colusa  ABt   12     28 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
3          colusa  Bt1   28     52 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
5           glenn    A   0       9 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
6           glenn   Bt   9      34 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84

So I have (top-bottom = 0-12, 12-28, 28-52, ...) and i would like to get the columns "top" and "bottom" interpolated by 5 units (cm in this case), for example (top-bottom = 0-5, 5-10, 10-15, 15-20, 20-25, 25-30, 30-35, 35-40, 40-45, 45-50, ...), interpolating values and repeating the other corresponding columns as id_num, id_name and horiz, as an example:

id_num    id_name horiz  top bottom  K   Mg   Ca CEC_7 ex_Ca_to_Mg sand silt clay   CF
1          colusa    A   0       5 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
1          colusa    A   5      10 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
2          colusa  ABt   10     15 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
2          colusa  ABt   15     20 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
2          colusa  ABt   20     25 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
3          colusa  Bt1   25     30 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   30     35 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   35     40 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   40     45 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   45     50 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
5           glenn    A   0       5 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
5           glenn    A   5      10 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
6           glenn   Bt   10     15 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   15     20 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   20     25 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   25     30 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   30     35 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84

Note: In this example the values are not interpolated (only repeated).

The sample data set can be viewed with the command data(sp4).

I tried the function slice package aqp with:

data(sp4) #obter o conjunto de dados de solo de exemplo
depths(sp4) <- id ~ top + bottom #ajustar os dados para o pacote `aqp` package
sliced <- slice(sp4, fm= c(0,5,10,15,20,25,30,35,40,45,50) ~ sand + silt + clay + name + ex_Ca_to_Mg, just.the.data=TRUE)

But I got:

(top-bottom = 0-1, 5-6, 10-11, 15-16, 20-21, 25-26, 30-31, 35-36, 40-41, 45-46, ...)

instead of:

(top-bottom = 0-5, 5-10, 10-15, 15-20, 20-25, 25-30, 30-35, 35-40, 40-45, 45-50, ...)

I also tried the function slab, but it hasn’t worked for me yet.

Suggestions with spline are very welcome!

Thank you very much!

1 answer

2


1) First you have to rearrange your table so that each column represents a soil profile.

2) The range of values to be predicted must be 'NA'. Ex:

0.3
NA
NA
0.2

3) Install the library(zoo);

4) Organize all your data into one data.frame(); use the function na.spline():

data.frame('id' = c(1, 2, NA, 4, 6, NA, NA, NA, 6.5)) -> exemplo
na.spline(exemplo) -> exemplo_preenchido
print(exemplo_preenchido)
  • Thank you very much Michel!!! Great solution! Simple and fast. I will organize the data and post the commands! (it may take a while...)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.