julienmoeys / soiltexture

The Soil Texture Wizard (R package soiltexture)
27 stars 10 forks source link

soil class not found #10

Open edvlmaas opened 6 months ago

edvlmaas commented 6 months ago

Hi, I'm using sand=12, silt=50, clay=38. This site https://agritechcenter.com.np/soil-calculator.html puts it at a silty clay loam, but the TT.points.in.classes function with class.sys="USDA.TT" returns "int[0, 1:12]" and viewing the resulting data frame says, "No data available in table".

If I use this code, I get a positive result ("Lo"): soil_texture_df <- data.frame(SAND=46, SILT=40, CLAY=14)

soil_type_ar <- TT.points.in.classes(tri.data=soil_texture_df[1,], class.sys="USDA.TT")

jonaslenz commented 6 months ago

Hi edvlmaas, which version of soiltexture are you using? I tried it with your desired values and the recent soiltexture version 1.5.3. It correctly returned a silty clay loam.

soil_texture_df <- data.frame(SAND=12,
SILT=50,
CLAY=38)

TT.points.in.classes(tri.data=soil_texture_df,
class.sys="USDA.TT")

>     Cl SiCl SaCl ClLo SiClLo SaClLo Lo SiLo SaLo Si LoSa Sa
>[1,]  0    0    0    0      1      0  0    0    0  0    0  0
edvlmaas commented 6 months ago

I’m using version 1.5.3 on R version 4.3.2. It works with a different texture I entered (a loam), just not the silty clay loam I sent you.Sent from my iPhoneOn Apr 29, 2024, at 9:23 AM, jonaslenz @.***> wrote: Hi edvlmaas, which version of soiltexture are you using? I tried it with your desired values and the recent soiltexture version 1.5.3. It correctly returned a silty clay loam. soil_texture_df <- data.frame(SAND=12, SILT=50, CLAY=38)

TT.points.in.classes(tri.data=soil_texture_df, class.sys="USDA.TT")

Cl SiCl SaCl ClLo SiClLo SaClLo Lo SiLo SaLo Si LoSa Sa

[1,] 0 0 0 0 1 0 0 0 0 0 0 0

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

jonaslenz commented 6 months ago

So can you try again with this code and send a screen shot of the output?

soil_texture_df <- data.frame(SAND=12,
SILT=50,
CLAY=38)

TT.points.in.classes(tri.data=soil_texture_df,
class.sys="USDA.TT")
edvlmaas commented 6 months ago
> soil_texture_df <- data.frame(SAND=12,
+                               SILT=50,
+                               CLAY=38)
> TT.points.in.classes(tri.data=soil_texture_df,
+                      class.sys="USDA.TT")
     Cl SiCl SaCl ClLo SiClLo SaClLo Lo SiLo SaLo Si LoSa Sa
[1,]  0    0    0    0      1      0  0    0    0  0    0  0
> class(soil_texture_df)
[1] "data.frame"

I just figured out the problem is that the code I had run originally is taking a single row from a data frame and sending it in, like this:

> soil_type_ar <- TT.points.in.classes(tri.data=soil_texture_df[1,],class.sys="USDA.TT")
> soil_type_ar
     Cl SiCl SaCl ClLo SiClLo SaClLo Lo SiLo SaLo Si LoSa Sa
>
> class(soil_texture_df[1,])
[1] "rowwise_df" "tbl_df"     "tbl"        "data.frame"

But you can see the class type is a "rowwise_df", which apparently the TT.points.in.classes doesn't recognize. If I cast it as a simple data frame, like this, it works:

>  soil_type_ar <- TT.points.in.classes(tri.data=as.data.frame(soil_texture_df[1,]),
+                                       class.sys="USDA.TT")
> soil_type_ar
     Cl SiCl SaCl ClLo SiClLo SaClLo Lo SiLo SaLo Si LoSa Sa
[1,]  0    0    0    0      1      0  0    0    0  0    0  0
> class(as.data.frame(soil_texture_df[1,]))
[1] "data.frame"

I appreciate your quick responses!