2

So, I got the code to work for T1_TOA band, but then when I switched it over to T1_SR band it gave me this error: User memory limit exceeded. So, I poked around the forum and found the code to limit my date frames, but I still get the error. Not quite sure what I'm missing.

// Import the Landsat 8 SR image collecton.

Map.addLayer(study_area, {color: 'Black'}, "study_area");

function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterBounds(study_area)
                  .map(maskL8sr)
                  .select('B5' , 'B4');
print(dataset);

var startDate = ee.Date('2013-05-01'); // set analysis start time
var endDate = ee.Date('2013-9-30'); // set analysis end time


// 'Reduce' stack of images by using the median value for each pixel and clip to study area
var output_bands = dataset.reduce(ee.Reducer.median()).clip(study_area);
print(output_bands)
// 
var index = output_bands.normalizedDifference(['B5_median', 'B4_median']); // NDVI calculated using NIR and red bands
print(index); // DISPLAY metadata

// DISPLAY output band
Map.addLayer(index, {}, 'NDVI');



print(ui.Chart.image.series({
  imageCollection: index,
  region: study_area,
  reducer: ee.Reducer.median(),
  scale: 30
}).setOptions({title: 'Cloud-masked NDVI over time'}));
7
  • Could you upload the full script via a link or provide the study_area variable. Without it, it's hard to know what causes an issue for you.
    – AdoMath
    Jan 26, 2021 at 9:39
  • code.earthengine.google.com/…
    – WhitmanCD
    Jan 27, 2021 at 5:12
  • Let me know if the link doesn't work
    – WhitmanCD
    Jan 27, 2021 at 5:13
  • The link doesn't work. The repository "users/brianwhitmancd/Imagery" does not exists, maybe you have moved the script or saved it in another repository.
    – AdoMath
    Jan 27, 2021 at 9:38
  • I'm not sure how to share the shapefile, but it's a watershed that is about 30,000 acres (121 km2).
    – WhitmanCD
    Jan 28, 2021 at 6:29

2 Answers 2

2

From looking at your code I see you haven't specified the time for your dataset. You defined the startDateand endDate, but haven't applied them in the collection.

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterBounds(study_area)
                  .filterDate('2013-05-01','2013-09-30')
                  .map(maskL8sr)
                  .select('B5' , 'B4');
print(dataset);

Notice that I removed the startDate and endDate variables and instead specified the time interval in the imagecollection using filterDate().

It's important to keep in mind that when you switch from one dataset to another (in this case Landsat 8 TOA to Landsat 8 SR), you might have different amount images. That's why filtering for your specific needs is important to carry out correctly.

1
  • So, putting in the filter date gave me an error stating no features contain non-null values of "system:time_start". I tried changing date and a few other ideas I got from poking around, but can't seem to figure it out.
    – WhitmanCD
    Feb 2, 2021 at 20:56
1

To answer to your comment, "system:time_start" error appears because after running the cloud mask, your dataset loses the metadata info. Try using .copyProperties() command in the cloudmask function like so:

function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask).copyProperties(image,['system:time_start']);
}
1
  • Same message again. Dang, did you get it to work on your end? I tried it a couple different ways and couldn't get it. The NDVI image shows up, it's just the chart doesn't...
    – WhitmanCD
    Feb 4, 2021 at 0:17

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.