Package: soilFlux 0.1.5

soilFlux: Physics-Informed Neural Networks for Soil Water Retention Curves

Implements a physics-informed one-dimensional convolutional neural network (CNN1D-PINN) for estimating the complete soil water retention curve (SWRC) as a continuous function of matric potential, from soil texture, organic carbon, bulk density, and depth. The network architecture ensures strict monotonic decrease of volumetric water content with increasing suction by construction, through cumulative integration of non-negative slope outputs (monotone integral architecture). Four physics-based residual constraints adapted from Norouzi et al. (2025) <doi:10.1029/2024WR038149> are embedded in the loss function: (S1) linearity at the dry end (pF in [5, 7.6]); (S2) non-negativity at pF = 6.2; (S3) non-positivity at pF = 7.6; and (S4) a near-zero derivative in the saturated plateau region (pF in [-2, -0.3]). Includes tools for data preparation, model training, dense prediction, performance metrics, texture classification, and publication-quality visualisation.

Authors:Hugo Rodrigues [aut, cre]

soilFlux_0.1.5.tar.gz
soilFlux_0.1.5.zip(r-4.7-any)soilFlux_0.1.5.zip(r-4.6-any)soilFlux_0.1.5.zip(r-4.5-any)
soilFlux_0.1.5.tgz(r-4.6-any)soilFlux_0.1.5.tgz(r-4.5-any)
soilFlux_0.1.5.tar.gz(r-4.7-any)soilFlux_0.1.5.tar.gz(r-4.6-any)
soilFlux_0.1.5.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION
card.svg |card.png
soilFlux/json (API)

# Install 'soilFlux' in R:
install.packages('soilFlux', repos = c('https://hugomachadorodrigues.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/hugomachadorodrigues/soilflux/issues

Pkgdown/docs site:https://hugomachadorodrigues.github.io

Datasets:

On CRAN:

Conda:

4.78 score 2 stars 7 scripts 504 downloads 36 exports 50 dependencies

Last updated from:12219c6da4. Checks:7 NOTE, 2 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64NOTE189
source / vignettesOK209
linux-release-x86_64NOTE183
macos-release-arm64NOTE126
macos-oldrel-arm64NOTE108
windows-develNOTE116
windows-releaseNOTE117
windows-oldrelNOTE172
wasm-releaseOK151

Exports:add_textureapply_minmaxbuild_residual_setsbuild_swrc_modelclassify_texturecompute_physics_lossevaluate_swrcfit_minmaxfit_swrcfix_bd_unitshead_from_pfhead_normalizeinvert_minmaxload_swrc_modelmake_obs_matricesmake_profile_arraynorouzi_lambdasparse_depthparse_depth_columnpf_from_headpf_normalizeplot_pred_obsplot_swrcplot_swrc_metricsplot_training_historypredict_swrcpredict_swrc_densepredict_theta_sprepare_swrc_dataresidual_to_tensorssave_swrc_modelswrc_metricsswrc_metrics_by_groupswrc_model_existstexture_triangletheta_unit_factor

Dependencies:backportsbase64enccliconfigcpp11dplyrfarvergenericsggplot2gluegtablehereisobandjsonlitelabelinglatticelifecyclemagrittrMatrixpillarpkgconfigpngprocessxpspurrrR6rappdirsRColorBrewerRcppRcppTOMLreticulaterlangrprojrootrstudioapiS7scalesstringistringrtensorflowtfautographtfrunstibbletidyrtidyselectutf8vctrsviridisLitewhiskerwithryaml

Pedometric Workflow: KSSL Data, Spline Harmonisation, and SWRC Fitting
Why harmonise horizons? | Required packages | The mass-preserving spline — illustrated | Fetching KSSL data — North Carolina | Horizon table structure | Visualise raw profiles with aqp | Mass-preserving spline harmonisation on KSSL | Prepare input for mpspline2 | Apply splines profile-by-profile | Compare raw vs. splined: one profile | Exploring the harmonised dataset | Distribution of soil properties by depth | Observed retention curves by depth | Texture triangle | Reshaping water retention and preparing for soilFlux | Fitting the soilFlux model | Train / validation / test split | Fit | Visualising predictions | Full SWRC curves — depth × texture | Predicted vs. observed scatter | Vertical profile — FC and WP at standard depths | Exporting the continuous SWRC data | Save and reload the model | Summary | References

Last update: 2026-03-23
Started: 2026-03-22

Introduction to soilFlux
Overview | What is the SWRC? | Key features | Quick-start | Installation | Minimal example | Data preparation | Expected columns | Unit handling | Model architecture | Monotone integral layer | Inputs to the model | Physics constraints | Saving and loading models | Visualisation | SWRC curves | Predicted vs. observed | Training history | Texture classification | Session information | References

Last update: 2026-03-13
Started: 2026-03-12

Readme and manuals

Help Manual

Help pageTopics
Add texture classification column to a data frameadd_texture
Apply a fitted min-max scaler to a data frameapply_minmax
Build physics residual point sets (S1 – S4)build_residual_sets
Build the CNN1D monotone-integral SWRC modelbuild_swrc_model
Classify soil texture according to the USDA systemclassify_texture
Data preparation for CNN1D SWRC modellingdata_prep
Compute metrics from a swrc_fit on new dataevaluate_swrc
Fit a min-max scaler from a training data framefit_minmax
Fit a physics-informed CNN1D SWRC modelfit_swrc
Detect and correct bulk-density unitsfix_bd_units
Convert pF to matric head (cm)head_from_pf
Normalise matric head (cm) to the pF domainhead_normalize
Invert a min-max scaling transformationinvert_minmax
Save and load fitted SWRC modelsio
Load a previously saved SWRC model from diskload_swrc_model
Performance metrics for SWRC modelsmetrics
CNN1D monotone-integral model architecturemodel
Return default Norouzi et al. (2025) loss weights (lambdas)norouzi_lambdas
Parse a soil depth string into midpoint and labelparse_depth
Parse depth column in a data frameparse_depth_column
Convert matric head (cm) to pFpf_from_head
Normalise pF values to [0, 1]pf_normalize
Physics-informed constraints for SWRC modellingphysics
Plot predicted vs. observed water contentplot_pred_obs
Plot soil water retention curves (SWRC)plot_swrc
Plot model performance metric comparisonplot_swrc_metrics
Plot training loss historyplot_training_history
Publication-quality plots for SWRC analysisplots
Prediction from fitted SWRC modelspredict
Predict water content at specific pF or matric-head valuespredict_swrc
Predict dense SWRC curves for a set of soil profilespredict_swrc_dense
Extract saturated water content (theta_s) from covariatespredict_theta_s
Predict method for swrc_fitpredict.swrc_fit
Prepare a soil data frame for SWRC modellingprepare_swrc_data
Print method for swrc_fitprint.swrc_fit
Save a fitted SWRC model to disksave_swrc_model
Min-max feature scalingscale
Summary method for swrc_fitsummary.swrc_fit
Example soil water retention datasetswrc_example
Compute regression metrics for SWRC predictionsswrc_metrics
Compute regression metrics by groupswrc_metrics_by_group
Check whether a model directory contains a valid saved modelswrc_model_exists
USDA soil texture classificationtexture
Plot a USDA soil texture triangle (ternary diagram)texture_triangle
Detect theta unit scale factortheta_unit_factor
Training the CNN1D SWRC modeltrain
Utility functions for soilFluxutils