Interesting question. I think 'clipping' as you want it is better done inside the earth engine using masking. Clipping is done on a geometry, while you can also mask all the pixels which are crop in the MODIS images.
As you didn't define your Area of Interest (roi) in your question, I draw a polygon myself. Also, you wanted it done from 2001 till 2016, so I first merged the image collections of landsat 5, 7 and 8 together:
// Landsat images
var l8images = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA').filterBounds(roi);
var l7images = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA').filterBounds(roi);
var l5images = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA').filterBounds(roi);
var merged = l8images.merge(l7images).merge(l5images);
You then want to mask all images of a certain year based on the MODIS image where cropland is classified. I think it is usefull to filter each image collection on a year and then mask all the landsat images from that year on the MODIS image of that year. I would do that as follows:
// mask images for years between:
var startyear = 2001;
var endyear = 2016;
// make image composites
var loopsteps = ee.List.sequence(startyear,endyear);
var masking = loopsteps.map(function(x){
var sdate = ee.Date.fromYMD(x,1,1); // startdate of current loop
var edate = ee.Date.fromYMD(x,12,31).advance(1, 'day'); // enddate of current loop (exclusive, so add 1 day)
var filtLs = merged.filterDate(sdate, edate);
var filtCrop = yearlyCrop.filterDate(sdate, edate).first().rename("LC_Type1Crop");
// map over the ls images of 1 year and mask everything which is not Crop (=12)
var maskedLandsat = filtLs.map(function(image){
return image.updateMask(filtCrop).addBands(filtCrop).clip(roi);
});
return maskedLandsat;
});
Note that I clipped every image based on the area of interest (roi), but that is not necesarry. Also you should know that if your studyarea is large or on the border of an Landsat scene, you will have to make image composites so your whole studyarea is covered by images.
Now you will end up with a list with on each position a imagecollection of that year. You possibly want to merge all the imageCollections of every year back together:
// rearrange the list of collections into a single image collection
var sizeList = masking.length();
var emptyCol = ee.ImageCollection(ee.Image());
function rearrange(current, previous){
previous = ee.ImageCollection(previous);
current = ee.ImageCollection(current);
return current.merge(previous);
}
// all the images masked on the yearly crop MODIS image
var output = ee.ImageCollection(masking.iterate(rearrange, emptyCol))
.filter(ee.Filter.listContains('system:band_names', 'LC_Type1Crop'));
print('images valid for MODIS crop', output);
Link to the script