This repository is evolving into an SDK and CLI for crop-yield inference on CY-BENCH-compatible data. It can also still be used for model training and evaluation.
This is the recommended end-user flow today.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .The model repositories are private for now. Put a read token in .env:
HF_TOKEN=your_token_here
HUGGINGFACE_HUB_TOKEN=your_token_hereYou can use the same token value for both variables.
For local development, the simplest setup is:
YIELD-HUB/
├── data/
│ ├── maize/
│ │ └── NL/
│ └── wheat/
For a given crop and country, the target folder must contain:
data/<crop>/<country>/
├── crop_calendar_<crop>_<country>.csv
├── fpar_<crop>_<country>.csv
├── location_<crop>_<country>.csv
├── meteo_<crop>_<country>.csv
├── ndvi_<crop>_<country>.csv
├── soil_<crop>_<country>.csv
├── soil_moisture_<crop>_<country>.csv
└── yield_<crop>_<country>.csv
Example:
data/maize/NL/yield_maize_NL.csv
yield-hub-predict validate-data --crop maize --country NL --data-root ./datayield-hub-predict list-models
yield-hub-predict fetch-model --model-type rlinear --crop maize --country NL
yield-hub-predict predict --model-type rlinear --crop maize --country NL --data-root ./dataPredictions are written to wrappers/data/ by default.
Missing Hugging Face token: addHF_TOKENin.env.No data found for <crop>-<country>: checkdata/<crop>/<country>/...and runvalidate-data.Missing columnsorinvalid_dates: fix the CSV schema before running inference.ModuleNotFoundError: cybench: install and point the project at a validAgML-CY-BENCHcheckout for now.
Current focus:
- SDK and Python API
- CLI for validation, artifact fetch, and prediction
- private Hugging Face model access
Later stage:
- dashboard
- public model access
The intended SDK workflow is:
- install the package
- provide CY-BENCH-compatible data via a
data_root - list or fetch the model you want
- run prediction
Python:
from yield_hub import ModelRegistry, Predictor, validate_data
validate_data(crop="maize", country="NL", data_root="./data")
registry = ModelRegistry()
models = registry.list_models()
checkpoint_path = registry.fetch_model(model_type="rlinear", crop="maize", country="NL")
predictor = Predictor(data_root="./data")
df = predictor.predict(model_type="rlinear", crop="maize", country="NL")CLI:
yield-hub-predict list-models
yield-hub-predict fetch-model --model-type rlinear --crop maize --country NL
yield-hub-predict validate-data --crop maize --country NL --data-root ./data
yield-hub-predict predict --model-type rlinear --crop maize --country NL --data-root ./dataThe CLI also keeps backward compatibility with the older direct form:
yield-hub-predict --model-type rlinear --crop maize --country NL --data-root ./dataThe SDK currently validates against data contract version 1.0.
data_root must resolve to a directory containing crop and country folders:
data_root/
├── maize/
│ └── NL/
└── wheat/
For each crop/country pair, these files are mandatory:
crop_calendar_<crop>_<country>.csv
fpar_<crop>_<country>.csv
location_<crop>_<country>.csv
meteo_<crop>_<country>.csv
ndvi_<crop>_<country>.csv
soil_<crop>_<country>.csv
soil_moisture_<crop>_<country>.csv
yield_<crop>_<country>.csv
Required columns by file:
yield:adm_id,harvest_year,yieldsoil:adm_id,awc,bulk_densitycrop_calendar:adm_id,sos,eosmeteo:adm_id,date,tmin,tmax,prec,rad,tavg,cwbfpar:adm_id,date,fparndvi:adm_id,date,ndvisoil_moisture:adm_id,date,ssmlocation:adm_id,latitude,longitude
Current validation rules:
- every required file must exist
- every required file must be non-empty
- all required columns must be present
- duplicate key rows are rejected for
yield,soil,crop_calendar, andlocation - temporal files must have parseable
datevalues yieldyears are checked for gaps between min and max detected years- numeric sanity checks are enforced for:
yield.yield >= 0soil.awc >= 0soil.bulk_density >= 0crop_calendar.sosandcrop_calendar.eosin1..366crop_calendar.eos >= crop_calendar.sosfpar.fparin0..100, with0..1treated as the preferred normalized scalendvi.ndviin-1..1soil_moisture.ssmin0..100, with0..1treated as the preferred normalized scalelocation.latitudein-90..90location.longitudein-180..180
- temporal files are checked for year overlap with the detected yield years
What is currently mandatory:
- the full file set above
- CY-BENCH-compatible file names
- CY-BENCH-compatible required columns
What is currently optional:
- extra columns beyond the required schema
- local storage location, as long as
--data-rootpoints to it correctly
Validation example:
yield-hub-predict validate-data --crop maize --country NL --data-root ./dataPython example:
from yield_hub import DATA_CONTRACT_VERSION, validate_data
print(DATA_CONTRACT_VERSION)
report = validate_data(data_root="./data", crop="maize", country="NL")
print(report["ok"])This repository now includes a minimal pyproject.toml for editable installs and
package structure for wrapper tooling and future app/backend work:
pip install -e .
yield-hub-predict --model-type patchtst --country DE --crop maize --data-root ./dataNote: cybench still comes from the external AgML-CY-BENCH codebase and is not
published on PyPI, so that prerequisite remains separate for now.
The package is organized around:
yield_hub.settings: environment loading and path resolutionyield_hub.artifacts: Hugging Face artifact lookup, listing, and downloadsyield_hub.data: dataset loading, localdata_rootsupport, and split setupyield_hub.predictor: importable prediction APIyield_hub.validation: dataset validationyield_hub.cli: command-line entrypoint
Python prediction example:
from yield_hub import ModelRegistry, Predictor, validate_data
report = validate_data(data_root="./data", crop="maize", country="NL")
if not report["ok"]:
raise ValueError(report)
registry = ModelRegistry()
registry.fetch_model(model_type="rlinear", crop="maize", country="NL")
predictor = Predictor(data_root="./data")
df = predictor.predict(model_type="rlinear", crop="maize", country="NL")
print(df.head())CLI prediction example:
yield-hub-predict validate-data --crop maize --country NL --data-root ./data
yield-hub-predict fetch-model --model-type rlinear --crop maize --country NL
yield-hub-predict predict --model-type rlinear --crop maize --country NL --data-root ./datavalidate-datareturns"target_exists": falsePoint--data-rootat the folder containingmaize/andwheat/, not directly at the country folder.missing_filesis non-empty Add the missing CSVs with the exact expected names.missing_columnsis non-empty Rename or add the required columns listed in the validation report.invalid_datesis non-zero Normalize thedatecolumn to a parseable format such asYYYYMMDDor ISO date strings.warningscontains scale messages forfparorssmThe file is accepted, but the values are not on the preferred normalized0..1scale.duplicate_key_rowsis non-zero Deduplicate the file on the reported logical key before inference.year_overlap_with_yieldis empty Your temporal files do not cover the same years as the yield file.- checkpoint download fails
Confirm the token has read access to the private
Ambrosia2024repositories. cybenchimport fails This package still depends on an externalAgML-CY-BENCHcheckout for now.
Depending upon the setup of interest:
- Temporal Split with the last 5 years as test dataset, the 2 years before for the validation data, and rest as training data (setups/temporal)
- Performing Hyperparameter Optimization using Optuna (setups/hpo)
- Walk Forward Setup with the last 5 years as the test dataset (setups/walk-forward)
Run
cd setups/temporal
python statisticalBaselines.py --model mlp --country DE --crop wheat --seed 1111 --save_dir ../output/saved_models/ --output_dir ../output/trained_models/
python tstBaselines.py --crop maize --country NL --model_type tst --use_sota_features --use_residual_trend --use_recursive_lags --use_cwb_feature --aggregation daily --include_spatial_features
python linearBaselines.py --crop maize --country NL --model_type xlinear --use_sota_features --use_residual_trend --use_recursive_lags --use_cwb_feature --aggregation daily --include_spatial_features
Alternatively, feel free to use the bash script if you are working with SLURM to train all the baselines together:
cd setups/temporal
sbatch run_baselines.sh
All the trained checkpoints are available under the Ambrosia2024/yield-hub collection on Hugging Face. Individual model repositories include yield-autoformer-cybench and the bundled yield-transformers-cybench and yield-linear-cybench repos.
The SDK downloads checkpoints on demand into the local Hugging Face cache. You do not need to manually copy checkpoints into this repository.
For private model repositories, create a token with read access to the Ambrosia2024 organization repos and store it in .env:
HF_TOKEN=your_token_here
HUGGINGFACE_HUB_TOKEN=your_token_here
The repository includes CLI and Python helpers that download config-and-results.csv and model checkpoints from Hugging Face using that token.
If you want to use this repository in the older integrated research layout with AgML-CY-BENCH, keep using the external CY-BENCH checkout and its installation instructions. That path is still relevant for training and benchmark development, but the recommended inference path is the SDK/CLI workflow above.