GAIN
by @qianlvdouhua
Predict rice agronomic traits (yield, plant height, heading date, grain size, etc.) from genotype and environmental data using pre-trained MMoE deep learning...
clawhub install gain๐ About This Skill
name: rice-phenotype-prediction description: >- Predict rice agronomic traits (yield, plant height, heading date, grain size, etc.) from genotype and environmental data using pre-trained MMoE deep learning models. Use when the user asks about rice phenotype prediction, crop trait estimation, genotype-environment interaction, or environmental stress effects on rice. Supports Chinese and English. Trigger terms: ๆฐด็จป, ่กจๅ, ้ขๆต, ๆ ช้ซ, ไบง้, ็ฒ้ฟ, ๆฝ็ฉๆ, ๅ็ฒ้, ็ปๅฎ็, rice, phenotype, yield, trait, stress.
Rice Phenotype Prediction
Self-contained skill for predicting 10 rice agronomic traits via pre-trained MMoE models. All models, data, and scripts are inside this directory โ give users this one folder.
Setup
First-time check
python /scripts/check_env.py
This verifies Python dependencies and data integrity. If packages are missing:
pip install -r /requirements.txt
Required: torch>=2.0 numpy pandas scikit-learn scipy requests
GPU is optional โ CPU works (just slower). If GPU is present, cuda:0 is used automatically.
convention
Throughout this file, means the absolute path to this skill's root directory
(the folder containing this SKILL.md). When running commands, substitute with the actual path.
--base_dir is optional; if omitted, scripts auto-detect it from their own location.
Supported Traits
| Code | Chinese | English | Unit | |------|---------|---------|------| | HD | ๆฝ็ฉๆ | Heading Date | days | | PH | ๆ ช้ซ | Plant Height | cm | | PL | ็ฉ้ฟ | Panicle Length | cm | | TN | ๅ่ๆฐ | Tiller Number | count | | GP | ๆฏ็ฉ็ฒๆฐ | Grains Per Panicle | count | | SSR | ็ปๅฎ็ | Seed Setting Rate | % | | TGW | ๅ็ฒ้ | Thousand Grain Weight | g | | GL | ็ฒ้ฟ | Grain Length | mm | | GW | ็ฒๅฎฝ | Grain Width | mm | | Y | ไบง้ | Yield | kg/ha |
Supported Locations (7 built-in stations)
| Code | City | Lat | Lon | |------|------|-----|-----| | km | ๆๆ | 25.02 | 102.68 | | gzl | ๅ ญ็ๆฐด | 26.59 | 104.83 | | nn | ๅๅฎ | 22.82 | 108.37 | | wh | ๆญฆๆฑ | 30.58 | 114.27 | | hf | ๅ่ฅ | 31.82 | 117.25 | | hz | ๆญๅท | 30.25 | 120.17 | | th | ้ๅ | 41.73 | 125.94 |
Any input lat/lon is auto-matched to the nearest station via Haversine distance. For locations with internet, daily weather data can also be fetched from NASA POWER API for the exact coordinates.
Stress Types
| Type | Chinese | Default effect | |------|---------|----------------| | high_temp | ้ซๆธฉ่่ฟซ | +3ยฐC max / +2ยฐC min | | low_temp | ไฝๆธฉ่่ฟซ | -3ยฐC max / -2ยฐC min | | drought | ๅนฒๆฑ่่ฟซ | 90% precipitation reduction | | flood | ๆถๅฎณ่่ฟซ | 3x precipitation increase | | low_light | ๅฏก็ ง่่ฟซ | 60% PAR reduction |
Prediction Commands
Full prediction (recommended)
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1
Genotype-only / environment-only
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --mode gene
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --mode env
Specific traits
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --trait PH,Y
With stress
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --stress high_temp
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --stress high_temp --stress_delta 5.0
Multiple samples
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample "sample1,sample2,sample3"
Custom genotype file
python /scripts/predict.py --lat 30.5 --lon 114.3 --genotype_file /path/to/user_vae.csv
Format: CSV with 1024 columns (VAE-encoded features), first column = sample index.Force CPU / specific device
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --device cpu
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --device cuda:0
Human-readable table
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --output table
All CLI arguments
| Arg | Default | Description | |-----|---------|-------------| |--lat | required | Latitude |
| --lon | required | Longitude |
| --sample | None | Built-in sample ID(s), comma-separated (sample1..sample3925) |
| --genotype_file | None | Custom 1024-dim VAE CSV path |
| --mode | full | gene, env, or full |
| --trait | all | Comma-separated trait codes or all |
| --stress | None | Stress type name |
| --stress_delta | None | Override temperature delta |
| --device | auto | auto, cpu, or cuda:0 |
| --year | 2024 | Year for environmental data |
| --output | json | json or table |
| --base_dir | auto | Override skill directory path |Handling User Requests
1. Extract location
--lat 30.5 --lon 114.3--lat 30.58 --lon 114.27--lat 25 --lon 1032. Map trait names
3. Map stress requests
--stress high_temp --stress_delta 5.04. Genotype data
--sample sample1 (3925 available: sample1..sample3925)--genotype_file /path/to/file.csv5. Interpreting output
JSON contains:location, genotype_prediction, environment_prediction, stress_prediction, trait_info.Report environment_prediction as primary (has environmental context).
Compare genotype_prediction as baseline.
For stress, compare normal vs stressed values.
Rounding: HD/TN/GP โ integer, PH/PL/TGW/SSR โ 1 decimal, GL/GW โ 2 decimals, Y โ integer.
Directory Structure
rice_prediction/ โ give users this folder
โโโ SKILL.md โ this file
โโโ requirements.txt โ pip dependencies
โโโ data/
โ โโโ grid_points.json โ 7 station coordinates
โ โโโ vae_features.csv โ 3925 built-in genotype samples (1024-dim VAE)
โ โโโ season_history.csv โ historical season data for normalization
โ โโโ env_cache/ โ cached daily weather (auto-populated)
โ โโโ models_env/ โ 10 trait-specific env+gene models (~4.6MB each)
โ โโโ models_gene/ โ 7 location-specific genotype models (~8MB each)
โโโ scripts/
โโโ predict.py โ main entry point
โโโ check_env.py โ dependency checker
โโโ model_def.py โ MMoE model architectures
โโโ grid_manager.py โ nearest grid point finder
โโโ env_data_fetcher.py โ NASA POWER API fetcher + cache
โโโ env_processor.py โ environmental feature engineering
โโโ stress_simulator.py โ stress scenario simulation
Architecture (for reference)
โ๏ธ Configuration
First-time check
python /scripts/check_env.py
This verifies Python dependencies and data integrity. If packages are missing:
pip install -r /requirements.txt
Required: torch>=2.0 numpy pandas scikit-learn scipy requests
GPU is optional โ CPU works (just slower). If GPU is present, cuda:0 is used automatically.
convention
Throughout this file, means the absolute path to this skill's root directory
(the folder containing this SKILL.md). When running commands, substitute with the actual path.
--base_dir is optional; if omitted, scripts auto-detect it from their own location.