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;
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
add a comment |
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
add a comment |
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
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
google-earth-engine
asked Mar 27 at 19:15
javierjavier
135 bronze badges
135 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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 anee.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 usingfilterDate
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 anee.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 usingfilterDate
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
add a comment |
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.
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 anee.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 usingfilterDate
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
add a comment |
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.
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.
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 anee.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 usingfilterDate
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
add a comment |
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 anee.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 usingfilterDate
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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