dssatlab
dssatlab aims to be a Python interface to the DSSAT-CSM. The goal is to let users work with DSSAT from Python and use the wider Python ecosystem (data, analysis, plotting, notebooks) to make DSSAT easier and more powerful to use.
Installation
pip install dssatlab
Requires Python 3.10 or newer. To upgrade later: pip install --upgrade dssatlab. To include plotting support: pip install dssatlab[plot].
Current stage
The project can get a working DSSAT into Python, run an existing experiment file, run a simulation from your own weather, soil, and management data, and read and plot the results. This part is done:
- Find an existing DSSAT-CSM installation on Windows and Linux (including Google Colab)
- Build DSSAT-CSM from the official release on Linux and Colab
- Run one existing FileX
- Turn your own daily weather into a strictly checked simulation and run it
- Turn your own soil data into a strictly checked simulation and run it
- Turn your own management data (planting, irrigation, fertilizer) into a strictly checked simulation and run it
- Run all or selected FileX treatments and what-if scenarios in separate folders, and combine their summaries
- Read five DSSAT output files (
Summary.OUT,PlantGro.OUT,SoilWat.OUT,PlantN.OUT,Weather.OUT) and plot plant growth
import dssatlab as dl
dssat = dl.connect() # path to the DSSAT executable
result = dl.run("UFGA8201.MZX") # all treatments
result = dl.run("UFGA8201.MZX", treatment=2) # one treatment
print(result.run_dir, result.outputs)
How a run works:
- DSSAT runs in the FileX's own folder, so weather and soil files beside the FileX are found. Its output files are then moved into a new
dssat_run_<date>folder beside the FileX, and your FileX folder is left as it was. - The FileX filename can be at most 12 characters, including the extension (DSSAT's own limit), for example
UFGA8201.MZX. - A failed run raises
DSSATRunErrorwith the command, the end of DSSAT's console output and the start ofERROR.OUT. The run folder is kept so you can look inside. run()returns the files DSSAT wrote. Read outputs withresult.summary(),result.plant_growth(),result.soil_water(),result.plant_nitrogen(), andresult.weather(), or plot withresult.plot(variable). Building experiments from Python is not built yet.
Upgrading from 0.1.x on Linux or Colab: a DSSAT built by 0.1.x cannot run simulations, so the first dl.install() (or dl.connect() with consent) rebuilds it once.
Your own weather, soil, and management data
Put your daily weather in the fixed weather template, optionally your soil profile in the soil template, and optionally your operations in the management template (or a plain dictionary), then create a Simulation for one treatment of an existing FileX:
import dssatlab as dl
dl.write_weather_template("weather.csv") # a correct weather example
dl.write_soil_template("soil.csv") # a valid 3-layer soil profile
dl.write_management_template("management.yaml") # a commented management template
sim = dl.Simulation(
"UFGA8201.MZX",
treatment=1,
weather="weather.csv",
soil="soil.csv",
management="management.yaml",
)
problems = sim.check() # every problem at once, nothing is written; [] means fine
result = sim.run() # checks first, then writes files and runs DSSAT
No FileX yet? For maize or wheat, write one from a FileX template instead. Station, coordinates and elevation come from your weather data, and the soil ID from your soil data:
dl.write_filex_template("filex.yaml") # crop, treatment name, cultivar, planting
sim = dl.Simulation(filex_template="filex.yaml", weather="weather.csv", soil="soil.csv")
Values are in DSSAT's own units and nothing is converted:
- Weather template: comma-separated UTF-8 CSV with
station,latitude,longitude,elevation,date(YYYY-MM-DD),srad,tmax,tmin,rain, and optionaltav,amp,refht,wndht(default -99). Station and coordinates repeat on every row; one row per calendar day without gaps or duplicates. - Soil template: one soil profile, one row per layer. Required profile columns:
soil_id(1 to 10 ASCII characters matching the FileXID_SOIL),salb,slro,sldr,slpf. Required layer columns:slb(cm, strictly increasing),slll,sdul,ssat(strictlyslll < sdul < ssat),srgf. Optional columns (slnf,ssks,sbdm,sloc, etc.) default to -99. Profile values repeat identically on every row. - Management template: YAML file or Python dict organized under
treatments -> {treatment_number: ...}with optionalplanting,irrigation,fertilizer,cultivar,initial_conditions, andcontrolssections (dl.write_experiment_template()writes a commented file covering all six; the last three are checked and applied to a copy of your FileX, see the Guide). All dates must be quoted ISO strings ("YYYY-MM-DD"). Omitted sections keep the FileX's original levels; empty lists ([]) specify no events (level 0). PyYAML is optional (pip install pyyamlorpip install dssatlab[yaml]) and only imported when loading a YAML path; plain dictionaries require zero runtime dependencies.
Inputs for weather and soil can be given as a CSV path, a list of dicts, or a pandas DataFrame (pandas is never required). Management can be given as a YAML path or a plain dictionary.
What happens:
check()reports every problem it finds: wrong or unknown columns/keys, empty or non-numeric values, bad dates or depths, gaps, impossible values (e.g.tmax < tmin, negative rain, non-increasing depths, water limits out of order, non-ascending event dates), and mismatches with the FileX (station code, start date coverage, case-sensitivesoil_idmatch, planting date before start date). Nothing is fixed or filled in automatically. When management is supplied, a structured Checks report is printed.run()raises oneDSSATCheckErrorlisting all problems if there are any, before writing anything.- Otherwise
run()makes a newdssat_sim_<date>folder beside your FileX. Withsoil, it writesSOIL.SOLand does not copy sibling.SOLfiles (a local.SOLbeats DSSAT's own Soil folder);.CUL,.ECO, and.SPEfiles are copied as before. Withoutsoil, sibling.SOLfiles are copied. Withmanagement, it edits the copied FileX to append new management levels and repoints the selected treatment row. The generated weather file is written to the simulation folder, DSSAT runs there, and output files are collected into adssat_run_<date>folder inside it. Your original files are never changed. - If DSSAT cannot use the soil profile, it exits with return code 99 and
run()raisesDSSATRunErrorwith theERROR.OUTmessage. - DSSAT does not fail when weather is missing: it exits normally and gives -99 results. After the run,
run()looks for DSSAT's "weather record not found" warning and raisesDSSATRunErrornaming the first missing date.
Not built yet: other management operations (tillage, organic amendments, harvest, chemicals), unit converters, reading other output files (such as ET.OUT or OVERVIEW.OUT), choosing a soil profile from DSSAT's own soil files, a FileX with more than one field, treatment or crop (maize and wheat are supported), and parallel or resumed runs.
Multi-treatment and scenario runs
Real studies often compare all treatments of an experiment or test what-if scenarios.
run_treatments() runs all treatments (or a selected subset) across named scenarios in a
single call:
import dssatlab as dl
# Generate a scenario template pre-filled with treatment numbers from the FileX:
dl.write_scenario_template("scenarios.yaml", filex="UFGA8201.MZX")
# Run treatments across scenarios:
results = dl.run_treatments(
"UFGA8201.MZX",
weather="weather.csv",
treatments=[1, 3],
scenarios="scenarios.yaml",
)
# Access a specific run (keyed by (scenario, treatment)):
result = results["base", 1]
# Combine all summaries into a single table:
combined = dl.combine_summaries(results)
df = dl.to_dataframe(combined)
How multi-treatment and scenario runs work:
- By default (
treatments=None), runs all treatments in the FileX; pass a list (e.g.treatments=[1, 3]) to select a subset. - Each
(scenario, treatment)simulation runs in its own dated folder beside the FileX (dssat_sim_<date>). - Scenarios are defined in a YAML file or plain dictionary. Allowed overrides:
weather,soil,management. Overrides replace the whole input without partial merging. The baseline un-overridden run is always included as"base". - Every weather input must match the station code of
WSTAfor all selected treatments. - All scenario and treatment inputs are verified before any run; a single
DSSATCheckErrorlists all problems across all scenarios and treatments. - A failed run halts execution immediately and reports all completed run directories kept on disk.
Reading results
Read outputs directly from a run result or any run directory:
import dssatlab as dl
# After a run:
summary_rows = result.summary() # one dict per simulation (Summary.OUT)
growth_rows = result.plant_growth() # daily crop development (PlantGro.OUT)
water_rows = result.soil_water() # daily soil water by layer (SoilWat.OUT)
nitro_rows = result.plant_nitrogen() # daily nitrogen uptake (PlantN.OUT)
weather_rows = result.weather() # daily weather as DSSAT saw it (Weather.OUT)
# Convert to a pandas DataFrame (pandas is optional):
df = dl.to_dataframe(growth_rows)
# Plot plant growth against date (requires pip install dssatlab[plot]):
ax = result.plot("LAID") # leaf area index over time
# Compare treatments across run directories:
ax = dl.plot_plant_growth([run_dir_rainfed, run_dir_irrigated], "LAID")
Dates are parsed into datetime.date objects, DSSAT's -99 missing values become None, and column names match DSSAT's own (HWAM, ADAT, LAID, SWTD, NUPC). Five output files are parsed (Summary.OUT, PlantGro.OUT, SoilWat.OUT, PlantN.OUT, and Weather.OUT); other output files remain listed in result.outputs.
Compare with your measurements
Put your observed data in a commented CSV template, using DSSAT's column names and
units. Compare it with one run result or the dictionary from run_treatments():
dl.write_observed_template("observed.csv")
# Replace the example rows with your observed data before continuing.
ev = dl.evaluate(result, "observed.csv")
print(ev.pairs)
print(ev.statistics)
dl.plot_evaluation(ev, variable="HWAM"); # requires dssatlab[plot]
Rows use scenario (base for one run) and treatment. Leave date blank for
Summary values such as HWAM; use yyyy-mm-dd for Plant growth measurements on a
day and for Summary date values such as ADAT. Evaluation reports simulated minus
observed errors, plus RMSE, mean bias and Willmott's d-index for variables with at
least two pairs. Observed data and matching problems are reported in one
DSSATCheckError. See the evaluation guide.
Metadata
Release files for dssatlab 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dssatlab-0.8.0.tar.gz | 144.4 kB | With provenance | Details for dssatlab-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dssatlab-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for dssatlab-0.8.0-py3-none-any.whl |
Total release size: 219.3 kB
Release files / dssatlab-0.8.0.tar.gz
| Download URL | dssatlab-0.8.0.tar.gz |
|---|---|
| Size | 144.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24fc4a1ce1d62e3ce284e8ed51912818f90e34da236f31f60a0cf38058c52235
|
|
BLAKE2b-256 checksum How to use checksums |
a2f34a738f26f791cabdd9647c66820d6ee1f35ddd97b5d9a413ec28e34a522d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / dssatlab-0.8.0-py3-none-any.whl
| Download URL | dssatlab-0.8.0-py3-none-any.whl |
|---|---|
| Size | 74.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a80f356df525a5afa4d045b789e5f4e8dc5c2a3b5c9de56933b1f8800346af7
|
|
BLAKE2b-256 checksum How to use checksums |
0acc5c60a672fb6b6c7669031b8489ee032011c57e4a38f1daaa6af41adac8f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logSecurity for dssatlab 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dssatlab-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.