1

I am creating a time-series chart of cloud cover. I calculate the cloud score for image using a custom function and store it as a cloud property.

Finally, I try to create a chart as follows:

  1. Get the list comprised of each image's cloud score using aggregate_array
var cs_list = image_col.aggregate_array('cloud);
  1. Finally, creating a series chart
var chrt = ui.Chart.array.values(cs_list, 1);
print(chrt);

And following is the script code:

var img_col = ee.ImageCollection("COPERNICUS/S2")
                    .filterDate('2018-05-01', '2018-07-30')
                    .filterBounds(region_of_interest_geometry);

var col_with_cloudiness = img_col.map(function(image) {
      var cloud_score = compute_cloud_score(image); // function to get cloud_score e.g 0.3454

      return image.set('cloud', cloud_score); // set new property
});

var cs_list = col_with_cloudiness.aggregate_array('cloud');
print(cs_list);  // JSON [0.2564 (type Obj), 0.0573 (type Obj), ...]. Want Array [0.2564 (type Number), 0.0573 (type Number)]

print(ui.Chart.array.values(cs_list, 1));

On running the code, I ran into the following issue: the cloud-score list contains numbers which are of type object. And so instead of getting line plot, several lines' legends representing each list element(score) gets created

How to convert them to numbers or create an array of cloud scores as actual numbers?

2
  • Can you share a reproducible example?
    – Kuik
    Commented Jul 6, 2020 at 13:32
  • @Kuik, Please see added code above
    – Waleed93
    Commented Jul 6, 2020 at 14:06

1 Answer 1

2

On running the code, I ran into the following issue: the cloud-score list contains numbers which are of type object.

I don't see anything strange about the types of your cs_list. It's an ordinary ee.Array which contains numbers as all ee.Arrays do.

There's no such thing as a "number of type object", either. (You can have an ee.Number which isn't known on the client to be that type, but that's not the problem here.)

And so instead of getting line plot, several lines' legends representing each list element(score) gets created

The problem is that you have asked to chart axis 1, the second axis, but your array is only one-dimensional and so the only interesting axis is axis 0, the first axis. Try this:

print(ui.Chart.array.values(cs_list, 0));
1
  • Thanks Kevin. I was taking wrong meaning of 'axis number'
    – Waleed93
    Commented Jul 7, 2020 at 13:37

Your Answer

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

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