I have an ndarray which I would like to save as rasterio raster.
I have all the information I needed (image size, transform, band names etc.).
The problem is that when I try to save the image as raster with the band names, the image saved correctly, but the names never saved.
This is snippet of my code:
#open the raster that I want to process
test=rasterio.open('gs://my_bucket/my_imgs/my_elevation/elevation_img.tif')
# access the bands names, will be used later to save the output with same bands names
names=list(test.descriptions)
names
>>>['B1_OK','B2_CK']
#read as array (need it for the processing)
arr=test.read()
####after I processed the image.....
#metadata for the image that will be saved
metadata = {
'driver': 'COG',
'height': arr.shape[1],
'width': arr.shape[2],
'count': arr.shape[0],
'dtype': arr.dtype,
'crs':'EPSG:4326',
'transform': test.transform,
'descriptions': names
}
##save the image
with rasterio.open('/home/my/folder/git/toolim/nbs/tmp/test1.tif', 'w', **metadata) as dst:
dst.write(arr)
#check the band names of the new image:
rasterio.open('/home/my/folder/git/toolim/nbs/tmp/test1.tif').descriptions
>>>(None,None)
I could not find any reason why this happens, setting names suppose to be relatively simple, so I must do something wrong...
My end goal: be able to use the list of names as post-processed image bands, and in general, to be able to define the bands names and to understand my mistake.