Skip to main content

cropemu

PyPI Python Downloads Downloads/month License: MIT

Crop model simulations in a fraction of a millisecond, anywhere on the globe, without installing the crop models.

cropemu ships validated neural-network emulators of two widely used process-based crop models, DSSAT CROPGRO-Soybean and FAO AquaCrop. Give it the daily weather, the soil, the sowing date and the cultivar, and it returns the whole season: phenology dates, yield, biomass, evapotranspiration, water balance and stress indices. A season runs in about 0.1–0.2 ms (v2) or 10 µs (v1), against 0.05–1 s for the crop model, so you can simulate millions of seasons on a laptop: decades of weather × sowing dates × cultivars × climate scenarios, for one field or a whole region.

Every prediction says how far it can be trusted: each output carries an acceptance level from a spatial cross-validation, and every season is checked against the range of the training data.

Emulator Crop model Inputs Outputs
dssat-soybean-v2 DSSAT 4.8 CROPGRO-Soybean (official executable) weather (summaries and the daily series), soil, sowing date, maturity group and 13 cultivar coefficients, water regime, CO₂ 41
aquacrop-soybean-v2 FAO AquaCrop 7.3 (official executable) weather (summaries and the daily series), soil, sowing date, 13 crop parameters, water regime, CO₂ 44

The v2 emulators (0.4.0) read the daily weather of the season with a convolutional network, which cut the yield error on unseen regions from 454 to 335 kg/ha (DSSAT) and from 0.58 to 0.50 t/ha (AquaCrop); the development dates come from the mean of four dense networks. The v1 emulators (dense networks on weather summaries only) still ship for comparison.

Both were trained on ~118,000 seasons simulated with the official executables at ~2,000 points of the world's soybean area (NASA POWER weather, SoilGrids soils, GGCMI crop calendar, perturbed cultivars and climate). They ship inside the package (~3.3 MB each for v2) and need only numpy, pandas and onnxruntime.

No Python? The same emulators run in the browser in the CropEmu web app: one season, many years, sowing window, cultivars, climate scenarios and crop monitoring of the season in progress, anywhere in the world, with NASA POWER weather, SoilGrids soil or your own spreadsheets.

What's new in 0.4.0

  • v2 emulators dssat-soybean-v2 and aquacrop-soybean-v2: a 1-D convolutional network reads the daily weather from 30 days before to 170 days after sowing (temperature, radiation, rain, ETo, vapour pressure deficit, day length, a soil-water stress index), so it sees when heat, drought or rain happen in the cycle. Yield error on unseen regions: 454 → 335 kg/ha (DSSAT) and 0.58 → 0.50 t/ha (AquaCrop); lower in all eight world regions of the soybean area.
  • emu.inputs() keeps the daily series of each season and adds a sequence_id column; tables built from it (and prediction.inputs) can be edited and passed to predict_inputs, or pass sequence= (rows × channels × days) yourself. emu.uses_sequence and emu.weather_days_after tell what an emulator needs.
  • Weather must now cover 170 days after sowing for v2 (130 for v1).
  • The v1 emulators are still shipped; cropemu.load("dssat-soybean-v1") keeps old results reproducible.

What you can do with it

  • Sowing window: yield and risk for every sowing date × every year of the climate record.
  • Cultivar choice: compare maturity groups or cycle lengths at a site, or across a region.
  • Climate scenarios: warming, CO₂ and rain changes, as in the training design.
  • Water: rainfed vs. irrigated yield, the yield gap due to water.
  • Season monitoring: observed weather up to today, then each past year (or a forecast) for the rest of the cycle, to follow the expected yield and the yield gap during the season.
  • Regional maps: thousands of points × decades in seconds.
  • Your own data: station weather, measured soils, field trials from spreadsheets or DSSAT files.
  • Calibration: fit cultivar parameters to your observations by trying thousands of candidates in seconds.
  • Sensitivity analysis and screening before running the full crop model where it matters.

Source, example notebooks and issues: https://github.com/fcoliveira-utfpr/emulator_crop.

Install

pip install cropemu            # emulators + NASA POWER weather + readers of your own data
pip install "cropemu[soil]"    # + SoilGrids soil profiles anywhere (rasterio)

