๐ŸŽ Get the FREE AI Skills Starter Guide โ€” Subscribe โ†’
BytesAgainBytesAgain
๐Ÿฆ€ ClawHub

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

Versionv1.0.1
Downloads619
TERMINAL
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

  • "็ป็บฌๅบฆ30.5, 114.3" โ†’ --lat 30.5 --lon 114.3
  • "ๆญฆๆฑ‰" โ†’ --lat 30.58 --lon 114.27
  • "ๅŒ—็บฌ25ๅบฆ๏ผŒไธœ็ป103ๅบฆ" โ†’ --lat 25 --lon 103
  • 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 โ†’ high_temp
  • ไฝŽๆธฉ/cold/chilling โ†’ low_temp
  • ๅนฒๆ—ฑ/drought โ†’ drought
  • ๆดชๆถ/flooding โ†’ flood
  • ้˜ดๅคฉ/ๅฏก็…ง/low light โ†’ low_light
  • "้ซ˜ๆธฉ+5ๅบฆ" โ†’ --stress high_temp --stress_delta 5.0
  • 4. Genotype data

  • Built-in samples: --sample sample1 (3925 available: sample1..sample3925)
  • User file: --genotype_file /path/to/file.csv
  • 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

    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)

  • 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)
  • โš™๏ธ 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.