├── file1 ├── File2 ├── file3 └── README.md /file1: -------------------------------------------------------------------------------- 1 | // Oil Spill Detection from Sentinel-1 SAR Imagery 2 | 3 | // 1. Define Area of Interest (AOI) 4 | var AOI = ee.Geometry.Polygon([ 5 | [[4.3, 5.8], [4.3, 4.8], [6.0, 4.8], [6.0, 5.8]] 6 | ]); 7 | Map.centerObject(AOI, 9); 8 | 9 | // 2. Load Sentinel-1 SAR GRD Data (VV polarization) 10 | var s1 = ee.ImageCollection('COPERNICUS/S1_GRD') 11 | .filterBounds(AOI) 12 | .filterDate('2023-01-01', '2023-01-31') 13 | .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV')) 14 | .filter(ee.Filter.eq('instrumentMode', 'IW')) 15 | .filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING')) 16 | .select('VV'); 17 | 18 | // 3. Median Composite 19 | var medianVV = s1.median().clip(AOI); 20 | 21 | // 4. Oil Spill Detection (Low backscatter areas) 22 | // Use a threshold for dark pixels indicating oil spill presence 23 | var threshold = -22; // dB (adjust as needed) 24 | var oilSpill = medianVV.lt(threshold); 25 | 26 | // 5. Visualization 27 | var visVV = {min: -30, max: 0}; 28 | Map.addLayer(medianVV, visVV, 'Sentinel-1 VV'); 29 | Map.addLayer(oilSpill.updateMask(oilSpill), {palette: ['red']}, 'Detected Oil Spill'); 30 | 31 | // 6. Optional: Export result 32 | Export.image.toDrive({ 33 | image: oilSpill, 34 | description: 'OilSpillDetection_Jan2023', 35 | scale: 10, 36 | region: AOI, 37 | fileFormat: 'GeoTIFF' 38 | }); 39 | -------------------------------------------------------------------------------- /File2: -------------------------------------------------------------------------------- 1 | import ee 2 | import geemap 3 | import folium 4 | 5 | # Initialize Earth Engine 6 | ee.Initialize() 7 | 8 | # Define Area of Interest (AOI) 9 | aoi = ee.Geometry.Polygon([ 10 | [[4.3, 5.8], [4.3, 4.8], [6.0, 4.8], [6.0, 5.8]] 11 | ]) 12 | 13 | # Load Sentinel-1 Image Collection (VV polarization) 14 | s1_vv = ee.ImageCollection('COPERNICUS/S1_GRD') \ 15 | .filterBounds(aoi) \ 16 | .filterDate('2023-01-01', '2023-01-31') \ 17 | .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV')) \ 18 | .filter(ee.Filter.eq('instrumentMode', 'IW')) \ 19 | .filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING')) \ 20 | .select('VV') 21 | 22 | # Median Composite 23 | vv_median = s1_vv.median().clip(aoi) 24 | 25 | # Oil Spill Detection via Thresholding (dark pixels < -22 dB) 26 | threshold = -22 27 | oil_spill = vv_median.lt(threshold) 28 | 29 | # Visualize 30 | Map = geemap.Map(center=[5.3, 5.0], zoom=9) 31 | Map.addLayer(vv_median, {'min': -30, 'max': 0}, 'Sentinel-1 VV') 32 | Map.addLayer(oil_spill.updateMask(oil_spill), {'palette': 'red'}, 'Oil Spill Detection') 33 | Map 34 | 35 | # Optional: Export image to Google Drive 36 | export_task = ee.batch.Export.image.toDrive( 37 | image=oil_spill, 38 | description='OilSpillDetection_Jan2023', 39 | folder='EarthEngine', 40 | fileNamePrefix='oil_spill_jan2023', 41 | region=aoi, 42 | scale=10, 43 | fileFormat='GeoTIFF' 44 | ) 45 | export_task.start() 46 | -------------------------------------------------------------------------------- /file3: -------------------------------------------------------------------------------- 1 | import ee 2 | import geemap 3 | import folium 4 | 5 | # Initialize the Earth Engine module 6 | ee.Initialize() 7 | 8 | # Define Area of Interest (AOI) 9 | aoi = ee.Geometry.Polygon([ 10 | [[4.3, 5.8], [4.3, 4.8], [6.0, 4.8], [6.0, 5.8]] 11 | ]) 12 | 13 | # Load Sentinel-1 GRD VV polarization 14 | sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD') \ 15 | .filterBounds(aoi) \ 16 | .filterDate('2023-01-01', '2023-01-31') \ 17 | .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV')) \ 18 | .filter(ee.Filter.eq('instrumentMode', 'IW')) \ 19 | .select('VV') \ 20 | .median() \ 21 | .clip(aoi) 22 | 23 | # Create training samples (oil spill and water) 24 | # 0 = non-spill (open water), 1 = spill (dark slick) 25 | oil_points = ee.FeatureCollection([ 26 | ee.Feature(ee.Geometry.Point([5.0, 5.2]), {'class': 1}), 27 | ee.Feature(ee.Geometry.Point([5.1, 5.21]), {'class': 1}), 28 | ee.Feature(ee.Geometry.Point([4.95, 5.18]), {'class': 1}) 29 | ]) 30 | 31 | non_oil_points = ee.FeatureCollection([ 32 | ee.Feature(ee.Geometry.Point([5.4, 5.3]), {'class': 0}), 33 | ee.Feature(ee.Geometry.Point([5.5, 5.32]), {'class': 0}), 34 | ee.Feature(ee.Geometry.Point([5.6, 5.35]), {'class': 0}) 35 | ]) 36 | 37 | # Merge training data 38 | training_points = oil_points.merge(non_oil_points) 39 | 40 | # Sample the Sentinel-1 image at the training point locations 41 | training = sentinel1.sampleRegions( 42 | collection=training_points, 43 | properties=['class'], 44 | scale=10 45 | ) 46 | 47 | # Train the Random Forest classifier 48 | classifier = ee.Classifier.smileRandomForest(numberOfTrees=50).train( 49 | features=training, 50 | classProperty='class', 51 | inputProperties=['VV'] 52 | ) 53 | 54 | # Classify the entire image 55 | classified = sentinel1.classify(classifier) 56 | 57 | # Visualize 58 | Map = geemap.Map(center=[5.3, 5.0], zoom=9) 59 | Map.addLayer(sentinel1, {'min': -30, 'max': 0}, 'Sentinel-1 VV') 60 | Map.addLayer(classified.eq(1).selfMask(), {'palette': 'red'}, 'Oil Spill (RF)') 61 | Map.addLayer(classified.eq(0).selfMask(), {'palette': 'blue'}, 'Non-Spill (RF)') 62 | Map.addLayer(training_points, {}, 'Training Points') 63 | Map 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🛢️ Oil Spill Detection from Satellite Imagery using Sentinel-1 and Random Forest 2 | 3 | This project uses Sentinel-1 Synthetic Aperture Radar (SAR) imagery and Google Earth Engine to detect oil spills in water bodies through supervised classification using the Random Forest algorithm. The method leverages backscatter intensity changes (dark spots) associated with oil slicks. 4 | 📍 Project Objectives 5 | 6 | Detect oil spills from satellite radar imagery 7 | 8 | Use supervised classification with Random Forest 9 | 10 | Generate classified oil spill maps for visualization and export 11 | 12 | Support oil spill monitoring and environmental management in coastal areas 13 | 14 | 🛰️ Data Source 15 | 16 | Satellite: Sentinel-1 GRD 17 | 18 | Band Used: VV polarization (Vertical transmit and receive) 19 | 20 | Temporal Coverage: January 2023 (can be adjusted) 21 | 22 | Area of Interest (AOI): Niger Delta coastal region (editable) 23 | 24 | 🧰 Tools & Technologies 25 | 26 | Google Earth Engine (Python API) 27 | 28 | Python 3.8+ 29 | 30 | geemap, earthengine-api, folium 31 | 32 | 🚀 How to Run 33 | 1. Install Required Packages 34 | 35 | pip install earthengine-api geemap folium 36 | 37 | 2. Authenticate and Initialize Earth Engine 38 | 39 | earthengine authenticate 40 | 41 | 3. Run the Python Script 42 | 43 | Execute the Python script (oil_spill_rf.py) to perform the following: 44 | 45 | Load and pre-process Sentinel-1 SAR imagery 46 | 47 | Label training data (oil spill and open water) 48 | 49 | Train Random Forest classifier 50 | 51 | Classify entire scene 52 | 53 | Visualize classified map and optionally export to Google Drive 54 | 55 | 📊 Sample Output Layers 56 | 57 | Sentinel-1 VV – SAR backscatter intensity 58 | 59 | Oil Spill (RF) – Pixels classified as oil spill (Red) 60 | 61 | Non-Spill (RF) – Pixels classified as open water (Blue) 62 | 63 | 📁 File Structure 64 | 65 | . 66 | ├── oil_spill_rf.py # Main detection script 67 | ├── training_data.geojson # Optional training points (if exporting from GEE) 68 | ├── classified_output.tif # Exported classified map 69 | ├── README.md # Project overview 70 | 71 | 📌 Key Notes 72 | 73 | Oil spills appear as dark patches due to reduced radar backscatter. 74 | 75 | Threshold-based methods are limited; machine learning improves accuracy. 76 | 77 | You can refine the model by adding more training points and bands (e.g., VH). 78 | 79 | Use NDPI or texture features for more robust detection. 80 | 81 | 📚 References 82 | 83 | Solberg, A. H. S., et al. (2007). "Automatic Detection of Oil Spills in ERS SAR Images." IEEE Transactions on Geoscience and Remote Sensing. 84 | 85 | Copernicus Open Access Hub: https://scihub.copernicus.eu/ 86 | 87 | GEE Docs: https://developers.google.com/earth-engine 88 | 89 | 🔐 License 90 | 91 | This project is open-source and available under the MIT License. 92 | --------------------------------------------------------------------------------