Google Earth Engine – How to Download All Images for a Particular Month of a Year

exportgoogle-earth-engine

I'm trying to download all the images for a certain month (February) for 2018 from Proba-V. Proba-V produces images every 2 days. Here is the link of the product. I am following this post on how to do it. When running my code I receive the following error:

Line 36: Required argument (image2) missing to function: Image.first(image1, image2)

Selects the value of the first value for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.

Args:

  image1 (Image): The image from which the left operand bands are taken.
  image2 (Image): The image from which the right operand bands are taken.

How can I download all images (not as layer stack) for February 2018?

Here is the code:

// Project the image to Mollweide.
var wkt = ' \
  PROJCS["World_Mollweide", \
    GEOGCS["GCS_WGS_1984", \
      DATUM["WGS_1984", \
        SPHEROID["WGS_1984",6378137,298.257223563]], \
      PRIMEM["Greenwich",0], \
      UNIT["Degree",0.017453292519943295]], \
    PROJECTION["Mollweide"], \
    PARAMETER["False_Easting",0], \
    PARAMETER["False_Northing",0], \
    PARAMETER["Central_Meridian",0], \
    UNIT["Meter",1], \
    AUTHORITY["EPSG","54009"]]';

var proj_mollweide = ee.Projection(wkt);

var era5_2mt = ee.ImageCollection('VITO/PROBAV/C1/S1_TOC_100M')
                   .select('NDVI')
                   .filter(ee.Filter.calendarRange(2018,2018,'year'))
                   .filter(ee.Filter.calendarRange(02,02,'month'))
                   // clip to your study area
                   .map(function(image) {return image.clip(table)});

var study_area = era5_2mt.map(function(img){
var s_ts = img.get('system:time_start')    // get the 'system:time start' property from the image
img = ee.Image(img)
              .subtract(20)
              .divide(250)
      .set({'system:time_start': s_ts});   // set the 'system:time_start' property from the output image
return(img);
});

var image_mollweide = merged.first();

// export image to Google Drive
Export.image.toDrive({
  image: merged,
  description: 'era5_2mt',
  scale: 100,
  region: table
});

And the shapefile I am using.

Best Answer

For visualizing and exporting only useful images for February of 2018, you can use following code. Before exporting whatever image, you can mark each layer in the Tab of layers (default visualization was placed in false mode) for corroborating if corresponding image has valid values (non nulls).

var table = ee.Geometry.Polygon(
        [[[100.13094216644127, 13.91184995445293],
          [100.13094216644127, 13.837189483367121],
          [100.28749734222252, 13.837189483367121],
          [100.28749734222252, 13.91184995445293]]], null, false);
          
//Map.addLayer(table);
Map.centerObject(table);

// Project the image to Mollweide.
var wkt = ' \
  PROJCS["World_Mollweide", \
    GEOGCS["GCS_WGS_1984", \
      DATUM["WGS_1984", \
        SPHEROID["WGS_1984",6378137,298.257223563]], \
      PRIMEM["Greenwich",0], \
      UNIT["Degree",0.017453292519943295]], \
    PROJECTION["Mollweide"], \
    PARAMETER["False_Easting",0], \
    PARAMETER["False_Northing",0], \
    PARAMETER["Central_Meridian",0], \
    UNIT["Meter",1], \
    AUTHORITY["EPSG","54009"]]';

var proj_mollweide = ee.Projection(wkt);

var era5_2mt = ee.ImageCollection('VITO/PROBAV/C1/S1_TOC_100M')
                   .select('NDVI')
                   .filterDate('2018-02-01', '2018-03-01')
                   // clip to your study area
                   .map(function(image) {return image.clip(table)});

var study_area = era5_2mt.map(function(img){

  var s_ts = img.get("system:time_start");    // get the 'system:time start' property from the image

  img = ee.Image(img)
                .subtract(20)
                .divide(250)
                .set("system:time_start", s_ts)
                .set('fileName', ee.String('image_').cat(ee.Date(s_ts).format().slice(0,10)));

  return(img);
  
});

print(study_area);

// Function to export an image to Google Drive
var exportImage = function(image, fileName) {
  Export.image.toDrive({
    image: image,
    description: fileName,
    folder: 'GEE_exports',
    scale: 100,
    region: table,
    fileFormat: 'GeoTIFF'
  });
};

//print(monthlyLAI.aggregate_array('fileName'))

study_area.aggregate_array('fileName').evaluate(function (fileNames) {
  fileNames.forEach(function(fileName) {
    var image = study_area
      .filter(ee.Filter.eq('fileName', fileName))
      .first();
    Map.addLayer(image, {}, fileName, false);
    exportImage(image, fileName);
  });
});

After running above code for an arbitrary area near of Bangkok (your shapefile was not available), I got result of following picture:

enter image description here

At the above picture is visualized the first useful image for 2018-02-03. Marking/unmarking successively each layer allows to discover which image has valid values (non nulls). So, image for 2018-02-03 can be exported to Google Drive.