File size: 2,440 Bytes
0951879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""

Example usage script for Crop Stress Detection Pipeline

"""

from crop_stress_pipeline import CropStressPipeline
import json

def main():
    """

    Example: Analyze a wheat field in Punjab, India

    """
    
    # Initialize pipeline
    print("Initializing pipeline...")
    pipeline = CropStressPipeline()
    
    # Define field parameters
    field_params = {
        'center_lat': 30.2300,
        'center_lon': 75.8300,
        'crop_type': 'Wheat',
        'analysis_date': '2024-01-15',
        'field_size_hectares': 0.04,
        'farmer_context': {
            'role': 'Owner-Operator',
            'years_farming': 15,
            'irrigation_method': 'Drip Irrigation',
            'farming_goal': 'Maximize yield while maintaining soil health'
        },
        'output_path': 'example_results.json'
    }
    
    print("\nField Information:")
    print(f"  Location: ({field_params['center_lat']}, {field_params['center_lon']})")
    print(f"  Crop: {field_params['crop_type']}")
    print(f"  Date: {field_params['analysis_date']}")
    print(f"  Size: {field_params['field_size_hectares']} hectares")
    
    # Run pipeline
    print("\nRunning pipeline...")
    try:
        results = pipeline.run(**field_params)
        
        print("\n" + "="*60)
        print("PIPELINE COMPLETED SUCCESSFULLY")
        print("="*60)
        
        # Display key results
        print("\nKey Results:")
        print(f"  Overall Health: {results['llm_analysis']['overall_health']['status'].upper()}")
        print(f"  Soil Moisture: {results['llm_analysis']['soil_moisture']['level'].upper()}")
        print(f"  Vegetation Stress: {results['llm_analysis']['vegetation_stress']['level'].upper()}")
        
        print(f"\nFull results saved to: {field_params['output_path']}")
        
        # Pretty print a sample of the results
        print("\nSample Output (Vegetation Indices):")
        ndvi_stats = results['vegetation_indices_summary']['indices']['NDVI']
        print(f"  NDVI Latest Mean: {ndvi_stats['latest']['mean']:.4f}")
        print(f"  NDVI Change: {ndvi_stats['change']:+.4f}")
        
        return results
        
    except Exception as e:
        print(f"\nERROR: Pipeline failed - {str(e)}")
        print("Check crop_stress_pipeline.log for details")
        raise


if __name__ == "__main__":
    results = main()