Python ≥ 3.10. On Intel Macs, add --prefer-binary (the newest rasterio has no wheel for them).

Quick start: any point of the globe

import cropemu
from cropemu.weather import fetch, fill_gaps
from cropemu.soil import soilgrids

lat, lon = -23.19, -51.18                                          # Londrina, Brazil
weather = fill_gaps(fetch(lat, lon, "2000-01-01", "2024-12-31"))   # NASA POWER, downloaded once
soil = soilgrids.fetch(lat, lon)                                   # SoilGrids 2.0, downloaded once

emu = cropemu.load("dssat-soybean-v2")                             # cropemu.available() lists them
emu.describe()                                                     # outputs, units, validation error, level

res = emu.predict(weather, lat=lat, elev=600, soil=soil,
                  sowing=["2020-10-15", "2021-10-15", "2022-10-15"],
                  cultivar=emu.cultivar(mg=6.5))                   # default coefficients of MG 6.5
res.outputs[["ADAT_dap", "MDAT_dap", "HWAM", "ETCM"]]              # flowering, maturity (days after sowing), yield (kg/ha), ET (mm)
res.recommended("caution")                                         # only the outputs that passed validation
res.out_of_domain, res.rare_inputs                                 # inputs outside the training data

Scenarios and water regime: emu.predict(..., dt=2.0, co2=550, rain_factor=0.9, irrigated=True).

Your own data

Spreadsheets (CSV or Excel; English or Portuguese headers; units in parentheses):

from cropemu.io import write_templates, read_sites, read_weather, read_soils, read_seasons

write_templates("my_data", lang="pt")        # locais, clima, solo, safras ("en": sites, weather, soil, seasons)
sites = read_sites("my_data/locais.csv")     # name, lat, lon, elevation
weather = read_weather("my_data/clima.csv", lat=-24.5, lon=-51.6, elev=600)
soils = read_soils("my_data/solo.csv")       # {profile: layers}; measured wilting point / field capacity are used as given
seasons = read_seasons("my_data/safras.csv") # farm, field, sowing, cultivar, irrigated, observed yield and dates

Column names such as Chuva (mm), Argila (g/kg) or MO (%) are recognised, and common unit mistakes (radiation in W/m², humidity as a fraction, texture in g/kg, organic matter instead of carbon) are converted with a warning.

Filling the gaps: cropemu.weather.fill_from(station, power) completes a station with NASA POWER; cropemu.soil.fill_from(profile, soilgrids.fetch(lat, lon)) completes a profile with SoilGrids.

DSSAT files: cropemu.io reads weather (read_wth), soil (read_sol), cultivar (read_cul), experiment (read_experiment) and observed data (read_observed):

from cropemu.io import read_cul
cultivar = emu.cultivar_from_dssat(read_cul("SBGRO048.CUL", "IB0001"))
emu.cultivar_domain(cultivar)                # where each coefficient sits in the training range

AquaCrop cycle from an observed season: aq.cultivar(gdd_maturity=cropemu.gdd_between(weather, sowing, maturity)).

Calibration in seconds

The inputs of every season are computed once; a candidate cultivar only changes the cultivar columns and runs the network:

import numpy as np
dates = [f"{y}-10-15" for y in range(2000, 2024)]
X = emu.inputs(weather, lat=lat, elev=600, soil=soil, sowing=dates, cultivar=emu.cultivar(mg=6))
grid = [emu.cultivar(mg=m, LFMAX=l) for m in np.arange(5, 8, 0.05) for l in np.linspace(1.0, 1.18, 10)]
pred = [emu.predict_inputs(X.assign(**c)).outputs["HWAM"] for c in grid]   # pick the best against your yields

600 candidates × 24 seasons take a few seconds; stacking the candidates in one table (pd.concat) and calling predict_inputs once is faster still.

How far to trust a prediction

Validation: 5-fold cross-validation by 5° spatial blocks (the emulator never saw the region it is tested on), against the crop model:

