Skip to main content
Bumped by Community user
Bumped by Community user
edited title
Link
sermomon
  • 1k
  • 7
  • 26

How to stack list of xarraysXarrays

deleted 1 character in body
Source Link
sermomon
  • 1k
  • 7
  • 26

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

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

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

Source Link
sermomon
  • 1k
  • 7
  • 26

How to stack list of xarrays

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