I am trying to read a GeoTIFF, perform calculations (radiometric correction) on all bands, and then output back to GeoTIFF. Most of the code I have works fine, up until trying to output.
import os
import rioxarray as rxr
import numpy as np
import pandas as pd
wv3tif = rxr.open_rasterio(os.path.join(os.getcwd(), "WV3 MUL GDA2020UTM55.tif"))
sensorvals = pd.read_excel(os.path.join("WV3_band_details.xlsx"))
L_bands = []
for band in range(len(sensorvals['Band no.'])):
L = np.add(np.multiply(wv3tif[band], (sensorvals['GAIN'][band] * sensorvals['abscalfactor'][band] / sensorvals['effectivebandwidth'][band])), sensorvals['OFFSET'][band])
L_bands.append(L)
L_bands.rio.to_raster("WV3 MUL GDA2020UTM55 TOA radiance.tif")
The last line throws an error 'numpy.ndarray' object has no attribute 'rio'
because the data is no longer an xarray.core.dataarray.DataArray
object. I have tried to vstack
but since that's a numpy
routine it only returns an ndarray
without the necessary output methods.
How do I stack the list of bands for output with rioxarray
, including outputting with original CRS and coords?
rioxarray
documentation and I just can't see a way to stack a list to an xarray DataArray for output.L_output = xa.DataArray(L_bands)
afterimport xarray as xa
. Not sure if there are corresponding methods inrioxarray
but this produces axarray.core.dataarray.DataArray
with the right shape. Now just have to work out how to copy the CRS and spatial dimensions etc.