I have this small code for getting nightlight image for a particular city using VIIRS Nighttime dataset.

var district = ee.FeatureCollection('ft:1PA2zwArj8EsplrX9eMxJ2H_TICyyx855KPnbJhC1','geometry')
var nighttime = ee.Image(ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG')
              .filterDate('2013-05-01', '2017-05-31')
var nighttimeVis = {min: 0.0, max: 60.0};
Map.addLayer(nighttime.clip(district), nighttimeVis, 'Nighttime');

Now I wish to export this image to my Google Drive. Usually I use the following script for exporting:

  image: nighttime.clip(district),
  description: 'Nighttime_Image',
  maxPixels: 499295920080,
  scale: 30,
  region: district

But for this particular image, I need to specify the min and max values like I have done while using Map.addlayer (for viewing the image) by using nighttimeVis vector. How can I specify the same max and min before or in my Export command for this image?

  • Do you want to mask all values below and above those values? Or do you want to scale your image such that all values above 60 will be set to 60, and all values below 0 will be set to 0?
    – Kuik
    Feb 12, 2019 at 11:04
  • @Kuik This is what the Visualisation parameters do in Map.addlayer do developers.google.com/earth-engine/image_visualization. I want a similar functionality, to map my 0-60 values between 0 and 255.
    – scottstots
    Feb 12, 2019 at 14:08

1 Answer 1


Probably, you'd like something like this:

// Scale the image between 0 and 255 
// based on: min = 0, max = 60
var scaled = nighttime.unitScale(0, 60).multiply(255).toByte();
Map.addLayer(scaled.clip(district), {min: 0, max: 255}, 'Nighttime');

By adding toByte(), you image is stored as a 8-bit integer which would save you some storage space, but you could remove that to keep floating values. Note that now values above 60 are all saved as 255 values. But I think that is what you want.

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.