Seeking Function to calculate red-edgeNDVI in Google Earth Engine?Calculating CIredEdge from Sentinel 2 composite image and adding as Band in Google Earth Explorer?How to calculate forest loss in google earth engineGEE cloud-free Sentinel2 and linear RegressionLinearFit with Google Earth EngineCalculate MSAVI (Modified Soil-adjusted Vegetation Index) in Google Earth EngineGoogle Earth Engine - Map.addLayerGoogle Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskMissing band in mapping function using Google Earth EngineEarth Engine - function for printing multiple histogramsEarth Engine create user defined function with default parametersGoogle Earth Engine formaTrend function

Why is the origin of “threshold” uncertain?

Why does processed meat contain preservatives, while canned fish needs not?

Reverse the word in a string with the same order in javascript

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

What are the spoon bit of a spoon and fork bit of a fork called?

Single Colour Mastermind Problem

Why was Germany not as successful as other Europeans in establishing overseas colonies?

Why do Ichisongas hate elephants and hippos?

Possible to set `foldexpr` using a function reference?

What is the range of this combined function?

Why does nature favour the Laplacian?

Will tsunami waves travel forever if there was no land?

Pulling the rope with one hand is as heavy as with two hands?

Need help understanding harmonic series and intervals

Are Boeing 737-800’s grounded?

Stark VS Thanos

Why do TACANs not have a symbol for compulsory reporting?

Find the coordinate of two line segments that are perpendicular

Binary Numbers Magic Trick

What does YCWCYODFTRFDTY mean?

How to figure out whether the data is sample data or population data apart from the client's information?

Asahi Dry Black beer can

Weird result in complex limit

When did stoichiometry begin to be taught in U.S. high schools?



Seeking Function to calculate red-edgeNDVI in Google Earth Engine?


Calculating CIredEdge from Sentinel 2 composite image and adding as Band in Google Earth Explorer?How to calculate forest loss in google earth engineGEE cloud-free Sentinel2 and linear RegressionLinearFit with Google Earth EngineCalculate MSAVI (Modified Soil-adjusted Vegetation Index) in Google Earth EngineGoogle Earth Engine - Map.addLayerGoogle Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskMissing band in mapping function using Google Earth EngineEarth Engine - function for printing multiple histogramsEarth Engine create user defined function with default parametersGoogle Earth Engine formaTrend function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am trying to calculate the red-edgeNDVI ((NIR – red edge)/(NIR + red edge)) of an Image.Collection in Google Earth Engine. There is a built in function for NDVI but not for red-edge NDVI. The code I have is below but I get the error message "image.NIR is undefined". I'm sure this is a simple syntax issue related to the function but I've tried everything I could think of and I just can't get it to work.



Can you tell me what I'm missing?



/**
* Function to mask clouds using the Sentinel-2 QA band
* @param ee.Image image Sentinel-2 image
* @return ee.Image cloud masked Sentinel-2 image
*/
function maskS2clouds(image)
var qa = image.select('QA60');

// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;

// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));

return image.updateMask(mask)
.divide(10000);


// Load Sentinel-2 TOA reflectance data.
var S2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2017-06-01', '2017-09-30')
// Pre-filter to get less cloudy granules.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
//Select required bands only
.select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
//Apply cloud mask
.map(maskS2clouds);

//Create band variables
var redEdge = S2.select('B5');
var NIR = S2.select('B8');

//Function to calculate redEdgeNDVI
var add_reNDVI = function(image)
var redEdgeNDVI = image.NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
return image.addBands(reNDVI);
;









