il formato di output e' stato modificato in Geotiff perche' JP2 non permette di salvare in float32
import numpy as np
import rasterio
from rasterio import plot
imagePath = './immagini/'
band4 = rasterio.open(imagePath+'B4.jp2', driver='JP2OpenJPEG')
band8 = rasterio.open(imagePath+'B8.jp2', driver='JP2OpenJPEG')
band4s = band4.read(1)
band8s = band8.read(1)
RED=band4s.astype(float)
NIR=band8s.astype(float)
np.seterr(divide = "ignore", invalid = "ignore")
ndvi = np.zeros(RED.shape, dtype=rasterio.float32)
ndvi = (NIR-RED) / (NIR+RED)
ndvi[ndvi > 1] = np.nan
ndvi[ndvi < -1] = np.nan
kwargs = band4.meta
kwargs.update(driver='GTiff',dtype=rasterio.float32,count=1)
ndviimage = rasterio.open('./immagini/SentinelNDVI2.tiff','w',**kwargs )
ndviimage.write(ndvi,1)
ndviimage.close()
Nessun commento:
Posta un commento