I have the following numpy arrays:
predictions; type is float32; shape: (94, 1461)
lats; float32; shape: (94,); centroid of cell in vector layer, decimal degs.
lons; float32; shape: (94,); centroid of cell in vector layer, decimal degs.
- 94 corresponds to the number of cells in the vector grid below
- 1461 corresponds to the number of bands
I've looked at similar questions but most of them discuss exporting full (i.e. no missing, rectangular) rasters or single-band rasters. I was wondering how could I export a multi-band raster with multiple noData cells similar to the gridded vector layer here:
Additional info: spatial ref: epsg:4326, GTiff, cell size 0.0270
My attempt:
xmin,ymin,xmax,ymax = [lons.min(),lats.min(),lons.max(),lats.max()]
xres = 0.0270
yres = 0.0270
geotransform=(xmin,xres,0,ymax,0, -yres)
output_raster = gdal.GetDriverByName('GTiff').Create(output_file, 9, 17, 1461, gdal.GDT_Float32) # Open the file
output_raster.SetGeoTransform(geotransform)
for i in range(1461):
output_raster.GetRasterBand(i+1).WriteArray(predictions)
output_raster.GetRasterBand(i+1).SetNoDataValue(noData)
output_raster.FlushCache()
Throws a: line 229, output_raster.GetRasterBand(i+1).WriteArray(predictions)
ValueError: array larger than output file, or offset off edge