0

I am mapping annual rainfall in the Eastern Sahel. I have a wide colour palette which allows me to see approx rainfall p.a. within the region of interest (not elegant, but sufficient) (Image 1). My problem is that when I try to export the map to an asset it loses the palette. (Image 2) I have also tried using visualize() but without success. Any advice?

var chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/PENTAD");

// Use GAUL Administrative Boundaries dataset - Admin1 dataset with district boundaries
// Set focus on the Eastern Sahel (Sudan and Eritrea)
var gaul = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1")
var Sahel = gaul.filter(ee.Filter.inList('ADM0_NAME', ['Eritrea','Sudan']))
// Overlay the district boundaries for the state
Map.addLayer(Sahel, {color: '#000000', width: 3}, 'Admin1 Boundaries')

var filtered = chirps.filter(ee.Filter.date('2020-01-01', '2020-12-31')) 

//Find cumulative rainfall
var total = filtered.reduce(ee.Reducer.sum())
//print (total) 

// Clip the classified image to the regional boundary
var SahelRainfall = total.clip(Sahel)
Map.addLayer(SahelRainfall, {min:0, max:1000, palette: ['#ff0000','#ff5300','#ffa500','#ffd200','#ffff00','#80c000','#008000','#004080',
'#0000ff','#2600c1','#4b0082']}, 'Sahel Rainfall')

// Specify area to clip and export.
var geometry = Sahel;
Export.image.toAsset({
  image: SahelRainfall,
  description: 'imageExport',
  assetId: 'rf',
  region: Sahel,

});

Map renders as follows:

Export renders like this:

2 Answers 2

0

visualize() is the missing piece as you have noticed — it is built into Map.addLayer but not Export operations. Here is an example of using it — I simply moved the parameters from addLayer into the visualize() call. Now the export should export the same results.

var SahelRainfallVis = SahelRainfall.visualize({
  min: 0,
  max: 1000,
  palette: ['#ff0000','#ff5300','#ffa500','#ffd200','#ffff00','#80c000','#008000','#004080',
'#0000ff','#2600c1','#4b0082']
});

Map.addLayer(SahelRainfallVis, {}, 'Sahel Rainfall');

Export.image.toAsset({
  image: SahelRainfallVis,
  description: 'imageExport',
  assetId: 'rf',
  region: Sahel,
});

(However, this will not include the original data bands in the asset. You could SahelRainfallVis.addBands(SahelRainfall) to do that.)

1
  • I think the issue is one of how I am using the asset which is to copy and paste into a document - this doesn't seem to work. However, if I export to Drive, then it renders correctly. Commented Jan 4, 2023 at 22:07
-2

In case you are wanting to preserve both the underlying data in the precipitation_sum band and also add your color map.

code link: https://code.earthengine.google.com/7f54e91193ff790274b8b86cade147c5

2
  • Thanks @kwgeo. Unfortunately, when I run it, both exported images still look like image 2 from my OP. They don't have the map-rendered palette. Does the script work for you? Commented Jan 3, 2023 at 21:01
  • Are you importing the images back into the script? For the exported image with the visualization bands added to them, you can then do Map.addLayer(image,{bands:['vis-red','vis-green','vis-blue']},'Exported image'), which is demonstrated at the bottom inside my code link. What @KevinReid explains about using addBands() is included in my code link.
    – kwgeo
    Commented Jan 4, 2023 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.