How to run a Google Earth Engine script locally

143 Views Asked by At

I am new to Google Earth Engine. I have been using the Google Earth Engine code editor to create and run my scripts. However, this approach doesn't scale.

I have a script that gets the precipitation data for a region and exports it as a .csv to Google Drive. I want to know if there is a way to run the script locally rather than on the Google Earth Engine code editor. Instead of storing the .csv output in Google Drive, I can even store it in my local file system if that simplifies things.

var grids = ee.FeatureCollection("users/ramaraja/grids");

var gridCode = 13885;
var grid_13885 = grids.filter(ee.Filter.eq('GRIDCODE',gridCode));

var chirps2021_1 = ee.ImageCollection('UCSB-CHG/CHIRPS/PENTAD')
            .filterDate('2021-01-01', '2021-02-28')
            .filter(ee.Filter.calendarRange(1,2,'month'))
            .filterBounds(grid_13885);

var chirps2021_1_sum = ee.Image(chirps2021_1.sum())

var chirps2021_1_sum_13885 = chirps2021_1_sum.clip(grid_13885);

var precipitationVis = {
  min: 0.0,
  max: 112.0,
  palette: ['001137', '0aab1e', 'e7eb05', 'ff4a2d', 'e90000'],
};

Map.addLayer(chirps2021_1_sum_13885, precipitationVis, "Sum January & February 2021 Precipitation", true, 1.0);

Map.centerObject(grid_13885, 0);

var pixels = chirps2021_1_sum_13885.multiply(10).toInt().reduceToVectors({
  reducer:ee.Reducer.countEvery(),
  geometry: grid_13885,
  scale: 5566,
  geometryType: 'centroid',
  labelProperty: 'precipitation',
  });

var proj = chirps2021_1_sum_13885.select([0]).projection()
var latlon = ee.Image.pixelLonLat()
chirps2021_1_sum_13885 = chirps2021_1_sum_13885.addBands(latlon.select('longitude','latitude'))

pixels=chirps2021_1_sum_13885.select('longitude').reduceRegions(pixels, ee.Reducer.first().setOutputs(['long']), 25)
pixels=chirps2021_1_sum_13885.select('latitude').reduceRegions(pixels, ee.Reducer.first().setOutputs(['lat']), 25);
pixels=chirps2021_1_sum_13885.select('precipitation').reduceRegions(pixels, ee.Reducer.first().setOutputs(['precipitation']), 25);

Map.addLayer(pixels,{}, 'grids')

Export.table.toDrive({
  collection: pixels,
  description: 'grid_13885',
  selectors: ['system:index','precipitation','lat','long',],
  fileFormat: 'CSV'
});

Here's a visualization of the output,

enter image description here

The asset, users/ramaraja/grids is a shapefile I uploaded to Google Earth Engine.

0

There are 0 best solutions below