├── README.md └── Rainfall_analysis_nigeria.js /README.md: -------------------------------------------------------------------------------- 1 | # Rainfall Analysis for Nigeria (2018-2024) 2 | 3 | This project analyzes and visualizes rainfall data for Nigeria from 2018 to 2024 using the Google Earth Engine (GEE) platform and the CHIRPS dataset. The CHIRPS dataset provides daily rainfall estimates, making it ideal for this temporal and spatial analysis. 4 | 5 | ## Features 6 | 7 | - **Monthly Rainfall Visualization**: Aggregates daily rainfall data into monthly sums for better analysis. 8 | - **Time Series Chart**: Displays the average monthly rainfall over the selected period. 9 | - **Interactive Map**: Highlights rainfall distribution across Nigeria with a color-coded legend. 10 | 11 | ## Technologies Used 12 | 13 | - **Google Earth Engine**: For accessing and processing geospatial data. 14 | - **CHIRPS Dataset**: High-resolution daily precipitation data. 15 | 16 | ## Script Overview 17 | 18 | The `rainfall_analysis_nigeria.js` script: 19 | 20 | 1. **Defines Nigeria's boundary**: Uses the FAO GAUL dataset. 21 | 2. **Filters CHIRPS data**: Retrieves rainfall data within the specified time range and region. 22 | 3. **Aggregates rainfall data**: Summarizes rainfall into monthly totals. 23 | 4. **Visualizes data**: 24 | - Adds a rainfall map with color-coded visualization. 25 | - Displays a time series chart of average monthly rainfall. 26 | - Includes a legend to interpret rainfall intensities. 27 | 28 | ## How to Use 29 | 30 | 1. Open the [Google Earth Engine Code Editor](https://code.earthengine.google.com/). 31 | 2. Copy and paste the contents of `rainfall_analysis_nigeria.js` into the editor. 32 | 3. Run the script to view the rainfall map, chart, and legend. 33 | 34 | ## File Structure 35 | 36 | - **`rainfall_analysis_nigeria.js`**: Main script for rainfall analysis and visualization. 37 | - **`README.md`**: Documentation for the project. 38 | 39 | ## Outputs 40 | 41 | - **Interactive Map**: Visualizes average rainfall distribution. 42 | - **Time Series Chart**: Shows trends in monthly rainfall. 43 | 44 | ## Requirements 45 | 46 | - Access to Google Earth Engine. 47 | - A Google account for using the GEE Code Editor. 48 | 49 | ## Example Visualization 50 | 51 | The interactive map and chart provide insights into Nigeria's rainfall patterns over the years. This data can support: 52 | 53 | - Agricultural planning 54 | - Climate change studies 55 | - Water resource management 56 | 57 | ## License 58 | 59 | This project is open-source and available under the MIT License. Feel free to use and adapt it as needed. 60 | 61 | -------------------------------------------------------------------------------- /Rainfall_analysis_nigeria.js: -------------------------------------------------------------------------------- 1 | // # Rainfall Analysis for Nigeria (2018-2024) 2 | // This script uses Google Earth Engine (GEE) to analyze and visualize rainfall data in Nigeria 3 | // from 2018 to 2024 using the CHIRPS dataset. 4 | 5 | // ## Define Nigeria's Boundary 6 | var nigeria = ee.FeatureCollection("FAO/GAUL/2015/level0") 7 | .filter(ee.Filter.eq('ADM0_NAME', 'Nigeria')); 8 | 9 | // ## Define Time Range 10 | var startDate = '2018-01-01'; 11 | var endDate = '2024-12-31'; 12 | 13 | // ## Load CHIRPS Dataset 14 | var chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY') 15 | .filterDate(startDate, endDate) 16 | .filterBounds(nigeria); 17 | 18 | // ## Calculate Monthly Rainfall 19 | var monthlyRainfall = ee.ImageCollection( 20 | ee.List.sequence(2018, 2024).map(function(year) { 21 | return ee.List.sequence(1, 12).map(function(month) { 22 | var start = ee.Date.fromYMD(year, month, 1); 23 | var end = start.advance(1, 'month'); 24 | return chirps.filterDate(start, end) 25 | .sum() 26 | .set('system:time_start', start.millis()); 27 | }); 28 | }).flatten() 29 | ); 30 | 31 | // ## Mask to Nigeria 32 | var maskedRainfall = monthlyRainfall.map(function(image) { 33 | return image.clip(nigeria); 34 | }); 35 | 36 | // ## Add Rainfall Layer with Color Visualization 37 | var rainfallVis = { 38 | min: 0, 39 | max: 300, 40 | palette: ['lightblue', 'blue', 'yellow', 'orange', 'red'] 41 | }; 42 | 43 | Map.addLayer(maskedRainfall.mean(), rainfallVis, 'Average Rainfall'); 44 | 45 | // ## Generate a Time Series Chart 46 | var chart = ui.Chart.image.series({ 47 | imageCollection: maskedRainfall, 48 | region: nigeria, 49 | reducer: ee.Reducer.mean(), 50 | scale: 5000, 51 | xProperty: 'system:time_start' 52 | }) 53 | .setOptions({ 54 | title: 'Monthly Rainfall in Nigeria (2018-2024)', 55 | hAxis: { title: 'Date' }, 56 | vAxis: { title: 'Rainfall (mm)' }, 57 | legend: { position: 'none' } 58 | }); 59 | 60 | // ## Add Legend to the Map 61 | var legend = ui.Panel({ 62 | style: { 63 | position: 'bottom-left', 64 | padding: '8px 15px' 65 | } 66 | }); 67 | 68 | var legendTitle = ui.Label({ 69 | value: 'Rainfall (mm)', 70 | style: { fontWeight: 'bold', fontSize: '16px', margin: '0 0 4px 0', padding: '0' } 71 | }); 72 | 73 | legend.add(legendTitle); 74 | 75 | var makeColorBar = function(palette) { 76 | return ui.Thumbnail({ 77 | image: ee.Image.pixelLonLat().select(0).multiply((rainfallVis.max - rainfallVis.min) / 100).add(rainfallVis.min), 78 | params: { 79 | bbox: [0, 0, 1, 0.1], 80 | dimensions: '100x10', 81 | min: rainfallVis.min, 82 | max: rainfallVis.max, 83 | palette: palette 84 | }, 85 | style: { stretch: 'horizontal', margin: '0 8px', maxHeight: '20px' } 86 | }); 87 | }; 88 | 89 | var colorBar = makeColorBar(rainfallVis.palette); 90 | legend.add(colorBar); 91 | 92 | var legendLabels = ui.Panel({ 93 | widgets: [ 94 | ui.Label(rainfallVis.min, { margin: '4px 8px' }), 95 | ui.Label((rainfallVis.max / 2).toFixed(0), { margin: '4px 8px', textAlign: 'center', stretch: 'horizontal' }), 96 | ui.Label(rainfallVis.max, { margin: '4px 8px' }) 97 | ], 98 | layout: ui.Panel.Layout.flow('horizontal') 99 | }); 100 | legend.add(legendLabels); 101 | 102 | Map.add(legend); 103 | 104 | // ## Add Layers to the Map 105 | Map.centerObject(nigeria, 6); 106 | Map.addLayer(nigeria, {color: 'blue'}, 'Nigeria'); 107 | 108 | // ## Display the Chart 109 | print(chart); 110 | 111 | // ## Instructions for GitHub 112 | // - Save this file as `rainfall_analysis_nigeria.js`. 113 | // - Add a `README.md` file explaining the script's purpose and usage. 114 | // - Commit and push both files to your GitHub repository. 115 | --------------------------------------------------------------------------------