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 <SKILL_DIR>/scripts/check_env.py
This verifies Python dependencies and data integrity. If packages are missing:
CODEBLOCK1
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.
<SKILL_DIR> convention
Throughout this file, <SKILL_DIR> 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 |
|---|
| hightemp | 高温胁迫 | +3°C max / +2°C min |
| lowtemp |
低温胁迫 | -3°C max / -2°C min |
| drought | 干旱胁迫 | 90% precipitation reduction |
| flood | 涝害胁迫 | 3x precipitation increase |
| low_light | 寡照胁迫 | 60% PAR reduction |
Prediction Commands
Full prediction (recommended)
CODEBLOCK2
Genotype-only / environment-only
CODEBLOCK3
Specific traits
CODEBLOCK4
With stress
CODEBLOCK5
Multiple samples
CODEBLOCK6
Custom genotype file
python <SKILL_DIR>/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
CODEBLOCK8
Human-readable table
CODEBLOCK9
All CLI arguments
| Arg | Default | Description |
|---|
| INLINECODE5 | required | Latitude |
| INLINECODE6 |
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
- - "经纬度30.5, 114.3" → INLINECODE26
- "武汉" → INLINECODE27
- "北纬25度,东经103度" → INLINECODE28
2. Map trait names
- - 株高/plant height → PH
- 产量/yield → Y
- 粒长/grain length → GL
- 抽穗期/heading date → HD
- 千粒重/1000-grain weight → TGW
- 穗长/panicle length → PL
- 结实率/seed setting rate → SSR
- 每穗粒数/grains per panicle → GP
- 粒宽/grain width → GW
- 分蘖数/tiller number → TN
3. Map stress requests
- - 高温/heat → hightemp
- 低温/cold/chilling → lowtemp
- 干旱/drought → drought
- 洪涝/flooding → flood
- 阴天/寡照/low light → low_light
- "高温+5度" → INLINECODE29
4. Genotype data
- - Built-in samples:
--sample sample1 (3925 available: sample1..sample3925) - User file: INLINECODE31
5. 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
CODEBLOCK10
Architecture (for reference)
- - Model: Multi-gate Mixture-of-Experts (MMoE) with ResidualMLP experts
- Genotype features: 1024-dim VAE latent encoding of genomic data
- Environment features: 53 season-aggregated variables from daily weather
- Environmental data: NASA POWER API (auto-fetched and cached locally)
水稻表型预测
通过预训练的MMoE模型预测10个水稻农艺性状的独立技能。
所有模型、数据和脚本均在此目录内——直接提供给用户此文件夹。
环境配置
首次检查
bash
python
DIR>/scripts/checkenv.py
此命令验证Python依赖项和数据完整性。如果缺少依赖包:
bash
pip install -r /requirements.txt
必需依赖:torch>=2.0 numpy pandas scikit-learn scipy requests
GPU为可选——CPU也可运行(仅速度较慢)。如果存在GPU,将自动使用cuda:0。
约定
在整个文件中, 表示此技能根目录的绝对路径(即包含此SKILL.md的文件夹)。运行命令时,请替换为实际路径。
--base_dir 为可选参数;如果省略,脚本将从自身位置自动检测。
支持性状
| 代码 | 中文 | 英文 | 单位 |
|---|
| HD | 抽穗期 | Heading Date | 天 |
| PH |
株高 | Plant Height | 厘米 |
| PL | 穗长 | Panicle Length | 厘米 |
| TN | 分蘖数 | Tiller Number | 个 |
| GP | 每穗粒数 | Grains Per Panicle | 粒 |
| SSR | 结实率 | Seed Setting Rate | % |
| TGW | 千粒重 | Thousand Grain Weight | 克 |
| GL | 粒长 | Grain Length | 毫米 |
| GW | 粒宽 | Grain Width | 毫米 |
| Y | 产量 | Yield | 千克/公顷 |
支持地点(7个内置站点)
| 代码 | 城市 | 纬度 | 经度 |
|---|
| 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 |
任何输入的经纬度将通过哈弗辛距离自动匹配到最近站点。
对于有网络的地区,还可以通过NASA POWER API获取精确坐标的每日天气数据。
胁迫类型
| 类型 | 中文 | 默认效果 |
|---|
| hightemp | 高温胁迫 | 最高温+3°C / 最低温+2°C |
| lowtemp |
低温胁迫 | 最高温-3°C / 最低温-2°C |
| drought | 干旱胁迫 | 降水量减少90% |
| flood | 涝害胁迫 | 降水量增加3倍 |
| low_light | 寡照胁迫 | 光合有效辐射减少60% |
预测命令
完整预测(推荐)
bash
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1
仅基因型/仅环境
bash
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
特定性状
bash
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --trait PH,Y
带胁迫
bash
python DIR>/scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --stress hightemp
python DIR>/scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --stress hightemp --stress_delta 5.0
多个样本
bash
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1,sample2,sample3
自定义基因型文件
bash
python DIR>/scripts/predict.py --lat 30.5 --lon 114.3 --genotypefile /path/to/user_vae.csv
格式:包含1024列(VAE编码特征)的CSV文件,第一列为样本索引。
强制使用CPU/指定设备
bash
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
人类可读表格
bash
python /scripts/predict.py --lat 30.5 --lon 114.3 --sample sample1 --output table
所有CLI参数
必需 | 经度 |
| --sample | 无 | 内置样本ID,逗号分隔(sample1..sample3925) |
| --genotype_file | 无 | 自定义1024维VAE CSV文件路径 |
| --mode | full | gene、env或full |
| --trait | all | 逗号分隔的性状代码或all |
| --stress | 无 | 胁迫类型名称 |
| --stress_delta | 无 | 覆盖温度变化量 |
| --device | auto | auto、cpu或cuda:0 |
| --year | 2024 | 环境数据年份 |
| --output | json | json或table |
| --base_dir | auto | 覆盖技能目录路径 |
处理用户请求
1. 提取地点
- - 经纬度30.5, 114.3 → --lat 30.5 --lon 114.3
- 武汉 → --lat 30.58 --lon 114.27
- 北纬25度,东经103度 → --lat 25 --lon 103
2. 映射性状名称
- - 株高/plant height → PH
- 产量/yield → Y
- 粒长/grain length → GL
- 抽穗期/heading date → HD
- 千粒重/1000-grain weight → TGW
- 穗长/panicle length → PL
- 结实率/seed setting rate → SSR
- 每穗粒数/grains per panicle → GP
- 粒宽/grain width → GW
- 分蘖数/tiller number → TN
3. 映射胁迫请求
- - 高温/heat → hightemp
- 低温/cold/chilling → lowtemp
- 干旱/drought → drought
- 洪涝/flooding → flood
- 阴天/寡照/low light → lowlight
- 高温+5度 → --stress hightemp --stress_delta 5.0
4. 基因型数据
- - 内置样本:--sample sample1(共3925个:sample1..sample3925)
- 用户文件:--genotype_file /path/to/file.csv
5. 解读输出
JSON包含:location(地点)、genotypeprediction(基因型预测)、environmentprediction(环境预测)、stressprediction(胁迫预测)、traitinfo(性状信息)。
以environment_prediction为主要结果(包含环境背景)。
将genotype_prediction作为基线进行比较。
对于胁迫情况,比较正常值与胁迫值。
四舍五入规则:HD/TN/GP → 整数,PH/PL/TGW/SSR → 1位小数,GL/GW → 2位小数,Y → 整数。
目录结构
rice_prediction/ ← 提供给用户此文件夹
├── SKILL.md ← 本文件
├── requirements.txt ← pip依赖项
├── data/
│ ├── grid_points.json ← 7个站点坐标
│ ├── vae_features.csv ← 3925个内置基因型样本(1024维VAE)
│ ├── season_history.csv ← 历史季节数据(用于归一化)
│ ├── env_cache/ ← 缓存的每日天气数据(自动填充)
│ ├── models_env/ ← 10个性状特定的环境+基因型模型(每个约4.6MB)
│