A Python tool to fetch and process rainfall data from Colombia's IDEAM (Institute of Hydrology, Meteorology and Environmental Studies) public API. This tool automatically filters for actual rainfall events and creates multiple data aggregations.
- Smart Filtering: Only downloads data when it's actually raining (valorobservado > 0)
- Multiple Aggregations: Creates raw, 30-minute, and daily rainfall aggregations
- Public Data: Uses Colombia's open government data API (no API keys required)
- Easy to Use: Simple Python class with comprehensive documentation
- Flexible Output: Saves data as CSV files with timestamps
- Clone this repository:
git clone https://github.com/yourusername/ideam-rainfall-data.git
cd ideam-rainfall-data- Install dependencies:
pip install -r requirements.txtfrom src.ideam_rainfall import IDEAMRainfallFetcher
# Create fetcher instance
fetcher = IDEAMRainfallFetcher()
# Run complete analysis (last 7 days)
raw_df, agg_30min_df, agg_daily_df = fetcher.run_full_analysis()from src.ideam_rainfall import IDEAMRainfallFetcher
# Create fetcher with custom settings
fetcher = IDEAMRainfallFetcher()
# Get data for last 14 days
raw_df = fetcher.get_rainfall_data_with_rain_only(days_back=14)
# Create custom aggregations
raw_df, agg_30min_df, agg_daily_df = fetcher.create_aggregations(raw_df)
# Save to custom directory
saved_files = fetcher.save_all_files(
raw_df, agg_30min_df, agg_daily_df,
output_dir="./my_rainfall_data"
)
# Show summary statistics
fetcher.show_summary_stats(raw_df, agg_30min_df, agg_daily_df)python src/ideam_rainfall.pyThe tool generates three types of CSV files:
- Minute-by-minute rainfall records
- Only includes records where it's actually raining
- Contains station information, coordinates, and rainfall values
- Rainfall summed over 30-minute intervals
- Only includes intervals with actual rainfall
- Useful for detailed temporal analysis
- Daily rainfall totals per station
- Only includes days with actual rainfall
- Perfect for daily weather analysis
codigoestacion: Station codenombreestacion: Station namedepartamento: Department/Statemunicipio: Municipality/Citylatitud: Latitude coordinatelongitud: Longitude coordinateunidadmedida: Measurement unit (mm)
fechaobservacion: Observation timestampvalorobservado: Observed rainfall value (mm)valor_numeric: Numeric rainfall valuefecha_dt: Parsed datetime
intervalo_30min: 30-minute interval timestamplluvia_30min_mm: Total rainfall in 30-minute period (mm)
fecha: Datelluvia_diaria_mm: Total daily rainfall (mm)
This tool uses Colombia's open government data API:
- Base URL:
https://www.datos.gov.co/resource/s54a-sgyg.json - Data Source: IDEAM (Institute of Hydrology, Meteorology and Environmental Studies)
- Authentication: None required (public API)
- Rate Limiting: Built-in delays between requests
from src.ideam_rainfall import IDEAMRainfallFetcher
fetcher = IDEAMRainfallFetcher()
# Get last 3 days of rainfall data
raw_df = fetcher.get_rainfall_data_with_rain_only(days_back=3)
if raw_df is not None:
print(f"Found {len(raw_df)} rainfall records")
print(f"Total rainfall: {raw_df['valor_numeric'].sum():.1f} mm")
print(f"Stations: {raw_df['codigoestacion'].nunique()}")# Filter data for a specific station
station_data = raw_df[raw_df['codigoestacion'] == '2801500078']
print(f"Station: {station_data['nombreestacion'].iloc[0]}")
print(f"Records: {len(station_data)}")
print(f"Total rainfall: {station_data['valor_numeric'].sum():.1f} mm")
print(f"Max intensity: {station_data['valor_numeric'].max():.1f} mm")# Save files to custom directory
fetcher = IDEAMRainfallFetcher()
raw_df, agg_30min_df, agg_daily_df = fetcher.run_full_analysis(
days_back=7,
output_dir="./rainfall_analysis_2024"
)days_back: Number of days to look back from today (default: 7)output_dir: Directory to save CSV files (default: current directory)base_url: IDEAM API endpoint (default: official endpoint)
The tool tries multiple approaches to fetch data:
- Medium sample with server-side rain filtering
- Large sample with server-side rain filtering
- Date range with server-side rain filtering
- All precipitation data with client-side filtering
- Python 3.7+
- requests >= 2.25.0
- pandas >= 1.3.0
- numpy >= 1.20.0
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
- IDEAM (Institute of Hydrology, Meteorology and Environmental Studies) for providing the public API
- Colombia's Open Government Data initiative for making this data freely available
- Python community for the excellent libraries used in this project
- Initial release
- Basic rainfall data fetching
- 30-minute and daily aggregations
- CSV output functionality
- Comprehensive documentation
If you encounter any issues or have questions, please:
- Check the Issues page
- Create a new issue with detailed information
- Include your Python version and error messages
Made with β€οΈ for Colombia's weather data community