I would like to get a list of bandNames from an image after applying a function on a imageCollection for computing monthly mean. But I found that the bandNames is empty in the returned imagecollection. Here is the code:
PR_geometry = ee.Geometry.Rectangle([-67.32, 17.70, -65.19, 18.56])
imgcollection = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_NO2').\
filterDate('2018/1/1', '2018/5/31').filterBounds(PR_geometry)
def make_datelist(n):
return startdate.advance(n, 'month')
dates = dates.map(make_datelist)
# Get monthly mean using reducer
def getm(d1):
d1 = ee.Date(d1)
m = d1.get('month')
y = d1.get('year')
s = imgcollection.filter(ee.Filter.calendarRange(y, y, 'year'))\
.filter(ee.Filter.calendarRange(m, m, 'month')).mean()
return s\ #return image for each specific month and year
.set('month', m)\
.set('year', y)
MonthlyCollection=ee.ImageCollection.fromImages(dates.map(getm))
# print out the bandNames, but return []
print(MonthlyCollection.first().bandNames().getInfo())
However, if just try one image only, it can return full list of bandNames.
# Get images in single month
singleMonth = imgcollection.filter(ee.Filter.calendarRange(2018, 2018, 'year'))\
.filter(ee.Filter.calendarRange(1, 1, 'month'))
# Return full list of bandNames
print('List of bands:',singleMonth.first().bandNames().getInfo())
reducedimg = singleMonth.reduce(ee.Reducer.mean())
# Return full list of bandNames
print('List of bands for reducedimg:',reducedimg.bandNames().getInfo())
So, why bandNames becomes empty after applying the function and how to get it back?
I also tried this, but still could not get the bandNames, what's wrong?
listOfImages = MonthlyCollection.toList(MonthlyCollection.size());
img0=ee.Image(listOfImages.get(2))
print(img0.propertyNames().getInfo())
print(img0.get('system:band_names').getInfo()) # return nothing
print(img0.get('system:band').getInfo()) # return nothing
TIA