Skip to content

vpoluyaktov/radiocast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

270 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Radio Propagation Service πŸ“‘

An intelligent amateur radio propagation reporting service that generates comprehensive daily reports by analyzing real-time solar and geomagnetic data using AI. The service provides detailed band-by-band propagation forecasts with interactive visualizations to help amateur radio operators optimize their communications.

🌟 Live Example

Visit the production service at radio-propagation.net to see live reports with:

  • Real-time solar activity analysis
  • Interactive propagation charts
  • Band-by-band recommendations
  • 3-day forecasts
  • DX opportunity predictions

🎯 Purpose

This service addresses the amateur radio community's need for:

  • Intelligent Analysis: AI-powered interpretation of complex space weather data
  • Actionable Insights: Clear recommendations for each amateur radio band (10m-80m)
  • Visual Data: Interactive charts showing trends and forecasts
  • Accessibility: Easy-to-understand reports for operators of all experience levels
  • Automation: Daily reports generated without manual intervention

πŸ—οΈ Architecture

graph LR
    A[NOAA SWPC] --> D[Data Fetcher]
    B[N0NBH API] --> D
    C[SIDC RSS] --> D
    E[Helioviewer] --> D
    D --> F[OpenAI GPT-4]
    F --> G[Report Generator]
    G --> H[Interactive Charts]
    G --> I[HTML Reports]
    H --> J[Cloud Storage]
    I --> J
    J --> K[Daily Reports]
Loading

Data Flow:

  1. Collection: Fetch solar/geomagnetic data from multiple authoritative sources
  2. Analysis: OpenAI GPT-4 analyzes conditions and generates insights
  3. Visualization: Create interactive charts using go-echarts
  4. Generation: Combine analysis and charts into comprehensive HTML reports
  5. Storage: Deploy reports to cloud storage with automated scheduling

πŸš€ Quick Start

Prerequisites

  • Go 1.21+ - Programming language runtime
  • OpenAI API Key - For AI-powered analysis (get one here)
  • Google Cloud Project - For production deployment (optional for local testing)

Local Development

  1. Clone and setup:
git clone https://github.com/vpoluyaktov/radiocast.git
cd radiocast/service
go mod download
  1. Set your OpenAI API key:
export OPENAI_API_KEY='sk-your-openai-key-here'
  1. Run the local server (from the service/ directory):
./run_local.sh server

This will:

  • βœ… Kill any existing process on port 8981
  • πŸ“‘ Fetch real data from NOAA, N0NBH, and SIDC
  • πŸ€– Generate a report using OpenAI GPT-4
  • 🌞 Download Sun images from Helioviewer
  • πŸ“Š Create HTML with interactive charts
  • 🌐 Start server on http://localhost:8981
  1. Test the service:
# Health check
curl http://localhost:8981/health

# Generate a new report (no API key required by default)
curl -X POST http://localhost:8981/generate

# View reports in browser
open http://localhost:8981

Fast Testing with Mock Data

For rapid development without API calls:

./run_local.sh server --mockup

πŸ“Š Report Features

Generated reports include comprehensive analysis with:

πŸ“ˆ Interactive Charts

  • Solar Activity: Real-time solar flux, sunspot numbers, and K-index
  • K-index Trend: 72-hour history with exponential moving average
  • Band Conditions: Heatmap showing day/night conditions for all amateur bands
  • 3-Day Forecast: Predicted K-index and propagation quality
  • Propagation Timeline: Dual-axis charts showing solar flux and geomagnetic activity

πŸ“‹ Analysis Sections

  1. Executive Summary - Current conditions overview
  2. Solar Activity Analysis - SFI, sunspot numbers, flare activity
  3. Geomagnetic Conditions - K-index, A-index, storm levels
  4. Band-by-Band Analysis - Specific recommendations for each amateur band (10m-80m)
  5. 3-Day Forecast - Predicted conditions and operating recommendations
  6. DX Opportunities - Enhanced propagation paths and timing
  7. Technical Explanation - Educational content for new operators

πŸ› οΈ Development Tools

Available Commands

Note: All ./run_local.sh commands must be run from the service/ directory.

# Run complete local test with real data
./run_local.sh server

# Fast testing with mock data (no API calls)
./run_local.sh server --mockup

# Test all external API endpoints
./run_local.sh debug-apis

# Run unit tests
./run_local.sh unit-tests

# Show help
./run_local.sh help

Testing & Quality

The project includes comprehensive unit tests with high coverage:

  • Config Package: ~85% coverage
  • Models Package: ~90% coverage
  • Storage Package: 55.6% coverage
  • Charts Package: 92.2% coverage
# Run all tests
go test -v ./...

# Run tests with coverage
go test -v -cover ./...

🌐 API Endpoints

GET / - Main Page

  • Displays the latest report or auto-generates one if none exist
  • Shows loading page with spinner during generation
  • Auto-refreshes every 10 seconds until report is ready

GET /health - Health Check

Health check endpoint for monitoring and load balancers.

POST /generate - Generate Report

Generates a new propagation report with concurrency protection.

API Key Protection: If the API_KEY environment variable is set, this endpoint requires authentication via the Authorization header.

Authentication (when API_KEY is configured):

# With API key
curl -X POST http://localhost:8981/generate \
  -H "Authorization: Bearer your-api-key-here"

Response (Success):

{
  "status": "success", 
  "report_url": "https://radio-propagation.net/2024/01/15/index.html",
  "timestamp": "2024-01-15T12:00:00Z",
  "duration_ms": 45000,
  "data_summary": {
    "solar_flux": 150.2,
    "k_index": 2.3,
    "sunspot_number": 45,
    "activity_level": "Moderate"
  }
}

