API Reference¶
Core Models¶
Soil profile model representing a vertical arrangement of soil layers.
SoilProfile
¶
Bases: BaseModel
A soil profile composed of layers with spatial information.
Source code in simplesoilprofile/models/profile.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
layer_bounds
property
¶
Get dictionary of (top, bottom) bounds for each layer.
profile_depth
property
¶
Total depth of the profile in cm (bottom of last layer).
get_layer_at_depth(depth)
¶
Get the soil layer at a specific depth.
Source code in simplesoilprofile/models/profile.py
62 63 64 65 66 67 68 69 | |
get_sublayer_boundaries()
¶
Get all sublayer boundaries for each layer in the profile.
Source code in simplesoilprofile/models/profile.py
71 72 73 74 75 76 77 78 | |
get_sublayer_depths()
¶
Get a sorted list of all sublayer boundary depths in the profile.
Source code in simplesoilprofile/models/profile.py
80 81 82 83 84 85 | |
validate_layer_depths()
¶
Validate that layer depths are consistent and monotonically increasing.
Source code in simplesoilprofile/models/profile.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
get_profile_from_dov(location, fetch_elevation=False, crs='EPSG:31370')
¶
Fetch a soil profile from DOV WMS at a specific location.
This function queries the DOV WMS service for soil texture data at the given location and constructs a SoilProfile object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Point
|
Shapely Point representing the location (x, y coordinates) |
required |
fetch_elevation
|
bool
|
Whether to fetch elevation data for the profile surface |
False
|
crs
|
str
|
Coordinate reference system of the input location |
'EPSG:31370'
|
Returns:
| Type | Description |
|---|---|
SoilProfile | None
|
SoilProfile object or None if data not found |
Source code in simplesoilprofile/models/profile.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
Soil layer model representing a single layer with physical properties.
SoilLayer
¶
Bases: BaseModel
A soil layer with uniform properties.
This class represents a soil layer with van Genuchten parameters and other properties needed for hydrological modeling, particularly for SWAP model integration. The layer can be discretized into sublayers for numerical computation.
Source code in simplesoilprofile/models/layer.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
sum_texture
property
¶
Compute the sum of clay, silt, and sand contents if all are provided.
get_sublayer_boundaries(top, bottom)
¶
Get the sublayer boundary depths for this layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top
|
float
|
Top depth of the layer [cm] |
required |
bottom
|
float
|
Bottom depth of the layer [cm] |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of boundary depths [cm], including top and bottom depths. |
list[float]
|
If no discretization is configured, returns [top, bottom]. |
Source code in simplesoilprofile/models/layer.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
infer_fractions_from_texture(texture_class)
¶
Add sand/silt/clay percentages to a SoilLayer based on texture class.
Parameters¶
layer : SoilLayer Soil layer to enrich texture_class : str Texture class name from field observations
Returns¶
SoilLayer Updated layer with estimated percentages
Source code in simplesoilprofile/models/layer.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
normalize_soil_fractions(tolerance=2.0)
¶
Normalize soil texture fractions to sum to 100%.
Parameters¶
sand, silt, clay : float Soil fraction percentages tolerance : float Maximum acceptable deviation from 100% before normalization (default: 2%)
Returns¶
tuple[float, float, float] Normalized (sand, silt, clay) percentages
Examples¶
normalize_soil_fractions(72.97, 22.44, 3.61) (73.76, 22.68, 3.65) # Sum was 99.02, now 100.0
Source code in simplesoilprofile/models/layer.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
predict_van_genuchten(method)
¶
Predict van Genuchten parameters from soil texture.
Source code in simplesoilprofile/models/layer.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
validate_water_contents()
¶
Validate that residual water content is less than saturated water content.
Source code in simplesoilprofile/models/layer.py
55 56 57 58 59 60 61 62 63 | |
Layer discretization models and utilities.
DiscretizationType
¶
Bases: str, Enum
Types of layer discretization methods.
Source code in simplesoilprofile/models/discretization.py
9 10 11 12 13 14 15 | |
LayerDiscretization
¶
Bases: BaseModel
Configuration for layer discretization.
Source code in simplesoilprofile/models/discretization.py
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 | |
compartment_heights
property
¶
Get the ordered list of compartment heights for this discretization.
The heights are calculated based on the discretization type and parameters. The order is from top to bottom of the layer.
Returns:
| Type | Description |
|---|---|
list[float]
|
List of compartment heights [cm] in order from top to bottom. |
list[float]
|
For EVEN discretization, all heights are equal. |
list[float]
|
For logarithmic discretizations, heights vary according to the spacing function. |
validate_discretization()
¶
Validate discretization parameters.
Source code in simplesoilprofile/models/discretization.py
40 41 42 43 44 45 | |
compute_sublayer_boundaries(top, bottom, discretization)
¶
Compute sublayer boundaries based on discretization configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top
|
float
|
Top depth of the layer [cm] |
required |
bottom
|
float
|
Bottom depth of the layer [cm] |
required |
discretization
|
LayerDiscretization
|
Discretization configuration |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of boundary depths [cm], including top and bottom |
Source code in simplesoilprofile/models/discretization.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
SoilLayerMetadata
¶
Bases: BaseModel
Metadata describing the source and quality of a measurement.
This class captures provenance information for soil measurements, following best practices for scientific data traceability and reproducibility.
Source code in simplesoilprofile/models/metadata.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
Plotting¶
Plotting utilities for visualizing soil profiles.
plot_profile(profile, ax=None, figsize=(8, 12), texture_colors=None, show_depths=True, show_layer_properties=True, show_sublayers=True)
¶
Plot a soil profile showing layers and their properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
SoilProfile
|
The soil profile to plot |
required |
ax
|
Axes | None
|
Optional matplotlib axes to plot on |
None
|
figsize
|
tuple[float, float]
|
Figure size (width, height) if creating new figure |
(8, 12)
|
texture_colors
|
dict[str, str] | None
|
Optional mapping of texture classes to colors |
None
|
show_depths
|
bool
|
Whether to show depth labels |
True
|
show_properties
|
Whether to show soil properties in annotations |
required | |
show_sublayers
|
bool
|
Whether to show sublayer boundaries for discretized layers |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
The matplotlib axes object containing the plot |
Source code in simplesoilprofile/plotting/profile_plot.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
SWAP Integration¶
Utilities for generating SWAP model input files from soil profiles.
profile_to_soilhydfunc_table(profile)
¶
Convert a SoilProfile to a SWAP-compatible SOILHYDRFUNC table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
SoilProfile
|
The soil profile to convert |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the SOILHYDRFUNC table with any column that contains |
DataFrame
|
None/NaN values removed. |
Source code in simplesoilprofile/models/swap.py
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 | |
profile_to_sublayer_table(profile)
¶
Convert a SoilProfile to a DataFrame representing sublayers and compartments.
Source code in simplesoilprofile/models/swap.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
profile_to_texture_table(profile)
¶
Convert a SoilProfile to a SWAP-compatible SOILTEXTURE table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
SoilProfile
|
The soil profile to convert |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the SOILTEXTURE table. |
Source code in simplesoilprofile/models/swap.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Texture Conversion¶
SoilTextureConverter
¶
Convert between soil texture class names and sand/silt/clay percentages.
Uses USDA classification data loaded from YAML configuration file.
Source code in simplesoilprofile/models/texture_conversion.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
__init__(config_path='usda_texture_data.yaml')
¶
Initialize with YAML configuration file.
Parameters¶
config_path : str Path to YAML configuration file
Source code in simplesoilprofile/models/texture_conversion.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
class_to_percentages(texture_class, method='centroid', normalize=True)
¶
Convert texture class name to sand/silt/clay percentages.
Parameters¶
texture_class : str Soil texture class name (e.g., 'silty sand', 'sandy loam') method : str 'centroid' for geometric centroid or 'mean' for statistical mean normalize : bool Whether to normalize to sum to 100%
Returns¶
tuple[float, float, float] (sand, silt, clay) percentages
Examples¶
converter = SoilTextureConverter() sand, silt, clay = converter.class_to_percentages('loamy sand') print(f"Sand: {sand}%, Silt: {silt}%, Clay: {clay}%") Sand: 82.0%, Silt: 12.0%, Clay: 6.0%
Source code in simplesoilprofile/models/texture_conversion.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
get_metadata()
¶
Get metadata about the classification system.
Source code in simplesoilprofile/models/texture_conversion.py
129 130 131 | |
get_ranges(texture_class)
¶
Get statistical ranges for a texture class.
Parameters¶
texture_class : str Soil texture class name
Returns¶
dict Dictionary with mean, min, max, std for each fraction
Source code in simplesoilprofile/models/texture_conversion.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
list_available_classes()
¶
List all available texture classes.
Source code in simplesoilprofile/models/texture_conversion.py
133 134 135 | |