Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with ee$List and iteration over imageCollection #343

Open
Remotsensei opened this issue Aug 7, 2023 · 0 comments
Open

issue with ee$List and iteration over imageCollection #343

Remotsensei opened this issue Aug 7, 2023 · 0 comments

Comments

@Remotsensei
Copy link

  • rgee version: 1.1.6.9999
  • R version 4.2.1 (2022-06-23 ucrt)
  • Platform: x86_64-w64-mingw32/x64 (64-bit)
  • Running under: Windows 10 x64 (build 19045)
  • Python config:
  • version: 3.10.9 | packaged by conda-forge | (main, Jan 11 2023, 15:15:40) [MSC v.1916 64 bit (AMD64)]
  • Architecture: 64bit
  • numpy_version: 1.24.3

Description

As for the issue issue with get on ee$List #232
i am trying to replicate an iteration loop similar to that provided in the GEE examples https://developers.google.com/earth-engine/guides/ic_iterating

following the issue above , i changed the script adding 'list' to the calls to ee$List
this works but only for the first iteration. at the second one it gives errors

# Load MODIS EVI imagery 
 collection =  ee$ImageCollection('MODIS/006/MYD13A1') $select('EVI');

# Define reference conditions from the first 10 years of data 
 reference = collection $filterDate('2001-01-01', '2010-12-31')$
# Sort chronologically in descending order 
 sort('system:time_start', FALSE);

# Compute the mean of the first 10 years 
 mean = reference$mean();

# Compute anomalies by subtracting the 2001-2010 mean from each image in a
# collection of 2011-2014 images .Copy the date metadata over to the
# computed anomaly images in the new collection 
 series = collection$filterDate('2011-01-01', '2014-12-31')$map(function(image) {
  return (image$subtract(mean)$set('system:time_start', image $get('system:time_start')))
});


# Get the timestamp from the most recent image in the reference collection 
 time0 = reference$first()$get('system:time_start');

# Use imageCollection $iterate() to make a collection of cumulative anomaly over time 
# The initial value for iterate() is a list of anomaly images already processed 
# The first anomaly image in the list is just 0, with the time0 timestamp 
 first =  ee$List(
  # Rename the first band 'EVI' 
   ee$Image(0)$set('system:time_start', time0)$rename('EVI'));

# This is a function to pass to Iterate() 
# As anomaly images are computed, add them to the list 
 accumulate = function(image, list1) {
  # Get the latest cumulative anomaly image from the end of the list with
  # get(-1).Since the type of the list argument to the function is unknown,
  # it needs to be cast to a List. Since the return type of get() is unknown,
  # cast it to Image 
   previous =  ee$Image(ee$List(list(list1))$get(-1))
   # Add the current anomaly to make a new cumulative anomaly image 
  
   added = image$add(previous)$
  # Propagate metadata to the new image 
   set('system:time_start', image$get('system:time_start'));
  # Return the list with the cumulative anomaly inserted 
  return  ((ee$List(list(list1)))$add(added))
};
 
# Create an ImageCollection of cumulative anomaly images by iterating 
# Since the return type of iterate is unknown, it needs to be cast to a List 
 cumulative =  ee$ImageCollection(ee$List(series$iterate(accumulate, first)))
 cumulative$getInfo()
 

Error

Error: ee.ee_exception.EEException: Image.add, argument 'image2': Invalid type.
Expected type: Image.
Actual type: List<Image<[EVI]>>.
Actual value: [<Image<[EVI]>>, <Image<[EVI]>>]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant