2

I am trying to rename the band names of my raster stack in GEE. Here is what I have tried so far:

var start_date = ee.Date('2020-11-01');
var finish_date = ee.Date('2020-12-01');
var orbit = 'DESCENDING';

var collectionS1 = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
    .filter(ee.Filter.eq('instrumentMode', 'IW'))
    .filter(ee.Filter.eq('orbitProperties_pass', orbit))
    .filterDate(start_date, finish_date)
    .filterBounds(polygons);

 // Get the VV collection.
var band_names = ['S1_VV_11'];
var collectionVV = collectionS1.select('VV').select (band_names);
// Get the VH collection.
var band_names1 = ['S1_VH_11'];
var collectionVH = collectionS1.select('VH').select(band_names1);


var VV = ee.Image(collectionVV.first().clip(polygons));  //roi_A is my rectangular roi
var VH = ee.Image(collectionVH.first()); 

// I would like to take VV and VH and stack them and download
var VVVH = VV.addBands(VH)

print(VVVH)

Export.image.toDrive({
  image: VVVH,
  description: 'S1_2020_11',
  scale: 10,
  region: polygons,
  fileFormat: 'GeoTIFF',
  //formatOptions: {
  //  cloudOptimized: true
  //}
});

But it throws me an error like this:

Image (Error)
Collection.first: Error in map(ID=null):
Image.select: Pattern 'S1_VH_11' did not match any bands

Is it possible to rename the band or keep the original band names instead of output like Band 1, Band 2, etc... Or do I need to change the output format?

3 Answers 3

2

If you want to rename all the images inside your image collection, you need to use the map function. This way you can rename each image with the new names. Additionally, if you look in the Docs section of GEE, you'll notice that ee.ImageCollection objects do not have a rename method and its select method does not have an option to rename directly the bands with a second list.

// Get the VV collection.
var band_names = ['S1_VV_11'];
var collectionVV = collectionS1.select('VV')
                               .map(function(image){
                                 return ee.Image(image).rename(band_names);
                               });
// Get the VH collection.
var band_names1 = ['S1_VH_11'];
var collectionVH = collectionS1.select('VH')
                               .map(function(image){
                                  return ee.Image(image).rename(band_names1);
                                });
0

Sentinel 1 images are not called 'S1_VV_11' and 'S1_VH_11' as you seem to suggest in your code. Additionally there is currently no way to set names to bands in a geotiff (export): Keeping the actual band names in GEE exported images

https://code.earthengine.google.com/689f0b4a874904d9ad0b7cd314ed18c0

0

To rename the bands, you have to use .rename()

    var collectionVV = collectionS1.select('VV').rename ('S1_VV_11');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.