Dynamic Cloud Filter Export

The Dynamic cloud filter and export tool is designed to allow the user to calculate total percentage stats for all bands in the UDM-2 imagery. Meaning for each AOI you get percentage clear pixel, snow cover, shadow, and so on. The method is simply based on summarizing these values over the overlapped AOI and then export these percentages up to two decimal places. The method also takes into account that since the daily composite or imagery may not overlap with the entire AOI it also generates a percentage overlap. The example runs this on both all imagery in the collection as well as daily composites.

dyanmic_cloud_export

You can also copy and past the code from below.

//UDM2 Band Descriptions from (https://developers.planet.com/docs/data/udm-2/)

/*
Band 1  Clear map   [0, 1]  0: not clear, 1: clear
Band 2  Snow map    [0, 1]  0: no snow or ice, 1: snow or ice
Band 3  Shadow map  [0, 1]  0: no shadow, 1: shadow
Band 4  Light haze map  [0, 1]  0: no light haze, 1: light haze
Band 5  Heavy haze map  [0, 1]  0: no heavy haze, 1: heavy haze
Band 6  Cloud map   [0, 1]  0: no cloud, 1: cloud
Band 7  Confidence map  [0-100] percentage value: per-pixel algorithmic confidence in classification
Band 8  Unusable pixels --  Equivalent to the UDM asset: see Planet's Imagery Specification for complete details

*/

var geometry =
    ee.Geometry.Polygon(
        [[[-120.65384411415185, 36.92661132978841],
          [-120.65384411415185, 36.6373393494637],
          [-120.33112072547998, 36.6373393494637],
          [-120.33112072547998, 36.92661132978841]]], null, false);

//Get required module
var cloudy= require('users/samapriya/utils:cloud-utils')

//Import the Planet UDM-2 Sample collection
var collection=ee.ImageCollection("projects/sat-io/open-datasets/udm2-tests/udm2");
print('Total udm-2 images in collection',collection.size())

//Get collection with daily composites
var daily_composite=cloudy.dailymax(collection)

//Get start and end dates from daily collection to print
var daily_composite_list = daily_composite.toList(daily_composite.size())
print('Start Date',ee.Image(daily_composite_list.get(0)).get('date'),
'End Date',ee.Image(daily_composite_list.get(daily_composite.size().subtract(1))).get('date'))

//Get UDM2 per daily composite
var udm2composite=cloudy.udm2info(ee.ImageCollection(daily_composite),geometry)
var udm2imagery=cloudy.udm2info(ee.ImageCollection(collection),geometry)

print('Total UDM-2 Composites from collection for AOI',
udm2composite.size())
print('UDM-2 info for AOI from daily composite',
udm2composite)

print('Total UDM-2 Images from collection for AOI',
udm2imagery.size())
print('UDM-2 info for AOI from all imagery in composites',
udm2imagery)

//Helper Function to extract Image ID for Search ID
var searchid=function(image){
  return image.set('search_id',ee.String(image.get('id_no')).replace('_3B_udm2',''))
}


// Export composite results with identifier
Export.table.toDrive({
  collection: udm2composite,
  description: 'AOI_Composite_Export',
  selectors: (["date",
  "clear_cover_percentage_aoi",
  "snow_cover_percentage_aoi",
  "shadow_cover_percentage_aoi",
  "light_haze_cover_percentage_aoi",
  "heavy_haze_cover_percentage_aoi",
  "cloud_cover_percentage_aoi",
  "percentage_overlap_aoi"]),fileFormat: 'CSV',
});


// Export imagery results with identifier
Export.table.toDrive({
  collection: udm2imagery.map(searchid),
  description: 'AOI_Imagery_Export',
  selectors: (["search_id",
  "clear_cover_percentage_aoi",
  "snow_cover_percentage_aoi",
  "shadow_cover_percentage_aoi",
  "light_haze_cover_percentage_aoi",
  "heavy_haze_cover_percentage_aoi",
  "cloud_cover_percentage_aoi",
  "percentage_overlap_aoi"]),fileFormat: 'CSV',
});

Export tables look like the following. Notice a couple of things:

  • It automatically calculates your percentage overlap with your AOI
  • The cloud , clear haze and other classes are then percentage fractions of the udm2 that lies within the AOI.
  • Hence it serves as a dyanmic cloud/clear filter.

dyanmic_cloud_export_report

Bonus feature: The search id function converts the asset id into item ids which you can then use to download clean AOI base images from Planet's API or Explorer using orders v2 API.