Code Monkey home page Code Monkey logo

Comments (3)

Daniel-Trung-Nguyen avatar Daniel-Trung-Nguyen commented on August 22, 2024

When I ran the same location on code.earthengine.google.com using the code boilerplate from https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR, the cloud was not masked at all. Is this a bug or am I missing something?
Thanks,
Daniel

/**
 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
 */
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

var point = ee.Geometry.Point([150.5773, -28.1182])
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate('2022-04-01', '2022-04-06')
                  .filterBounds(point)
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',50))
                  .map(maskS2clouds);

var visualization = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};

Map.setCenter(150.5773, -28.1182,15);

Map.addLayer(dataset.mean(), visualization, 'RGB');

image

from eemont.

Daniel-Trung-Nguyen avatar Daniel-Trung-Nguyen commented on August 22, 2024

Apparently I added unmask() after clipping the imagecollection to an ROI that was why the mask was replaced by zero.

from eemont.

davemlz avatar davemlz commented on August 22, 2024

Don't worry! :)

from eemont.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.