I have a function to visualize imagery of different dates. However, I need to use both landsat 7 and 8, since my the dates I want start earlier than 2013. The issue arises that landsat 7 and 8 order their bands differently, so visualizing the images in the same way would require different code. To fix this, I am trying to rename the red, green, blue, and NIR bands in the landsat 7 image collection to match landsat 8. This way I can write a universal code that will apply to both images from landsat 7 and 8. Below is the code I have written (assume landsat 7 has been imported and called 'landsat7', and a geometry that encloses the area of interest called 'bounds' is also imported).
// Function to rename landsat 7 bands to match landsat 8 bands
var adjustBands = function(landsat7){
var adjust = ee.ImageCollection(landsat7)
.filterDate('2010-01-01', '2010-05-01')
.filterBounds(bounds).first();
return adjust.select(['B4', 'B3', 'B2', 'B1'],['B5', 'B4', 'B3','B2']);
}
print('adjust', adjustBands(landsat7));
//apply function to entire image collection
var l7a = landsat7.map(adjustBands);
However, when I run the code I get an error: Error in map(ID=LE07_001004_20000610): Image.select: Parameter 'input' is required. Any advice?
You can just call the .select()
function from the image collection with the first argument being a list of bands you want to select and the second argument being a list to rename the bands.
var adjustBands = landsat7.select(['B4', 'B3', 'B2', 'B1'],['B5', 'B4', 'B3','B2'])
There is no need to map a function over the image collection to rename bands as that method will create unnecessary overhead.
It looks like you are mapping a function onto a collection, but inside the function you are reading in the same collection. Make sure when mapping functions onto collections, that the function itself only takes a single image as its argument and returns a single image. Here's how I handle the band renaming if I want to combine Landsat collections:
function renameBandsETM(image) {
var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'pixel_qa'];
var new_bands = ['B', 'G', 'R', 'NIR', 'SWIR1', 'SWIR2', 'pixel_qa'];
return image.select(bands).rename(new_bands);
}
var etm = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.map(renameBandsETM)
I then do the same to the LC8 imagery, taking into account the different band naming system:
function renameBandsOLI(image) {
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'pixel_qa'];
var new_bands = ['B', 'G', 'R', 'NIR', 'SWIR1', 'SWIR2', 'pixel_qa'];
return image.select(bands).rename(new_bands);
}
var oli = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.map(renameBandsOLI);
You can then merge the collections:
var landsat = ee.ImageCollection(etm.merge(oli));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With