3

Question: How can I get a random sample of images from an image collection?

Background: I am working with the GRIDMET: University of Idaho Gridded Surface Meteorological Dataset which provides daily weather for the continental US from 1979-2015 as an image collection. I am interested in calculating the 90th percentile value for one of the weather variables (specifically ERC) at a large number (30,000) points in Washington and Oregon. The GRIDMET image Collection is daily from 1979-present about 13,000 images, obviously calculating the 90th percentile from all the images is taking a long time. I have already clipped the image collection to only the points of interest. I am looking to randomly sample the image collection to speed up my code.

Current Code:

// import Fire Features and GRIDMET image collection
var fires = ee.FeatureCollection("users/brycekellogg/Fires_test");
var Idaho = ee.ImageCollection("IDAHO_EPSCOR/GRIDMET");

Map.setCenter(-119.905, 45.836, 6); // Center on Oregon.
Map.addLayer(fires);// add the 5 test fire points to the map.

var firefeature = ee.FeatureCollection(fires); // convert test fires into a 
feature collection 

var fullERC = Idaho.select('erc')// select only the ERC values

// Create a funtion to clip each image to the feature collection
var clipFeature = function(image) {
  return image.clipToCollection(firefeature);
};

// Map the clip funtion over the Image Collection 
var fullERCclip= fullERC.map(clipFeature);

//Find the 90th percentile of the image collection
var ercPrecentile90 = fullERCclip.reduce(ee.Reducer.percentile({
  percentiles:[90]
}));

// define function to extract 90th percentile image at points
var find90piErc = function(feature) {
 var ercpi90 = ercPrecentile90.reduceRegion({
    reducer:ee.Reducer.first(),
    geometry: feature.geometry(),
    scale:400
  });
  return feature.set({erc90pi:ercpi90.get('erc_p90')
  });
};

// map function on to the fire features
var firefeature_pi_added = firefeature.map(find90piErc);

// print first feature
print('Fire Features with 90th Percentile', firefeature_pi_added);

Here is the solution that I came up with to select 1000 random images:

var fullERCselect = ee.ImageCollection(fullERC.randomColumn('random',13).sort('random').limit(1000));
3
  • 1
    You've got 4 questions in this post. Can you focus it down to 1 question as per the guidelines in the Tour. Top menu. Commented Aug 3, 2017 at 17:42
  • 1
    Posting code also helps. Commented Aug 3, 2017 at 20:09
  • You should mark this question as closed. Commented Jan 9, 2019 at 14:35

1 Answer 1

2

Here is the solution that I came up with to select 1000 random images:

var fullERCselect = ee.ImageCollection(fullERC.randomColumn('random',13).sort('random').limit(1000));

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.