Response (Concurrent Request):

{
  "error": "Report generation already in progress",
  "status": "conflict"
}

HTTP 409 Conflict - Only one report can be generated at a time

Response (Unauthorized - when API_KEY is configured):

{
  "error": "Missing Authorization header",
  "message": "This endpoint requires an API key. Please provide it in the Authorization header as 'Bearer <your-api-key>'",
  "status": "unauthorized"
}

HTTP 401 Unauthorized - API key required but not provided or invalid

GET /reports?limit=10 - List Reports

Lists recent reports with metadata and direct links.

βš™οΈ Configuration

Variable Description Default Required
OPENAI_API_KEY OpenAI API key for GPT-4 - βœ…
OPENAI_MODEL OpenAI model to use gpt-4.1 ❌
PORT HTTP server port 8981 ❌
ENVIRONMENT Deployment environment local ❌
GCP_PROJECT_ID GCP project (production only) - ❌
GCS_BUCKET GCS bucket (production only) - ❌
RADIOCAST_API_KEY API key for /generate endpoint protection - ❌

πŸ” API Security

The /generate endpoint can be protected with an API key to prevent unauthorized report generation.

Enabling API Key Protection

Set the RADIOCAST_API_KEY environment variable to enable protection:

export RADIOCAST_API_KEY="your-secret-api-key-here"
./run_local.sh server

Using the Protected Endpoint

When API key protection is enabled, include the key in the Authorization header:

# Correct usage with API key
curl -X POST http://localhost:8981/generate \
  -H "Authorization: Bearer your-secret-api-key-here"

# This will be rejected with HTTP 401
curl -X POST http://localhost:8981/generate

Backward Compatibility

  • No RADIOCAST_API_KEY configured: The /generate endpoint works without authentication (default behavior)
  • RADIOCAST_API_KEY configured: The /generate endpoint requires the Authorization: Bearer <key> header
  • Other endpoints: All other endpoints (/health, /reports, /, etc.) remain unprotected

Security Best Practices

  • Use a strong, randomly generated API key (minimum 32 characters)
  • Store the API key securely (environment variables, secret managers)
  • Rotate API keys regularly in production environments
  • Monitor logs for unauthorized access attempts

πŸ“‘ Data Sources

The service integrates with multiple authoritative space weather data sources:

🌞 NOAA Space Weather Prediction Center

  • Website: swpc.noaa.gov
  • K-index Data: Real-time planetary geomagnetic activity
  • Solar Cycle Data: Solar flux index and sunspot numbers
  • Reliability: Primary government source for space weather

πŸ“Š N0NBH Solar Data API

  • Website: hamqsl.com
  • Band Conditions: Real-time HF propagation conditions for all amateur bands
  • Formatted Data: Pre-processed amateur radio specific metrics
  • Update Frequency: Multiple times per day

🌍 SIDC (Solar Influences Data Analysis Center)

  • Website: sidc.be
  • Solar Events: Flare reports and space weather events
  • International Data: European Space Agency collaboration
  • RSS Feed: Real-time event notifications

🌞 Helioviewer Project

  • Website: helioviewer.org
  • Solar Images: Real-time Sun imagery from SDO/AIA instruments
  • Visual Context: Provides visual representation of solar activity
  • NASA Data: Direct integration with space-based solar observatories

πŸ—οΈ Project Structure

radiocast/
β”œβ”€β”€ service/                    # Go application
β”‚   β”œβ”€β”€ main.go                # HTTP server entry point
β”‚   β”œβ”€β”€ internal/
β”‚   β”‚   β”œβ”€β”€ config/            # Configuration management
β”‚   β”‚   β”œβ”€β”€ fetchers/          # Data source integrations  
β”‚   β”‚   β”œβ”€β”€ llm/               # OpenAI GPT-4 integration
β”‚   β”‚   β”œβ”€β”€ models/            # Data structures & types
β”‚   β”‚   β”œβ”€β”€ reports/           # HTML generation & templates
β”‚   β”‚   β”œβ”€β”€ charts/            # Interactive chart generation
β”‚   β”‚   β”œβ”€β”€ storage/           # Local & cloud storage
β”‚   β”‚   β”œβ”€β”€ server/            # HTTP handlers & middleware
β”‚   β”‚   └── imagery/           # Solar image processing
β”‚   β”œβ”€β”€ templates/             # HTML & CSS templates
β”‚   β”œβ”€β”€ run_local.sh          # Development runner script
β”‚   └── Dockerfile            # Container build
β”œβ”€β”€ terraform/                 # Infrastructure as Code
β”‚   β”œβ”€β”€ stage/                # Staging environment
β”‚   └── prod/                 # Production environment
└── .github/workflows/        # CI/CD automation

πŸš€ Production Deployment

The service runs on Google Cloud Platform with automated CI/CD:

  • Production URL: radio-propagation.net
  • Staging Environment: Automatic deployment from stage branch
  • Production Environment: Automatic deployment from main branch
  • Infrastructure: Managed via Terraform
  • Scheduling: Daily report generation via Cloud Scheduler
  • Storage: Reports stored in Google Cloud Storage
  • Monitoring: Cloud Run metrics and custom alerts

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality
  4. Commit changes (git commit -m 'Add amazing feature')
  5. Push to branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Development Guidelines

  • Maintain high test coverage (aim for >80%)
  • Follow Go best practices and conventions
  • Add unit tests for new packages/functions
  • Update documentation for API changes

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support


73! Happy DXing! πŸ“‘πŸŒ

About

RadioCast delivers daily, easy-to-read radio propagation reports powered by real-time solar and space weather dataRadioCast

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors