API Overview¶
This page covers the main public API for package users.
Recommended for Most Users: SoilTextureTriangle¶
from soiltextureplot.triangle import SoilTextureTriangle
Use this class when you want a simple, notebook-friendly workflow.
Example:
import pandas as pd
from soiltextureplot.triangle import SoilTextureTriangle
example_df = pd.DataFrame(
{
"sample_id": ["S1", "S2", "S3"],
"sand": [75, 65, 45],
"silt": [15, 20, 35],
"clay": [10, 15, 20],
"BD": [1.35, 1.42, 1.20],
}
)
tri = SoilTextureTriangle(system_name="USDA")
tri.load_dataframe(example_df)
classified = tri.classify()
fig, ax = tri.plot(size_by="BD", cmap="viridis")
Key methods:
load_csv(...): load from CSV and normalize texture column namesload_dataframe(...): load from pandas DataFrameclassify(): addtexture_classvalues to loaded dataplot(...): create the ternary plot figure
Advanced API (Lower-Level Building Blocks)¶
Use these when you want full control over classification and plotting internals.
get_texture_system(system_name)¶
Returns a TextureSystem definition used for classification and plotting.
- Accepted values:
"USDA","HYPRES" - Raises
ValueErrorfor unknown system names
PolygonClassifier¶
Classifies points into texture classes using polygon inclusion.
from soiltextureplot import PolygonClassifier, get_texture_system
system = get_texture_system("USDA")
classifier = PolygonClassifier.from_system(system)
labels = classifier.classify_points(
clay=df["clay"].to_numpy(),
sand=df["sand"].to_numpy(),
silt=df["silt"].to_numpy(),
)
If a point is outside known polygons, the classifier returns "Unknown" for that point.
plot_triangle_with_points(...)¶
Creates a ternary diagram with texture polygons and sample points.
Expected DataFrame columns:
- required:
clay,sand,silt - optional:
sample_id(for labels), plus anysize_bycolumn
Common options:
show_labels=Trueto draw sample labelssize_by,size_min,size_maxto scale point sizecmapto control class polygon colorscolor_pointsto control point colors
Example:
from soiltextureplot import get_texture_system, plot_triangle_with_points
system = get_texture_system("USDA")
fig, ax = plot_triangle_with_points(df=df, system=system, show_labels=True)
Advanced users can also import internal modules from soiltextureplot.* as needed.