Maturity date Yield Evapotranspiration
Maturity date Yield Evapotranspiration
--- --- --- ---
dssat-soybean-v2 3.1 d (R² 0.98) 335 kg/ha (R² 0.97) 23 mm (R² 0.98)
aquacrop-soybean-v2 4.3 d (R² 0.99) 0.50 t/ha (R² 0.93) 45 mm (R² 0.93)
dssat-soybean-v1 3.3 d (R² 0.98) 454 kg/ha (R² 0.94) 32 mm (R² 0.96)
aquacrop-soybean-v1 4.4 d (R² 0.99) 0.58 t/ha (R² 0.91) 52 mm (R² 0.90)

By world region, the v2 yield error ranges from 223 kg/ha (Europe and Central Asia) to 439 kg/ha (North America) for DSSAT and from 0.38 to 0.59 t/ha for AquaCrop. At 7 sites outside the training data (Brazil, Argentina, USA, China), the v2 yield error against new runs of the crop models was 224 kg/ha (DSSAT) and 0.33 t/ha (AquaCrop), about half of the values above.

  • Acceptance level of every output (emu.describe(), res.levels):
    • recommended: dates with RMSE ≤ 5 days, other outputs with RMSE < 0.25 of the within-site standard deviation;
    • caution: relative error < 0.5;
    • not recommended: everything else.
  • out_of_domain: inputs outside the range of the training data. The prediction is an extrapolation; do not trust it.
  • rare_inputs: inputs outside the 0.5–99.5 % range of the training data. Trust it less.

Inputs, as in training

  • Weather: daily radiation, Tmax, Tmin, rain (humidity and wind optional), summarised in windows from 30 days before to 130 days after sowing; the v2 emulators also read the daily series up to 170 days after sowing.
  • Soil: profile to 2 m. Water retention, unless measured: Reichert et al. (2009), field capacity at 10 kPa, up to 30° latitude; Saxton & Rawls (2006) from 40°; a linear blend in between.
  • Cultivar: DSSAT coefficients around the defaults of each maturity group; AquaCrop crop parameters within their usual ranges and a cycle (growing degrees) fitted to the local calendar.
  • Fixed in training: 30 plants/m², 50 cm rows, no nitrogen stress, half of the available water 30 days before sowing.

Limitations

  • An emulator reproduces its crop model, not the field: errors of the crop model are inherited, and the crop models were not calibrated for each site.
  • Plant density, row spacing, nitrogen, pests and diseases are not inputs.
  • Soybean only for now; maize is planned.
  • Alpha: output names follow the crop models and the API may still change.

License and data

MIT. Training data: NASA POWER, SoilGrids 2.0 (ISRIC, CC-BY 4.0), GGCMI Phase 3 crop calendar; crop models: DSSAT (BSD-3) and FAO AquaCrop 7.3. cropemu is not affiliated with the DSSAT Foundation or FAO.

A paper describing the emulators, their validation by world region and the web app is in preparation; until then, please cite the package and its version.

Metadata

Release files for cropemu 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cropemu 0.4.0
File Size Uploaded Provenance Actions
cropemu-0.4.0.tar.gz 8.7 MB Without provenance Details for cropemu-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cropemu 0.4.0
File Interpreter ABI Platform Actions
cropemu-0.4.0-py3-none-any.whl Python 3 none any Details for cropemu-0.4.0-py3-none-any.whl

Total release size: 17.5 MB

Release files / cropemu-0.4.0.tar.gz

Download URL cropemu-0.4.0.tar.gz
Size 8.7 MB
Tags Source
SHA-256 checksum
How to use checksums
f716b69f0939d56768fd0d79c63c4e73ea08b4ba0f99f2d9385da571a2ef9cda
BLAKE2b-256 checksum
How to use checksums
eab85de58a1d337eea0a7afd29a32bc002ff6b3c695aa4b122e9087e8f98131d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.13

Release files / cropemu-0.4.0-py3-none-any.whl

Download URL cropemu-0.4.0-py3-none-any.whl
Size 8.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
bbb152284784b322833ed2777a3a7cfb563be1472f5f8a3e8ee0b6f2d1bb5da3
BLAKE2b-256 checksum
How to use checksums
79ed564a1020c01228ec3e27361aa0fad9079afe4e5e9a30ff18f4f21f7428d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.13

Security for cropemu 0.4.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page