GEE Tutorials

Google Earth Engine Tutorial: Download Rainfall Data as CSV

Credit: Youtube Channel “Terra Spatial, Guide on generating random sample points and downloading rainfall data in CSV format for analysis.”

You can see all the tutorials from here: Techgeo Academy.

Introduction

Google Earth Engine (GEE) is a powerful platform for planetary-scale geospatial analysis, and it allows users to access and process global datasets, including rainfall data. This tutorial will guide you on how to download rainfall data as a CSV file using GEE.

Prerequisites

To follow this guide, ensure you have:

Step 1: Open Google Earth Engine Code Editor

Launch the Google Earth Engine Code Editor and authenticate your account if prompted. This will allow access to the platform’s datasets and tools.

Step 2: Import Suitable Rainfall Dataset

Use a precipitation dataset such as ERA5 (European Centre for Medium-Range Weather Forecasts) or CHIRPS (Climate Hazards Group Infra-Red Precipitation with Stations). Example code for ERA5:


var dataset = ee.ImageCollection("ECMWF/ERA5_LAND/DAILY_AGGR");
var rainfall = dataset.select('discharge');

Step 3: Filter the Dataset

Define a date range and region of interest (ROI) for your analysis. Adjust the start and end dates and ROI coordinates as needed:


var roi = ee.Geometry.Rectangle([longitude1, latitude1, longitude2, latitude2]);
var filtered = rainfall.filterDate('2020-01-01', '2021-01-01')
                       .filterBounds(roi);

Step 4: Convert Data to CSV Format

Create a function to extract and format the data for CSV output. Example:


function toCsv(image) {
  return image.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: roi,
    scale: 1000,
    maxPixels: 1e9
  }).toCloudStorage({
    description: 'rainfall_csv',
    bucket: 'your-bucket-name',
    fileNamePrefix: 'rainfall_data',
    fileFormat: 'CSV'
  });
}

Step 5: Export and Download

Call the function and check the output in the cloud storage. Use the following code to trigger the export:


filtered.evaluate(toCsv);

After exporting, download the CSV file from your cloud storage (e.g., Google Cloud Storage or your Drive).

FAQ

Q: Can I use a different rainfall dataset?

A: Yes, replace ‘ECMWF/ERA5_LAND/DAILY_AGGR’ with another dataset ID, such as ‘CHIRPS/2.0/daily’ for CHIRPS data.

Q: What if the dataset is too large to process?

A: Use reset() or mosaic() to reduce the dataset size and optimize performance.

Q: How do I handle different CSV file formats?

A: Adjust the function to define headers, delimiter, or include additional parameters like format or columns.

Q: Does GEE support exporting to local machines directly?

A: No, GEE exports must be saved in cloud storage first (Google Drive, Cloud Storage, etc.) and then downloaded manually.

Q: How accurate is rainfall data from these sources?

A: Accuracy depends on the dataset. Era5 is based on models, while CHIRPS combines satellite and station data for higher precision in regions with ground measurements.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *