apply a function over 2 consecutive images in an imageCollection in google earth enginePixel values Google Earth EngineExporting all images in a Google Earth Engine image collection (Google Earth Engine API)Supervised Classification with the Google Earth EngineLab 2 Google Earth Engine - Image.select errorGoogle App Engine and Google Earth Engine in Windowsgoogle earth engine: ee.List() output as an integer?Calculating the area of classified pixels in google earth engineDigitize Points in Google Earth EngineGoogle Earth Engine - RGB image export from ImageCollection Python APIArray in Google Earth Engine

Ordering a list of integers

“T” in subscript in formulas

Is first Ubuntu user root?

When calculating a force, why do I get different result when I try to calculate via torque vs via sum of forces at an axis?

Why is there a difference between predicting on Validation set and Test set?

Book with the Latin quote 'nihil superbus' meaning 'nothing above us'

Does ostensible/specious make sense in this sentence?

How is linear momentum conserved in case of a freely falling body?

How does the OS tell whether an "Address is already in use"?

What is a natural problem in theory of computation?

Handling Disruptive Student on the Autism Spectrum

Add 2 new columns to existing dataframe using apply

Anyone else seeing white rings in the Undead parish?

Macro inserted via everypar in obeylines context doesn't see some commands

Can RMSE and MAE have the same value?

Rent contract say that pets are not allowed. Possible repercussions if bringing the pet anyway?

Can $! cause race conditions when used in scripts running in parallel?

How many birds in the bush?

Who was the most successful German spy against Great Britain in WWII, from the contemporary German perspective?

Duplicate instruments in unison in an orchestra

Architectural feasibility of a tiered circular stone keep

"There were either twelve sexes or none."

When, exactly, does the Rogue Scout get to use their Skirmisher ability?

How to maximize the drop odds of the Essences in Diablo II?



apply a function over 2 consecutive images in an imageCollection in google earth engine


Pixel values Google Earth EngineExporting all images in a Google Earth Engine image collection (Google Earth Engine API)Supervised Classification with the Google Earth EngineLab 2 Google Earth Engine - Image.select errorGoogle App Engine and Google Earth Engine in Windowsgoogle earth engine: ee.List() output as an integer?Calculating the area of classified pixels in google earth engineDigitize Points in Google Earth EngineGoogle Earth Engine - RGB image export from ImageCollection Python APIArray in Google Earth Engine






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








0















the function .map applies a function to every individual image in an ImageCollection. And the function .iterate applies a function to one image and the output of the calculation done to the precedent image on an ImageCollection.
The first only works with one image each time, and the second implies modifying each image and utilize it to any calculation with the next one.



I need a function that works like .iterate, but does not modify the precedent image. I just need to do:
image (time -1) / image (time 0).
I can not find a way to do it,



thanks for your help



i have tried,



var first = ee.List([
ee.Image(1).set('system:time_start', time0).select([0], ['pc1'])
]);

var changeDET = function(image, list)
var previous = ee.Image(ee.List(list).get(-1));
var change = previous.divide(image.select('pc1'))
.set('system:time_start', image.get('system:time_start'));

return ee.List(list).add(change);
;

var cumulative = ee.ImageCollection(ee.List(imageCollection.iterate(changeDET, first)))
.sort('system:time_start', false)









share|improve this question






























    0















    the function .map applies a function to every individual image in an ImageCollection. And the function .iterate applies a function to one image and the output of the calculation done to the precedent image on an ImageCollection.
    The first only works with one image each time, and the second implies modifying each image and utilize it to any calculation with the next one.



    I need a function that works like .iterate, but does not modify the precedent image. I just need to do:
    image (time -1) / image (time 0).
    I can not find a way to do it,



    thanks for your help



    i have tried,



    var first = ee.List([
    ee.Image(1).set('system:time_start', time0).select([0], ['pc1'])
    ]);

    var changeDET = function(image, list)
    var previous = ee.Image(ee.List(list).get(-1));
    var change = previous.divide(image.select('pc1'))
    .set('system:time_start', image.get('system:time_start'));

    return ee.List(list).add(change);
    ;

    var cumulative = ee.ImageCollection(ee.List(imageCollection.iterate(changeDET, first)))
    .sort('system:time_start', false)









    share|improve this question


























      0












      0








      0








      the function .map applies a function to every individual image in an ImageCollection. And the function .iterate applies a function to one image and the output of the calculation done to the precedent image on an ImageCollection.
      The first only works with one image each time, and the second implies modifying each image and utilize it to any calculation with the next one.



      I need a function that works like .iterate, but does not modify the precedent image. I just need to do:
      image (time -1) / image (time 0).
      I can not find a way to do it,



      thanks for your help



      i have tried,



      var first = ee.List([
      ee.Image(1).set('system:time_start', time0).select([0], ['pc1'])
      ]);

      var changeDET = function(image, list)
      var previous = ee.Image(ee.List(list).get(-1));
      var change = previous.divide(image.select('pc1'))
      .set('system:time_start', image.get('system:time_start'));

      return ee.List(list).add(change);
      ;

      var cumulative = ee.ImageCollection(ee.List(imageCollection.iterate(changeDET, first)))
      .sort('system:time_start', false)









      share|improve this question














      the function .map applies a function to every individual image in an ImageCollection. And the function .iterate applies a function to one image and the output of the calculation done to the precedent image on an ImageCollection.
      The first only works with one image each time, and the second implies modifying each image and utilize it to any calculation with the next one.



      I need a function that works like .iterate, but does not modify the precedent image. I just need to do:
      image (time -1) / image (time 0).
      I can not find a way to do it,



      thanks for your help



      i have tried,



      var first = ee.List([
      ee.Image(1).set('system:time_start', time0).select([0], ['pc1'])
      ]);

      var changeDET = function(image, list)
      var previous = ee.Image(ee.List(list).get(-1));
      var change = previous.divide(image.select('pc1'))
      .set('system:time_start', image.get('system:time_start'));

      return ee.List(list).add(change);
      ;

      var cumulative = ee.ImageCollection(ee.List(imageCollection.iterate(changeDET, first)))
      .sort('system:time_start', false)






      google-earth-engine






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 19:15









      javierjavier

      135 bronze badges




      135 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0















          What you can do is to convert your imageCollection into a ee.List object, then map over that list with an index variable to access the previous image. Example code is below:



          var length = yourImageCollection.size();
          var list = yourImageCollection.toList(length);

          var calculated_list = list.map(function(img)
          var index = list.indexOf(img)
          img = ee.Image(img);
          var previousIndex = ee.Algorithms.If(index.eq(0), index, index.subtract(1));
          var previousImage = ee.Image(list.get(previousIndex)):
          var change = ee.Image(previousImage.divide(img)
          .copyProperties(img, ["system:time_start"]));
          return change;
          )


          I'm not sure what you want to do with the first image, so when map function reach the first image, previousIndex will equal to index. In other words, the first image will be divided by itself (as there is no image before it).



          Hope this helps.






          share|improve this answer

























          • thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

            – javier
            Mar 28 at 13:53











          • @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

            – Kevin
            Mar 29 at 10:37











          • thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

            – javier
            Mar 29 at 14:42











          • Your original answer works perfect, thanks!

            – javier
            Mar 29 at 14:42










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f55384915%2fapply-a-function-over-2-consecutive-images-in-an-imagecollection-in-google-earth%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









          0















          What you can do is to convert your imageCollection into a ee.List object, then map over that list with an index variable to access the previous image. Example code is below:



          var length = yourImageCollection.size();
          var list = yourImageCollection.toList(length);

          var calculated_list = list.map(function(img)
          var index = list.indexOf(img)
          img = ee.Image(img);
          var previousIndex = ee.Algorithms.If(index.eq(0), index, index.subtract(1));
          var previousImage = ee.Image(list.get(previousIndex)):
          var change = ee.Image(previousImage.divide(img)
          .copyProperties(img, ["system:time_start"]));
          return change;
          )


          I'm not sure what you want to do with the first image, so when map function reach the first image, previousIndex will equal to index. In other words, the first image will be divided by itself (as there is no image before it).



          Hope this helps.






          share|improve this answer

























          • thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

            – javier
            Mar 28 at 13:53











          • @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

            – Kevin
            Mar 29 at 10:37











          • thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

            – javier
            Mar 29 at 14:42











          • Your original answer works perfect, thanks!

            – javier
            Mar 29 at 14:42















          0















          What you can do is to convert your imageCollection into a ee.List object, then map over that list with an index variable to access the previous image. Example code is below:



          var length = yourImageCollection.size();
          var list = yourImageCollection.toList(length);

          var calculated_list = list.map(function(img)
          var index = list.indexOf(img)
          img = ee.Image(img);
          var previousIndex = ee.Algorithms.If(index.eq(0), index, index.subtract(1));
          var previousImage = ee.Image(list.get(previousIndex)):
          var change = ee.Image(previousImage.divide(img)
          .copyProperties(img, ["system:time_start"]));
          return change;
          )


          I'm not sure what you want to do with the first image, so when map function reach the first image, previousIndex will equal to index. In other words, the first image will be divided by itself (as there is no image before it).



          Hope this helps.






          share|improve this answer

























          • thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

            – javier
            Mar 28 at 13:53











          • @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

            – Kevin
            Mar 29 at 10:37











          • thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

            – javier
            Mar 29 at 14:42











          • Your original answer works perfect, thanks!

            – javier
            Mar 29 at 14:42













          0














          0










          0









          What you can do is to convert your imageCollection into a ee.List object, then map over that list with an index variable to access the previous image. Example code is below:



          var length = yourImageCollection.size();
          var list = yourImageCollection.toList(length);

          var calculated_list = list.map(function(img)
          var index = list.indexOf(img)
          img = ee.Image(img);
          var previousIndex = ee.Algorithms.If(index.eq(0), index, index.subtract(1));
          var previousImage = ee.Image(list.get(previousIndex)):
          var change = ee.Image(previousImage.divide(img)
          .copyProperties(img, ["system:time_start"]));
          return change;
          )


          I'm not sure what you want to do with the first image, so when map function reach the first image, previousIndex will equal to index. In other words, the first image will be divided by itself (as there is no image before it).



          Hope this helps.






          share|improve this answer













          What you can do is to convert your imageCollection into a ee.List object, then map over that list with an index variable to access the previous image. Example code is below:



          var length = yourImageCollection.size();
          var list = yourImageCollection.toList(length);

          var calculated_list = list.map(function(img)
          var index = list.indexOf(img)
          img = ee.Image(img);
          var previousIndex = ee.Algorithms.If(index.eq(0), index, index.subtract(1));
          var previousImage = ee.Image(list.get(previousIndex)):
          var change = ee.Image(previousImage.divide(img)
          .copyProperties(img, ["system:time_start"]));
          return change;
          )


          I'm not sure what you want to do with the first image, so when map function reach the first image, previousIndex will equal to index. In other words, the first image will be divided by itself (as there is no image before it).



          Hope this helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 5:01









          KevinKevin

          1331 gold badge1 silver badge8 bronze badges




          1331 gold badge1 silver badge8 bronze badges















          • thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

            – javier
            Mar 28 at 13:53











          • @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

            – Kevin
            Mar 29 at 10:37











          • thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

            – javier
            Mar 29 at 14:42











          • Your original answer works perfect, thanks!

            – javier
            Mar 29 at 14:42

















          • thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

            – javier
            Mar 28 at 13:53











          • @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

            – Kevin
            Mar 29 at 10:37











          • thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

            – javier
            Mar 29 at 14:42











          • Your original answer works perfect, thanks!

            – javier
            Mar 29 at 14:42
















          thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

          – javier
          Mar 28 at 13:53





          thanks, @Kevin. Before I try it, actually the problem that you mentioned was the next one. I always get an imageCollection with the first (or possibly the last if sorted backward) with an image I don't want. How can I filter the collection without that image? there is not an ee.Filter.first function. thanks

          – javier
          Mar 28 at 13:53













          @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

          – Kevin
          Mar 29 at 10:37





          @javier, if the image you want to filter out does not share its date with other images, you can filter it using filterDate method of imageCollection. Note that this can only be done if that image is either the first or the last image by date.

          – Kevin
          Mar 29 at 10:37













          thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

          – javier
          Mar 29 at 14:42





          thanks @Kevin, i have thought of that solution, but, i will filter also on the images of interest, since they share the date.

          – javier
          Mar 29 at 14:42













          Your original answer works perfect, thanks!

          – javier
          Mar 29 at 14:42





          Your original answer works perfect, thanks!

          – javier
          Mar 29 at 14:42








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f55384915%2fapply-a-function-over-2-consecutive-images-in-an-imagecollection-in-google-earth%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript