Function to calculate red-edgeNDVI in Google Earth Engine Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraGEE 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 parametersEarth Engine how to avoid timeout for buffer calculation?Google Earth Engine formaTrend function

Seek and ye shall find

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Retract an already submitted recommendation letter (written for an undergrad student)

Is there any hidden 'W' sound after 'comment' in : Comment est-elle?

All ASCII characters with a given bit count

Is Diceware more secure than a long passphrase?

What is the term for a person whose job is to place products on shelves in stores?

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

As an international instructor, should I openly talk about my accent?

What's parked in Mil Moscow helicopter plant?

Married in secret, can marital status in passport be changed at a later date?

c++ diamond problem - How to call base method only once

How to count in linear time worst-case?

Is Bran literally the world's memory?

Putting Ant-Man on house arrest

Implementing 3DES algorithm in Java: is my code secure?

What to do with someone that cheated their way through university and a PhD program?

Why did Israel vote against lifting the American embargo on Cuba?

Why does the Cisco show run command not show the full version, while the show version command does?

Book with legacy programming code on a space ship that the main character hacks to escape

Is this homebrew racial feat, Stonehide, balanced?

What was Apollo 13's "Little Jolt" after MECO?

PIC mathematical operations weird problem



Function to calculate red-edgeNDVI in Google Earth Engine



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraGEE 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 parametersEarth Engine how to avoid timeout for buffer calculation?Google 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. Any GEE/java experts who can 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. Any GEE/java experts who can 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. Any GEE/java experts who can 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. Any GEE/java experts who can 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










      asked 3 hours ago









      Adam GAdam G

      262




      262




















          1 Answer
          1






          active

          oldest

          votes


















          3














          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























            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%2ffunction-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









            3














            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



























              3














              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

























                3












                3








                3







                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 3 hours ago









                Rodrigo E. PrincipeRodrigo E. Principe

                4,54111021




                4,54111021



























                    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%2ffunction-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

                    Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

                    Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                    How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2