Sample code for optimizing water retention curves
Easiest way to start learning how to use unsatfit is to run sample codes as instructed in this page. You can optimize parameters of WRF (water retention function)of various available models to measured data set. You can test with sample data provided in this page. SWRC Fit can also be used. For optimizing HCF (hydraulic conductivity function) also, please refer to this page.
- Install Python 3 and unsatfit. Install pandas by
python -m pip install pandas
.
- Prepare datafile as csv (comma-separated values) format for (h, θ) data in the filename “swrc.csv” with a header of “h, theta”. See sample data of Gilat loam.
- Download a sample code for the model that you select from below.
- Run the sample code at the same directory with the data file (swrc.csv). For running the code on Mac or unix-like system, edit the first line (shebang) and mark the file executable by
chmod +x VG.py
. For running on Windows, please refer to Python on Windows FAQ.
- Fitted parameters are shown at the standard output, where qs and qr means θs and θr respectively. Statistics are also shown.
- Note that the program is unit independent, meaning that the unit of the parameters depends on the unit of the input data. Unit of pressure head is assumed as cm for a (cm-1) and hb.
- Figure files are produced as png files. For use in papers, pdf files can be produced as instructed in the sample code. To change the appearance of a figure, edit the figure settings in the sample code. For more figure options, see the source code of unsatfit.
List of sample codes
Multiple curves


UNSODA data
Here are sample codes to draw multiple fitting curves for the UNSODA database and figures which were produced with the code.
Method
- The code reads laboratory drying curves of UNSODA data from a JSON converted file.
- θr is fitted for VG and KO models, and θr = 0 for other models.
- Upper limits are imposed for θs / max(θ) = 1.5 and n1, n2 = 8, along with a lower limit of σ2 = 0.2.
- The generated PDF files are concatenated using this script.
- With the UNSODA viewer, you can select a specific soil sample and send data directly to SWRC Fit by clicking the link labeled “Fit with various water retention models”.