0

I am trying to export a csv of daily mean cloud cover in the Netherlands according to S5P data. I have calculated the mean cloud fraction, but the exported csv shows many, many rows - none of them are cloud_fraction (image below). What am I missing?

//  1. Setup
var countries = ee.FeatureCollection("FAO/GAUL/2015/level0");
var NL = countries.filterMetadata('ADM0_NAME', 'equals', 'Netherlands');
var start_period = ee.Date('2018-07-01');
var end_period = ee.Date(new Date().getTime());

var clouds = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_CLOUD')
  .select('cloud_fraction')
  .filterDate(start_period, end_period);

var cloudNL=clouds.map(function(im){ 
   return im.clip(NL)//.resample('bilinear').reproject('EPSG:4326', null, 2000);
});


//  2. Mean cloud cover dictionary for entire collection
var cloudlist = cloudNL.map(function(image){
  var meandict = image.select('cloud_fraction').reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: NL
  })
  return image.set(meandict); 
});

Export.table.toDrive(cloudlist.sort('cloud_fraction'), 'NL_mean_cloud_fraction');

enter image description here

1 Answer 1

0

ASNWER: Include 'cloud_fraction' in a list of properties of cloudlist to export using the selectors argument. Example:

Export.table.toDrive({
  collection: cloudlist.sort('cloud_fraction'),
  description: 'NL_mean_cloud_fraction',
  selectors:['system:time_start','cloud_fraction']
});

EXPLANATION: 'cloud_fraction' didn't appear in your exported .csv is because of null values set for this property in the function you mapped onto cloudNL. It is not possible to set an image property to have a null value. This can be shown by:

var image = ee.Image().set('dummy',null)
print(image.propertyNames()) // there is no 'dummy' property in the returned list 

If the selectors argument is not defined in Export.table.toDirive, I'm guessing that the function sets selectors to be all of the properties of the first entry in the exported collection. If 'cloud_fraction' was set to null in that first entry, then this property would be deselected from your exported .csv -- which would be the case since cloudlist was sorted by 'cloud_fraction' (null values came first).

EDIT: the following example filters cloudlist by 'cloud_fraction' and adds a new property, which we will call 'datestring':

cloudlist = cloudlist

   // keep images with cloud_fraction less than 0.1 
  .filter(ee.Filter.lt('cloud_fraction',0.1))
  
  .map(function(image){
    
    // extract the first 8 characters from system:index using ee.String.slice
    var datestring = ee.String(image.get('system:index')).slice(0,8)
    return image.set('datestring', datestring)
  })

Note, you will have to add datestring to your list of properties to export as a table.

7
  • Thanks! I don't see where I explicitly the set cloud_fraction values to null? The csv export now works, but the cloud_fraction column is still completely empty.
    – Olivier
    Commented Feb 19, 2021 at 10:57
  • 1
    The majority of your images do not intersect with your area of interest (NL), so when you reduce your image a null is returned. If you are still sorting your exported collection by 'cloud_fraction', the non-null entires should be at the end of the .csv. Might be useful to filter cloudlist using Filter.notNull, example: cloudlist.filter(ee.Filter.notNull(['cloud_fraction']))
    – korndog
    Commented Feb 19, 2021 at 17:59
  • I realized that the images with cloud_fraction values were simply further down in the Excel. Using .notNull worked for me, thanks! In addition to that, could I keep only values lower than 0.10? And furthermore, could I directly split the system:time attributes before the first 'T', so I only keep e.g. 20200721 as a title?
    – Olivier
    Commented Feb 23, 2021 at 10:58
  • 1
    Glad to hear things are working for you, @Olivier. See my editted answer for my response to your questions.
    – korndog
    Commented Feb 23, 2021 at 18:46
  • 1
    @Olivier, I suggest that you post these follow-up question seperately, since your original question has been answered. At this time, I cannot help you with this last question. I recall a similar question being asked recently: gis.stackexchange.com/questions/387693/…. All the best.
    – korndog
    Commented Feb 24, 2021 at 16:42

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.