javascript – Filtering Image Collection by Image ID in Google Earth Engine

filtergoogle-earth-enginejavascript

I'm trying to filter an image collection using not bands within each image of the collection, but by pattern matching in the image ID. Using:

var dataset_2099 = ee.ImageCollection('NASA/NEX-DCP30')
                  .filter(ee.Filter.date('2099-01-01', '2099-12-31'));

we can create an image collection with forecasted climate data. If I, suppose, want to access just the RCP 2.5 data, I'm in a bind because there doesn't seem to be a clear-cut way to filter the image collection based on individual image names, which begin with "rcpXX" where XX may be 26, 45, 60, or 85 depending on the RCP scenario being mapped.

Image ID's can be printed using the following code, where you can see the pattern that I'm describing:

// Image ID listing code by Tyler Erickson
// https://gis.stackexchange.com/a/281489/67264
// Create a list of image objects.
var imageList = dataset_2099.toList(5000);
print('imageList', imageList);
// Extract the ID of each image object.
var id_list = imageList.map(function(item) {
  return ee.Image(item).id();
});
print('id_list', id_list);

The problem is I don't just want to get the names of the images, I want to subset the image collection based on those names.

Best Answer

Alright, I figured it out. Filtering can be done using the image properties (you can see what properties are available by searching for the product in the search bar). In this case, NASA's NEX-DCP30 data comes with a 'scenario' property, so adding a single line of code filters to this level. For example, to access only the RCP 4.5 projections:

var dataset_2099 = ee.ImageCollection('NASA/NEX-DCP30')
                  .filter(ee.Filter.date('2099-01-01', '2099-12-31'))
                  .filterMetadata('scenario','equals','rcp45');

Image property-based filtering can be used for specific models in the NEX-DCP30 collection, so users can specify that they just want to look at CSIRO projections using

.filterMetadata('model','equals','CSIRO-Mk3-6-0')
Related Question