Snappy: lost of size of resampled bands when making a custom product

Hi,

I’m concerning about an issue I have encountered using snappy with the resampling of 20 m bands.

I was making a code to study some environmental indexes defined by a mixture of Sentinel 2 bands when I noticed a strange behaviour in the outputs. Digging in the code I have found that a custom product I have defined is the cause of this.

How you can see in the first attached code (Code 1), I am extracting from a level 1C product the 20 m resolution bands ( Res20m_Product ), resampling them at 10 m ( Rsmpl_20m ) and eventually adding them to those originally at 10 m. The result of this process is a product made of only 10 m resolution bands ( Res10_Product ).

Unfortunately, what written above is my purpose, but not my result. When I print the size of the 20 m bands, I get the expected width x height = 5490 x 5490. When I call the resampled product size, I get 10980 x 10980. But when I add the Rsmpl_20m bands to Res10_Product, here I get again width x height = 5490 x 5490.

As far I know, the code I wrote should be ok, but obviously it is not. I hope someone can help me find out the mistake.

Note 1: For the time being as a workaround I have made a Res10_Product with 10m and 20m and only after I have resampled all the bands to 10m (see Code 2). This code work properly and all the bands remain at 10 m of resolution.

Note 2: I have tested this code also with the AddBand( ) method by adding the resampled bands to the Res10_Product, but I have obtained the same problem.

# Making product from SAFE file
print('Reading product ...')
product = ProductIO.readProduct(XML_path)       
pgc= product.getSceneGeoCoding()    


# Making the 20 m Product
Res20_Product = Product('Res20_Bands', 'Same_res', width, height)       
Res20_Bands = ['B5','B6','B7','B8A','B11','B12']
for band in Res20_Bands: ProductUtils.copyBand(band, product, Res20_Product, True)     
ProductUtils.copyGeoCoding(product, Res20_Product)
ProductUtils.copyProductNodes(product, Res20_Product)

##  Checking raster size of a 20 m band
k = Res20_Product.getBand('B5')
Width_k  = k.getRasterWidth()
Height_k = k.getRasterHeight()
print("Band Size: " + str(Width_k) +','+ str(Height_k))


# Resampling the 20m product
parameters = HashMap()
parameters.put('targetResolution',10)
parameters.put('resampling', "Nearest")
Rsmpl_20m = snappy.GPF.createProduct('Resample',parameters,Res20_Product)

##  Checking raster size of a resampled band
k = Rsmpl_20m.getBand('B5')
Width_k  = k.getRasterWidth()
Height_k = k.getRasterHeight()
print("Band Size: " + str(Width_k) +','+ str(Height_k))


# MAKING CUSTOM PRODUCT AT 10M RESOLUTION
Res10_Product = Product('Res10_Bands', 'Same_res', width, height)      
Res10_Bands = ['B2','B3','B4','B5','B6', 'B7','B8', 'B8A', 'B11', 'B12']
for band in Res10_Bands: 
    if band == 'B2' or 'B3' or 'B4' or 'B8':
        ProductUtils.copyBand(band, product, Res10_Product, True)      
    else:
        ProductUtils.copyBand(band, Rsmpl_20m, Res10_Product, True)         
ProductUtils.copyGeoCoding(product, Res10_Product)
ProductUtils.copyProductNodes(product, Res10_Product)

##  Checking raster size of a 10 m band
k = Res10_Product.getBand('B5')
Width_k  = k.getRasterWidth()
Height_k = k.getRasterHeight()
print("Band Size: " + str(Width_k) +','+ str(Height_k))

Code 1 Outputs:
Reading product …
Band Size: 5490,5490
Band Size: 10980,10980
Band Size: 5490,5490

Code 2:

### Extracting 20m bands
Res20_Product = Product('Res20_Bands', 'Same_res', width, height)       
Res20_Bands = ['B5','B6','B7','B8A','B11','B12']
for band in Res20_Bands: ProductUtils.copyBand(band, product, Res20_Product, True)     
ProductUtils.copyGeoCoding(product, Res20_Product)
ProductUtils.copyProductNodes(product, Res20_Product)

### Adding 10 m & 20 m bands togheter, then resampling
Grouping_10_20 = Product('Res10_Bands', 'Same_res', width, height) 
ProductUtils.copyGeoCoding(product, Grouping_10_20)
ProductUtils.copyProductNodes(product,  Grouping_10_20)

Grouping_10_20Bands = ['B2','B3','B4','B5','B6', 'B7','B8', 'B8A', 'B11', 'B12']
for band in Grouping_10_20Bands:  
        Grouping_10_20.addBand(product.getBand(band))

parameters = HashMap()
parameters.put('targetResolution',10)
parameters.put('resampling', "Nearest")  # Cubic ??
Res10_Product = snappy.GPF.createProduct('Resample',parameters, Grouping_10_20)```