I am working with the NASA/NEX-DCP30 downscaled climate data.

Ideally, I would like to set a threshold for two bands - pr (precipitation) and tasmax (maximum temperature) and filter it to display where those are both met in a given year (e.g. tasmax > 300 AND pr < .0001 for 1995) both visually and ultimately export as a raster and do some charts of how many times it occurred in a year.

Here was my best attempt, maps look nice but it doesn't account for both pr AND tasmax in the same layer...

var collection = ee.ImageCollection('NASA/NEX-DCP30')
    .filterDate('1994-01-01', '1995-12-31')
var maxtemp = collection.select(['tasmax']);
var precipitation = collection.select(['pr']);
    {'min': 286, 'max': 310, palette: '000000, 00FF00'}, 'MaxTemp');
    {'min': 0, 'max': .000025, palette: '0000FF, FF0000'}, 'Precipitation');

The approach that you want to take is:

  1. Define your collection of daily images.
  2. Write a function that works on individual images, and masks out data that does not meet the criteria you provide.
  3. Map the function across all images in your collection.
  4. Display a count of the data that is not masked out.

The following Earth Engine JavaScript code implements this logic:

var tasmax_threshold = 300; var pr_threshold = 0.0001;

// Create a function that masks out data that does not meet the
// specified thresholds.
var MaskDailyImage = function(img) {
  var mask = img.select('tasmax').gt(tasmax_threshold)
  return img.updateMask(mask); 

var collection = ee.ImageCollection('NASA/NEX-DCP30')
    .filterDate('1995', '1996');
// Map the masking function over all images in the collection.
var filtered = collection.map(MaskDailyImage);
// Create a mask for where there is any valid data.
var data_mask = collection.count().gt(0);
var filtered_count = filtered.count();
// Make sure zero counts are not masked out.
filtered_count = filtered_count.mask(data_mask.mask());
  {bands:'tasmax', 'min': 0, 'max': 300, palette: '000000, FFFFFF'},
  'count of occurrence'

This following link is a shortcut for producing the code above: https://code.earthengine.google.com/065b73a54c25127fb640b875fe7da676

  • Thank you so much for such a helpful and clear response. I truly appreciate it. – Tim Aug 31 '16 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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