I try crop classification for wheat crops in my study area. My code very well works for the 2016-2019 years. But for the 2020 year, my code did not work.
Here is my code:
var Polygon =
/* color: #d63000 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[9.671764962717377, 50.72618024130225],
[9.671764962717377, 49.65178588495313],
[11.182385079904877, 49.65178588495313],
[11.182385079904877, 50.72618024130225]]], null, false);
//Import S2 image collection, // Define a cloud masking function and Selected Boundary // Selected period
var collection4 = ee.ImageCollection('COPERNICUS/S2').filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20).filterBounds(Polygon).filterDate('2020-05-01', '2020-05-15');
var image4 = collection4.mean();
// Define an index function (selected NDVI value).
var ndvi4 = image4.normalizedDifference(['B8', 'B4']).gt(0.4);
//Import S2 image collection, // Define a cloud masking function and Selected Boundary // Selected period
var collection5 = ee.ImageCollection('COPERNICUS/S2').filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20).filterBounds(Polygon).filterDate('2020-06-15', '2020-06-30');
var image5 = collection5.mean();
// Define an index function (selected NDVI value).
var ndvi5 = image5.normalizedDifference(['B8', 'B4']).lt(0.3);
//Import S2 image collection, // Define a cloud masking function and Selected Boundary // Selected period
var collection6 = ee.ImageCollection('COPERNICUS/S2').filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20).filterBounds(Polygon).filterDate('2020-07-01', '2020-07-15');
var image6 = collection6.mean();
// Define an index function (selected NDVI value).
var ndvi6 = image6.normalizedDifference(['B8', 'B4']).lt(0.3);
//NDVI collection
var wheat = (ndvi4).and(ndvi5).and(ndvi6)
var wheatViz = {min: 0, max: 1, palette: ['#FFFFFF00', 'blue']}
//var wheatMask = wheat.eq(1)
var ndviMasked = wheat.updateMask(wheat.gte(0.5))
Map.addLayer(ndviMasked.clip(Polygon), wheatViz, 'wheat')