I made this code to get a Linear Regression using the function SAVI in my own collection but it is not working.

Does anyone know why?

    // Simple regression of year versus NDVI.

   // Define the start date and position to get images covering SatgeArea,
   // Bolivia, from 2000-2010.
    var start = '2000-01-01';
    var end = '2014-12-31';

    var region = table

    // Filter to Collection
    // time of year to avoid seasonal affects, and for each image create 
     the bands
     // we will regress on:
    // 1. A 1, so the resulting array has a column of ones to capture the 
    // 2. Fractional year past 2000-01-01.
    // 3. SAVI.
   // 4. Mask Clouds
    var col = imageCollection
    .map(function(image) {
      var date = ee.Date(image.get('system:time_start'));
      var yearOffset = date.difference(ee.Date(start), 'year');
      var savi = image.expression(
        '(1 + L) * float(nir - red)/ (nir + red + L)',
          'nir': image.select('B4'),
           'red': image.select('B3'),
           'L': 0.5
          var mask = image.select(['cfmask']).neq((1,2,3,4));


  // Convert to an array. Give the axes names for more readable code.
    var array = col.toArray();
    var imageAxis = 0;
    var bandAxis = 1;

  // Slice off the year and ndvi, and solve for the coefficients.
     var x = array.arraySlice(bandAxis, 0, 2);
     var y = array.arraySlice(bandAxis, 2);
     var fit = x.matrixSolve(y);

 // Get the coefficient for the year, effectively the slope of the long-term
  // NDVI trend.
   var slope = fit.arrayGet([1, 0]).clip(region);


    // Export the image, specifying scale and region.
      image: slope,
      description: 'SAVI_slope_jan',
      scale: 30,
      maxPixels: 1e9,
      region: table

Im using my own collection (images from LE7_SR and LT5_SR) and my own geometry (table). I can map the result (slope) but I cannot download and if I try with a normal collection (ee.ImageCollection) I can. Does anyone know why I cannot download the image from my own collection?

  • Are you getting any errors or is the resulting layer not right? – HDunn Nov 21 '17 at 13:11
  • I cannot download the image (there are no errors). Basically it is downloading the image for ages. – Juan TB Nov 21 '17 at 16:46
  • I can Map.addLayer("result") but I cannot download it. – Juan TB Nov 21 '17 at 16:46
  • Use Export.image. If it fails, report back with the error message. If not, wait... – Nicholas Clinton Nov 22 '17 at 1:14
  • I am using Export.image.toDrive and it fails. – Juan TB Nov 22 '17 at 10:44

Your Answer

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

Browse other questions tagged or ask your own question.