Skip to main content
Loading navigation

Build a Crop Portfolio Drought Contingency Allocator — implementation

Prompt source

implementation99 lines11 sectionsNo variables1 code block
## Build
Evaluate agricultural parcel soil moisture deficits using simulated ERA5 volumetric water layer indicators. Formulate operational drought contingency plans allocating secondary irrigation rations across crop varieties.

## User
Agricultural Risk Officer

## Workflow
1. Ingest crop portfolio parcel acreage, crop water thresholds, and baseline yield valuations.
2. Retrieve ERA5 soil moisture layer indicators across target growing months via CDS API queries.
3. Calculate parcel-level soil moisture deficit anomalies against 10-year baseline historical quantiles.
4. Generate a prioritized irrigation allocation plan and crop contingency schedule for human sign-off.

## Interface
Streamlit operational dashboard displaying parcel risk rankings, soil moisture anomaly plots, and editable irrigation contingency tables.

## Data
Execute ECMWF CDS API client calls with local mock fallback fixtures storing reanalysis-era5-single-levels volumetric soil water layer parameters.
Starter examples below are synthetic. They are not downloaded records.

## Source
[Copernicus Climate Data Store client](https://raw.githubusercontent.com/ecmwf/cdsapi/master/README.rst)
Uses the cdsapi.Client query format for ERA5 reanalysis parameters, retrieving soil moisture layers across defined temporal ranges.

## Tools
pydantic-ai, cdsapi, pandas.
Enforces strict type safety and schema validation over multi-parcel drought contingency models and allocation schedules.
Local or cloud LLM supporting structured function calling and JSON schema extraction.

## Deliverables
Submit runnable source, pinned dependencies, setup commands, a working interface, example outputs, and a recorded end-to-end demo. Include tests and an action log.

## Acceptance
- Calculates volumetric soil moisture anomaly scores for each parcel relative to baseline historical norms.
- Produces a deterministic irrigation rationing priority table ranking crops by drought susceptibility.
- Outputs contingency recommendations flagged for agronomist approval without automated operational execution.

## Starter Examples
```json
[
  {
    "input": {
      "portfolio_id": "PORT-IA-2024",
      "parcels": [
        {
          "parcel_id": "P-01",
          "crop": "corn",
          "acres": 300,
          "moisture_threshold": 0.22,
          "current_layer1_moisture": 0.16
        },
        {
          "parcel_id": "P-02",
          "crop": "soybean",
          "acres": 250,
          "moisture_threshold": 0.18,
          "current_layer1_moisture": 0.19
        }
      ],
      "available_reserve_m3": 15000
    },
    "expected_output": {
      "portfolio_id": "PORT-IA-2024",
      "deficit_detected": true,
      "allocations": [
        {
          "parcel_id": "P-01",
          "crop": "corn",
          "deficit": -0.06,
          "allocated_reserve_m3": 15000,
          "status": "critical_ration"
        },
        {
          "parcel_id": "P-02",
          "crop": "soybean",
          "deficit": 0.01,
          "allocated_reserve_m3": 0,
          "status": "sufficient"
        }
      ],
      "contingency_summary": "Corn parcel P-01 breached soil moisture threshold by 0.06 m3/m3; reserved water directed to mitigate yield loss."
    }
  },
  {
    "input": {
      "portfolio_id": "PORT-CA-2024",
      "parcels": [
        {
          "parcel_id": "P-03",
          "crop": "almond",
          "acres": 120,
          "moisture_threshold": 0.25,
          "current_layer1_moisture": null
        }
      ],
      "available_reserve_m3": 5000
    },
    "expected_output": {
      "portfolio_id": "PORT-CA-2024",
      "deficit_detected": false,
      "allocations": [],
      "contingency_summary": "Incomplete moisture data for parcel P-03; contingency plan halted pending valid telemetry."
    }
  }
]
```

## Safety
Simulates water allocation suggestions only. No physical control systems or commercial irrigation gates are actuated.
Use mock external writes. Require human review before any real deployment.