share|improve this question






























    1















    I am trying to calculate the red-edgeNDVI ((NIR – red edge)/(NIR + red edge)) of an Image.Collection in Google Earth Engine. There is a built in function for NDVI but not for red-edge NDVI. The code I have is below but I get the error message "image.NIR is undefined". I'm sure this is a simple syntax issue related to the function but I've tried everything I could think of and I just can't get it to work.



    Can you tell me what I'm missing?



    /**
    * Function to mask clouds using the Sentinel-2 QA band
    * @param ee.Image image Sentinel-2 image
    * @return ee.Image cloud masked Sentinel-2 image
    */
    function maskS2clouds(image)
    var qa = image.select('QA60');

    // Bits 10 and 11 are clouds and cirrus, respectively.
    var cloudBitMask = 1 << 10;
    var cirrusBitMask = 1 << 11;

    // Both flags should be set to zero, indicating clear conditions.
    var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
    .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

    return image.updateMask(mask)
    .divide(10000);


    // Load Sentinel-2 TOA reflectance data.
    var S2 = ee.ImageCollection('COPERNICUS/S2')
    .filterDate('2017-06-01', '2017-09-30')
    // Pre-filter to get less cloudy granules.
    .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
    //Select required bands only
    .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
    //Apply cloud mask
    .map(maskS2clouds);

    //Create band variables
    var redEdge = S2.select('B5');
    var NIR = S2.select('B8');

    //Function to calculate redEdgeNDVI
    var add_reNDVI = function(image)
    var redEdgeNDVI = image.NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
    return image.addBands(reNDVI);
    ;









    share|improve this question


























      1












      1








      1








      I am trying to calculate the red-edgeNDVI ((NIR – red edge)/(NIR + red edge)) of an Image.Collection in Google Earth Engine. There is a built in function for NDVI but not for red-edge NDVI. The code I have is below but I get the error message "image.NIR is undefined". I'm sure this is a simple syntax issue related to the function but I've tried everything I could think of and I just can't get it to work.



      Can you tell me what I'm missing?



      /**
      * Function to mask clouds using the Sentinel-2 QA band
      * @param ee.Image image Sentinel-2 image
      * @return ee.Image cloud masked Sentinel-2 image
      */
      function maskS2clouds(image)
      var qa = image.select('QA60');

      // Bits 10 and 11 are clouds and cirrus, respectively.
      var cloudBitMask = 1 << 10;
      var cirrusBitMask = 1 << 11;

      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

      return image.updateMask(mask)
      .divide(10000);


      // Load Sentinel-2 TOA reflectance data.
      var S2 = ee.ImageCollection('COPERNICUS/S2')
      .filterDate('2017-06-01', '2017-09-30')
      // Pre-filter to get less cloudy granules.
      .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
      //Select required bands only
      .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
      //Apply cloud mask
      .map(maskS2clouds);

      //Create band variables
      var redEdge = S2.select('B5');
      var NIR = S2.select('B8');

      //Function to calculate redEdgeNDVI
      var add_reNDVI = function(image)
      var redEdgeNDVI = image.NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
      return image.addBands(reNDVI);
      ;









      share|improve this question
















      I am trying to calculate the red-edgeNDVI ((NIR – red edge)/(NIR + red edge)) of an Image.Collection in Google Earth Engine. There is a built in function for NDVI but not for red-edge NDVI. The code I have is below but I get the error message "image.NIR is undefined". I'm sure this is a simple syntax issue related to the function but I've tried everything I could think of and I just can't get it to work.



      Can you tell me what I'm missing?



      /**
      * Function to mask clouds using the Sentinel-2 QA band
      * @param ee.Image image Sentinel-2 image
      * @return ee.Image cloud masked Sentinel-2 image
      */
      function maskS2clouds(image)
      var qa = image.select('QA60');

      // Bits 10 and 11 are clouds and cirrus, respectively.
      var cloudBitMask = 1 << 10;
      var cirrusBitMask = 1 << 11;

      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

      return image.updateMask(mask)
      .divide(10000);


      // Load Sentinel-2 TOA reflectance data.
      var S2 = ee.ImageCollection('COPERNICUS/S2')
      .filterDate('2017-06-01', '2017-09-30')
      // Pre-filter to get less cloudy granules.
      .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
      //Select required bands only
      .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
      //Apply cloud mask
      .map(maskS2clouds);

      //Create band variables
      var redEdge = S2.select('B5');
      var NIR = S2.select('B8');

      //Function to calculate redEdgeNDVI
      var add_reNDVI = function(image)
      var redEdgeNDVI = image.NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
      return image.addBands(reNDVI);
      ;






      google-earth-engine function vegetation-index






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      PolyGeo

      54.1k1782248




      54.1k1782248










      asked Apr 24 at 19:42









      Adam GAdam G

      406




      406




















          1 Answer
          1






          active

          oldest

          votes


















          5














          In your code, S2 is an ImageCollection, so when you "create band variables" you're just getting ImageCollections in which every image inside has only the selected band, which is useful. As you well commented, add_reNDVI is a function that will take every image in the collection and calculate reNDVI. So you have to map that function over the collection to get what you want.



          // Load Sentinel-2 TOA reflectance data.
          var S2 = ee.ImageCollection('COPERNICUS/S2')
          .filterDate('2017-06-01', '2017-09-30')
          // Pre-filter to get less cloudy granules.
          .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
          //Select required bands only
          .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
          //Apply cloud mask
          .map(maskS2clouds);

          //Function to calculate redEdgeNDVI
          var add_reNDVI = function(image)
          //Create band variables
          var redEdge = image.select('B5');
          var NIR = image.select('B8');
          var redEdgeNDVI = NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
          return image.addBands(redEdgeNDVI);
          ;
          var s2_reNDVI = S2.map(add_reNDVI)
          Map.centerObject(s2_reNDVI.first())
          Map.addLayer(s2_reNDVI.first())


          I guess you'll need to filter by bounds at some point, that is why I just took the first image out of the collection to check if it's working






          share|improve this answer























          • Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

            – Adam G
            2 days ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320766%2fseeking-function-to-calculate-red-edgendvi-in-google-earth-engine%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          In your code, S2 is an ImageCollection, so when you "create band variables" you're just getting ImageCollections in which every image inside has only the selected band, which is useful. As you well commented, add_reNDVI is a function that will take every image in the collection and calculate reNDVI. So you have to map that function over the collection to get what you want.



          // Load Sentinel-2 TOA reflectance data.
          var S2 = ee.ImageCollection('COPERNICUS/S2')
          .filterDate('2017-06-01', '2017-09-30')
          // Pre-filter to get less cloudy granules.
          .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
          //Select required bands only
          .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
          //Apply cloud mask
          .map(maskS2clouds);

          //Function to calculate redEdgeNDVI
          var add_reNDVI = function(image)
          //Create band variables
          var redEdge = image.select('B5');
          var NIR = image.select('B8');
          var redEdgeNDVI = NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
          return image.addBands(redEdgeNDVI);
          ;
          var s2_reNDVI = S2.map(add_reNDVI)
          Map.centerObject(s2_reNDVI.first())
          Map.addLayer(s2_reNDVI.first())


          I guess you'll need to filter by bounds at some point, that is why I just took the first image out of the collection to check if it's working






          share|improve this answer























          • Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

            – Adam G
            2 days ago















          5














          In your code, S2 is an ImageCollection, so when you "create band variables" you're just getting ImageCollections in which every image inside has only the selected band, which is useful. As you well commented, add_reNDVI is a function that will take every image in the collection and calculate reNDVI. So you have to map that function over the collection to get what you want.



          // Load Sentinel-2 TOA reflectance data.
          var S2 = ee.ImageCollection('COPERNICUS/S2')
          .filterDate('2017-06-01', '2017-09-30')
          // Pre-filter to get less cloudy granules.
          .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
          //Select required bands only
          .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
          //Apply cloud mask
          .map(maskS2clouds);

          //Function to calculate redEdgeNDVI
          var add_reNDVI = function(image)
          //Create band variables
          var redEdge = image.select('B5');
          var NIR = image.select('B8');
          var redEdgeNDVI = NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
          return image.addBands(redEdgeNDVI);
          ;
          var s2_reNDVI = S2.map(add_reNDVI)
          Map.centerObject(s2_reNDVI.first())
          Map.addLayer(s2_reNDVI.first())


          I guess you'll need to filter by bounds at some point, that is why I just took the first image out of the collection to check if it's working






          share|improve this answer























          • Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

            – Adam G
            2 days ago













          5












          5








          5







          In your code, S2 is an ImageCollection, so when you "create band variables" you're just getting ImageCollections in which every image inside has only the selected band, which is useful. As you well commented, add_reNDVI is a function that will take every image in the collection and calculate reNDVI. So you have to map that function over the collection to get what you want.



          // Load Sentinel-2 TOA reflectance data.
          var S2 = ee.ImageCollection('COPERNICUS/S2')
          .filterDate('2017-06-01', '2017-09-30')
          // Pre-filter to get less cloudy granules.
          .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
          //Select required bands only
          .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
          //Apply cloud mask
          .map(maskS2clouds);

          //Function to calculate redEdgeNDVI
          var add_reNDVI = function(image)
          //Create band variables
          var redEdge = image.select('B5');
          var NIR = image.select('B8');
          var redEdgeNDVI = NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
          return image.addBands(redEdgeNDVI);
          ;
          var s2_reNDVI = S2.map(add_reNDVI)
          Map.centerObject(s2_reNDVI.first())
          Map.addLayer(s2_reNDVI.first())


          I guess you'll need to filter by bounds at some point, that is why I just took the first image out of the collection to check if it's working






          share|improve this answer













          In your code, S2 is an ImageCollection, so when you "create band variables" you're just getting ImageCollections in which every image inside has only the selected band, which is useful. As you well commented, add_reNDVI is a function that will take every image in the collection and calculate reNDVI. So you have to map that function over the collection to get what you want.



          // Load Sentinel-2 TOA reflectance data.
          var S2 = ee.ImageCollection('COPERNICUS/S2')
          .filterDate('2017-06-01', '2017-09-30')
          // Pre-filter to get less cloudy granules.
          .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
          //Select required bands only
          .select('B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'QA60')
          //Apply cloud mask
          .map(maskS2clouds);

          //Function to calculate redEdgeNDVI
          var add_reNDVI = function(image)
          //Create band variables
          var redEdge = image.select('B5');
          var NIR = image.select('B8');
          var redEdgeNDVI = NIR.subtract(redEdge).divide(NIR.add(redEdge)).rename('reNDVI');
          return image.addBands(redEdgeNDVI);
          ;
          var s2_reNDVI = S2.map(add_reNDVI)
          Map.centerObject(s2_reNDVI.first())
          Map.addLayer(s2_reNDVI.first())


          I guess you'll need to filter by bounds at some point, that is why I just took the first image out of the collection to check if it's working







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 24 at 20:16









          Rodrigo E. PrincipeRodrigo E. Principe

          4,57411021




          4,57411021












          • Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

            – Adam G
            2 days ago

















          • Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

            – Adam G
            2 days ago
















          Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

          – Adam G
          2 days ago





          Thanks @Rodrigo. This worked fine. I've posted a follow-up question (gis.stackexchange.com/questions/320967/…). I supect you may be able to answer this one too.

          – Adam G
          2 days ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320766%2fseeking-function-to-calculate-red-edgendvi-in-google-earth-engine%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sum ergo cogito? 1 nng

          419 nièngy_Soadمي 19bal1.5o_g

          Queiggey Chernihivv 9NnOo i Zw X QqKk LpB