I have a folder with 4 .tiff (GeoTiff) files. Each of these contains two layers (the spectral band and a mask). I'm able to create a list containig each image using xarray.open_rasterio
.
Now I need to stack the bands of the list into a single DataArray
. How can I do this?
# Path of the folder containing the .tiff files
IMG_PATH = 'D:/test_xarray/data/'
import rasterio as rio
import xarray as xr
import numpy as np
from glob import glob
# List of .tiff files
sentinel_bands = glob(f"{IMG_PATH}*B?*.tiff")
sentinel_bands.sort() # sorted list
ls_bands = [] # list filled with the first layer of each file
for band in sentinel_bands:
with xr.open_rasterio(band) as b:
ls_bands.append(b[0,]) # index 0 corresponds to the first band of each file
# Stack bands into a single DataArray
Data available here https://github.com/syamkakarla98/Satellite_Imagery_Analysis/tree/main/Data/sundarbans_raw_data