[GIS] Concerning “Landsat 5’s cloud mask and pixel quality assessment” in Google Earth Engine

google-earth-enginejavascriptlandsatlandsat-5

I need assistance for solving a problem with Landsat 5 surface reflectance image's cloud mask.

I am new to this tool/programming and want to try this tool to process cloud mask. Through the provided open source code in the web page of Goole Earth Engine, the processing code is composed as below.

However, I would like to request help to debug this error message "Error: Invalid argument: 'image' must be of type Image."


var cloudy_scene = ee.Image('LANDSAT/LT5_SR/LT5*************');

Map.centerObject(cloudy_scene);

Map.addLayer(cloudy_scene,{},'all_bands_cloud');

// Load a Landsat 5 image collection.
var collection = ee.ImageCollection("LANDSAT/LT5_SR")

// Filter to get a geometry representing an export region.
.filterBounds(ee.Geometry.Rectangle([***.***,**.***,***.***,**.***]))

// Filter to get the years/months/days of data.
.filterDate('1993-01-01', '1993-03-01')  // filter to your favorite period

// Sort the collection in chronological order.
.sort('system:time_start', true);

//Details for cfmask
//0=clear
//1=water
//2=shadow
//3=snow
//4=cloud

var masked = collection.map(function(image){  
    return image.updateMask(cloudy_scene.select(['cfmask']).neq(4))
});

// Apply the mask to the image and display the result.
Map.addLayer(masked, {}, 'masked');

var geometry = ee.Geometry.Rectangle([***.***,**.***,***.***,**.***]);

//export the image, specifying scale and region.
Export.image.toDrive({
    image: masked,
    description: 'ImageToDrive',
    scale: 30,
    region: geometry
});

Best Answer

Ok, interestingly your script ran through without giving me any error. But if you want to mask out clouds and shadows in your specific image (as you said in your comment) you can do it like this:

//cloudy image
var cloudy_scene = ee.Image('LANDSAT/LT5_SR/LT51170431993035');
Map.centerObject(cloudy_scene);

// add true color composite to map
Map.addLayer(cloudy_scene,{min:0,max:3000,bands:['B3','B2','B1']},'cloudy');

//Details for cfmask
//0=clear
//1=water
//2=shadow
//3=snow
//4=cloud

// select cfmask band as mask
var msk = cloudy_scene.select('cfmask');

//conditions which to mask out - no shadows, snow or clouds
msk = msk.neq(2).and(msk.neq(3)).and(msk.neq(4));

// apply mask
var masked = cloudy_scene.mask(msk)

// add masked image to Layer
Map.addLayer(masked,{min:0,max:3000,bands:['B3','B2','B1']},'masked');

//  rectangle for export
var geometry = ee.Geometry.Rectangle(122.006687,24.673089,121.282702,25.300515);

// Select bands for export
var bnds = ['B1','B2','B3','B4','B5','B7'];

//export the image, specifying scale and region.
Export.image.toDrive({
    image: masked.select(bnds),
    description: 'MaskedLS5',
    scale: 30,
    region: geometry
});

Edit:

GEE requires the data types of an image to be identical if you want to export it. If you print the masked image to the console you'll see that there are additional 8bit bands. I assumed you're interested in the surface reluctance only, so I added a list of bands for export and I select them within the export function.

If you want to export all bands, you need to cast them in a common datatype like uint16.