#1: create a cloud free composite

A modular land cover system part 1

Step 1: Create a new repository and call it mrc.


Step 2: create a new script and call it importS2_module

Step 3: copy the code below and store it in the script

var inBands = ee.List(['QA60','B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B10','B11','B12']);
var outBands = ee.List(['QA60','cb','blue','green','red','re1','re2','re3','nir','re4','waterVapor','cirrus','swir1','swir2']);

var CloudCoverMax = ??

exports.importData = function(studyArea,startDate,endDate) {

// Get Sentinel-2 data
var s2s = ee.ImageCollection('COPERNICUS/S2')

  function scaleBands(img){
    var prop = img.toDictionary()
    var t = img.select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B10','B11','B12']).divide(10000);
    t = t.addBands(img.select(['QA60'])).set(prop).copyProperties(img,['system:time_start','system:footprint'])
  return ee.Image(t);

s2s = s2s.map(scaleBands);
s2s = s2s.select(inBands,outBands) ;

return s2s;

Step 4: Create a new script and call it main

// import required modules
var importS2 = require("users/../mrc:importS2_module");

// import shapefile data
var cambodia = ee.FeatureCollection("users/.../.../KHM_adm1");
var KampongThum = cambodia.filter(ee.Filter.eq("NAME_1","...")).geometry();

// set the variables
var CloudCoverMax = ...;
var startDate = ...;
var endDate = ...;
var studyArea = ...;

print("getting images");
var s2 = importS2.importData(studyArea,startDate,endDate);
print("found ",s2.size(),"images");
Map.addLayer(ee.Image(s2.first()),{min:0,max:0.6,bands:"swir2,nir,red"},"first image");

Step 5: Run the script



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s