title: Atmospheric correction for Sentinel-2 imagery in Google Earth Engine
body: <p>I want to apply atmospheric correction on Sentinel-2 imagery in Google Earth Engine(GEE). I saw the Sammurphy code which is written in Python and unfortunately it did not work for me. I tried the dark pixel subtraction method using the code(Java)  below but it results in a total dark image over my region of interest.</p>
  <p>I am new to both Earth Engine and JavaScript. Has anyone tried using the dark pixel subtraction or any other atmospheric correction on Sentinel 2 imagery in GEE (preferably a code written in Java)?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var toa=maskedComposite1;
  var thresh= 0.5;
  
  var dark=findDarkPixels(toa, thresh)
  print(dark);
  
  
  //Function to find dark pixels from threshold on sum of NIR, SWIR1, &amp; SWIR2 bands
  //Returns classified image with binary [0,1] 'dark' band
  // toa: Sentinel 2 image converted to surface radiance
  // thresh: threshold (0.2 - 0.5) value for sum of NIR, SWIR1 &amp; SWIR2 bands
  function findDarkPixels(toa, thresh) {
    var darkPixels1 = toa.select(['B8','B11','B12']);
    var darkPixels = darkPixels1.reduce(ee.Reducer.sum()).lt(thresh);
    var filtered = darkPixels.focal_mode(0.1, 'square', 'pixels');
    Map.addLayer(filtered,{},'darkPixel');
    return filtered.rename(['dark']);
  }</code></pre>
  </div>
  </div>
  </p>