gisrastergeotiffrasterio

How to save (as a PNG) single band thermal image geotiff raster with false color in rasterio


I am a newbie so please forgive my ignorance.

I have a GEOTIFF raster with one band (it's a thermal image of Chicago). Here's the metadata:

driver: GTiff
dtype: uint8
nodata: None
width: 7921
height: 7271
count: 1
crs: EPSG:32616
transform: | 30.00, 0.00, 397185.00|
| 0.00,-30.00, 4731615.00|
| 0.00, 0.00, 1.00|
blockxsize: 256
blockysize: 256
tiled: True
compress: jpeg
interleave: band

I want to save the geotiff with color rather than in black and white. I know how to make an image in false color and display it in Python:

therm2010Clip = rasterio.open(outRastT10)
show(therm2010Clip, cmap='plasma')
plt.show()

However, I don't know how to save it with false color. Is there a way to save it with color? (It doesn't have to be the plasma color map)

Here's my code to save the file (but black and white).

 #Transform geotiff ready to save it as a PNG

with rasterio.open('2010ThermClip.tif') as chicTherm2010:
    data = chicTherm2010.read(
        out_shape=(chicTherm2010.count, int(chicTherm2010.height), int(chicTherm2010.width)),
        resampling=Resampling.bilinear
    )
    transform = chicTherm2010.transform

#Save geotiff as PNG
with rasterio.open('chicTherm2010.png', 'w', driver='PNG', height=data.shape[1],     
width=data.shape[2], count=chicTherm2010.count, dtype=data.dtype) as dst:
    dst.write(data)

Solution

  • try to replace the last line with

    dst.write(data,1)