TransWikia.com

Error generating chart: User memory limit exceeded, when changing dataset from T1_TOA to T1_SR

Geographic Information Systems Asked by WhitmanCD on March 9, 2021

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'}));

2 Answers

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.

Answered by AdoMath on March 9, 2021

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']);
}

Answered by AdoMath on March 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP