152 lines
4.2 KiB
Python
152 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Setup Script for SAR Download Environment
|
|
=========================================
|
|
|
|
This script helps set up the Python environment for SAR data download.
|
|
|
|
Usage:
|
|
python setup_sar_environment.py
|
|
|
|
The script will:
|
|
1. Check Python version
|
|
2. Install required packages
|
|
3. Test SentinelHub connection
|
|
4. Create necessary directories
|
|
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
def check_python_version():
|
|
"""Check if Python version is compatible"""
|
|
version = sys.version_info
|
|
if version.major != 3 or version.minor < 8:
|
|
print(f"Error: Python 3.8+ required, found {version.major}.{version.minor}")
|
|
return False
|
|
print(f"✓ Python {version.major}.{version.minor}.{version.micro} is compatible")
|
|
return True
|
|
|
|
def install_requirements():
|
|
"""Install required packages"""
|
|
requirements_file = "requirements_sar.txt"
|
|
|
|
if not os.path.exists(requirements_file):
|
|
print(f"Error: {requirements_file} not found")
|
|
return False
|
|
|
|
print("Installing required packages...")
|
|
try:
|
|
subprocess.check_call([
|
|
sys.executable, "-m", "pip", "install", "-r", requirements_file
|
|
])
|
|
print("✓ Packages installed successfully")
|
|
return True
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error installing packages: {e}")
|
|
return False
|
|
|
|
def create_directories():
|
|
"""Create necessary directory structure"""
|
|
directories = [
|
|
"data/aura/weekly_SAR_mosaic",
|
|
"data/aura/field_boundaries",
|
|
"output/sar_analysis"
|
|
]
|
|
|
|
for directory in directories:
|
|
Path(directory).mkdir(parents=True, exist_ok=True)
|
|
print(f"✓ Created directory: {directory}")
|
|
|
|
return True
|
|
|
|
def test_imports():
|
|
"""Test if all required packages can be imported"""
|
|
packages = [
|
|
"sentinelhub",
|
|
"geopandas",
|
|
"rasterio",
|
|
"numpy",
|
|
"scipy"
|
|
]
|
|
|
|
print("Testing package imports...")
|
|
failed_imports = []
|
|
|
|
for package in packages:
|
|
try:
|
|
__import__(package)
|
|
print(f"✓ {package}")
|
|
except ImportError as e:
|
|
print(f"✗ {package}: {e}")
|
|
failed_imports.append(package)
|
|
|
|
if failed_imports:
|
|
print(f"\nFailed to import: {', '.join(failed_imports)}")
|
|
return False
|
|
|
|
print("✓ All packages imported successfully")
|
|
return True
|
|
|
|
def check_sentinelhub_config():
|
|
"""Check SentinelHub configuration"""
|
|
try:
|
|
from sentinelhub import SHConfig
|
|
config = SHConfig()
|
|
|
|
print("\nSentinelHub Configuration Check:")
|
|
print(f"Instance ID: {'Set' if config.instance_id else 'Not set'}")
|
|
print(f"Client ID: {'Set' if config.sh_client_id else 'Not set'}")
|
|
print(f"Client Secret: {'Set' if config.sh_client_secret else 'Not set'}")
|
|
|
|
if not config.sh_client_id or not config.sh_client_secret:
|
|
print("\n⚠️ SentinelHub credentials not configured")
|
|
print("You'll need to set these up when running the download script")
|
|
print("Get credentials from: https://apps.sentinel-hub.com/")
|
|
else:
|
|
print("✓ SentinelHub credentials are configured")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"Error checking SentinelHub config: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Main setup function"""
|
|
print("=== SAR Download Environment Setup ===\n")
|
|
|
|
# Check Python version
|
|
if not check_python_version():
|
|
return False
|
|
|
|
# Install requirements
|
|
if not install_requirements():
|
|
return False
|
|
|
|
# Create directories
|
|
if not create_directories():
|
|
return False
|
|
|
|
# Test imports
|
|
if not test_imports():
|
|
return False
|
|
|
|
# Check SentinelHub config
|
|
check_sentinelhub_config()
|
|
|
|
print("\n=== Setup Complete! ===")
|
|
print("\nNext steps:")
|
|
print("1. Get SentinelHub credentials from https://apps.sentinel-hub.com/")
|
|
print("2. Place your field boundaries file (geojson) in data/aura/field_boundaries/")
|
|
print("3. Run: python download_s1_aura.py")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|