I want to use a function to scale the bands of an image. The number and name of the image bands may differ. The following (working) code almost does what I want, except I want to loop over the (number of) bandnames, instead of a pre-defined range size:
from scipy.stats.distributions import randint_gen
# Function to scale the images (one mosaicked ee.Image) to a Uint8 format scaled from 0-255
def scale_composites(image):
image_copy = image
bandnames = image.bandNames()
image = image.select(0).multiply(0).rename('base')
min_max = [-5,5] # Min and Max values for S1 change ratios (list)
bandlist = []
for band in range(0, 4):
scaledband = image_copy.select(band).unitScalemin_max[0], min_max[1]).multiply(255).toUint8()
bandlist.append(scaledband)
image = image.addBands(bandlist)
image = image.select(bandnames)
return image
The input of the function is an 'ee.image.Image', and 'bandnames' is an 'ee.ee_list.List'.
I have tried double loops with enumerate, length, toList, ... but I cannot figure out how to adapt the loop to my purpose.