Skip to content

CSin007/FarmSim

Repository files navigation

Farm Risk Analysis Backend

A Python backend for farm risk and climate impact analysis, built around published agricultural models and official data sources.

What this project computes

  1. Baseline risk without mitigation using published crop temperature sensitivity and water stress models.
  2. Climate damage without mitigation using EPA GHG inventory emission factors and equivalencies.
  3. Mitigated risk using USDA ERS risk reduction factors for climate-smart practices.
  4. Climate benefit prevented using COMET-Planner soil carbon sequestration lookup tables.
  5. U.S.-focused top 5 climate-smart practice recommendations with animation-ready storytelling metadata.

Models and methodologies

  • Zhao et al. (2017) PNAS crop yield sensitivity to temperature.
  • FAO Irrigation and Drainage Paper 66 (2012) water stress Ky model.
  • USDA NASS commodity price volatility and USDA ERS price risk classification.
  • EPA GHG Inventory 2024 emission factors and EPA equivalencies.
  • USDA ERS EIB-233 (2022) risk reduction factors for climate-smart agricultural practices.
  • USDA NRCS COMET-Planner v3 (2024) DayCent Tier-3 carbon sequestration rates.

Structure

  • src/farm_risk_analysis/constants.py - published lookup tables and source citations.
  • src/farm_risk_analysis/models.py - dataclasses and request models.
  • src/farm_risk_analysis/agents.py - weather, market, and soil data fetchers.
  • src/farm_risk_analysis/recommendations.py - deterministic U.S. practice ranking and animation metadata.
  • src/farm_risk_analysis/risk_calc.py - core four-output computation logic.
  • src/farm_risk_analysis/orchestrator.py - orchestration and narrative synthesis.
  • src/farm_risk_analysis/api.py - FastAPI endpoint.

Getting started

  1. Install dependencies:
python -m pip install -r requirements.txt
  1. Run the API server:
uvicorn farm_risk_analysis.api:app --reload --port 8010
  1. Use scripts/run_example.py to execute a sample profile locally.

Frontend

A React + Vite frontend now lives in frontend/ and is wired to the FastAPI /analyze endpoint.

  1. Install frontend dependencies:
cd frontend
npm install
  1. Set the backend base URL if needed:
copy .env.example .env
  1. Start the frontend:
npm run dev

The backend enables CORS for http://localhost:5173 and http://127.0.0.1:5173 by default. It also allows http://localhost:4173 and http://127.0.0.1:4173 for static preview/testing.

Notes

  • The backend deliberately separates quantitative modeling from narrative synthesis.
  • Practice scoring is deterministic and runs locally; GPT is optional for richer summaries.
  • All quantitative formulas and data tables are grounded in published research or official datasets.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors