1

I am new to Google Earth Engine.

I have a program for Atmosphere Monitoring. I have managed to pull data for historical data. However, I can't pull recent data e.g. (a couple of days, today , yesterday etc.), I get error:

Collection.toList: The value of 'count' must be positive. Got: 0.

As it says 'Near-Real-Time' that mean that the data must update many times a day? My final goal is to be able to pull data in (near) real time so that I can this data through some other program visualize it. Is that possible?

var pt = ee.Geometry.Point(23.72801716860135,37.984115295446216);

Map.centerObject(pt,14);
Map.addLayer(pt);

var starDate = '2023-02-20';
var endDate = '2023-02-21';

var Monthly = ee.ImageCollection('ECMWF/CAMS/NRT').select('total_aerosol_optical_depth_at_550nm_surface')
  .filterDate(starDate, endDate);

print(Monthly);

var allDates = ee.List(Monthly.aggregate_array('system:time_start'));

var allDatesSimple = allDates.map(function(date){
  return ee.Date(date).format().slice(0,10);
  });

//print(allDatesSimple);

var getTemp = function(image) {

  // Reducing region and getting value
  var value_tmmx = ee.Image(image)
    .reduceRegion(ee.Reducer.first(), pt)
    .get('total_aerosol_optical_depth_at_550nm_surface');
  return ee.Number(value_tmmx).multiply(0.1);

};

var count = Monthly.size();

var tmmx_list = Monthly.toList(count).map(getTemp);

print("tmmn_list", tmmx_list);

var paired = allDatesSimple.zip(tmmx_list);

print ("paired", paired);

var myFeatures = ee.FeatureCollection(paired.map(function(el){
  el = ee.List(el); // cast every element of the list
  return ee.Feature(null, {
    'date': ee.String(el.get(0)),
    'aerosol':ee.Number(el.get(1)),


  });
}));

print(myFeatures);

// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"export_aerosol", //my task
"GEE_Folder", //my export folder
"aerosol2",  //file name
"csv");

1 Answer 1

0

You didn't have any data for your date range, so count was 0, causing Monthly.toList(count) to fail.

A general best practice in EE is to avoid converting collections to lists. In this case, doing that actually directly solve your problem. You can convert your image collection to a feature collection directly like this:

var myFeatures = ee.ImageCollection('ECMWF/CAMS/NRT')
  .select('total_aerosol_optical_depth_at_550nm_surface')
  .filterDate(starDate, endDate)
  .map(function(image) {
    var value_tmmx = ee.Image(image)
      .reduceRegion(ee.Reducer.first(), pt)
      .get('total_aerosol_optical_depth_at_550nm_surface')
    return ee.Feature(null, {
      date: image.date().format('yyyy-MM-dd'),
      aerosol: ee.Number(value_tmmx).multiply(0.1)
    })
})

https://code.earthengine.google.com/29601f5a822d3b956482e1209aff9b38

1
  • Hi , thanks for your answer. I test the code and i get an error (ImageCollection (Error) User memory limit exceeded....or Empty date ranges ...)....However my final goal is to get real time data (same day).... Thanks again!
    – gek
    Feb 25 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.