read_rasters(raster_dirs=[], raster_files=[], raster_ext='tif', spatial_win=None, dtype='float16', n_jobs=4, data_mask=None, expected_img_size=None, try_without_window=False, verbose=False)[source]

Read raster files aggregating them into a single array. Only the first band of each raster is read.

The nodata value is replaced by np.nan in case of dtype=float*, and for dtype=*int* it’s replaced by the the lowest possible value inside the range (for int16 this value is -32768).

  • raster_dirs (List) – A list of folders where the raster files are located. The raster are selected according to the raster_ext.

  • raster_files (List) – A list with the raster paths. Provide it and the raster_dirs is ignored.

  • raster_ext (str) – The raster file extension.

  • spatial_win (Optional[Window]) – Read the data according to the spatial window. By default is None, reading all the raster data.

  • dtype (str) – Convert the read data to specific dtype. By default it reads in float16 to save memory, however pay attention in the precision limitations for this dtype [1].

  • n_jobs (int) – Number of parallel jobs used to read the raster files.

  • data_mask (Optional[array]) – A array with the same space dimensions of the read data, where all the values equal 0 are converted to np.nan.

  • expected_img_size – The expected size (space dimension) of the read data. In case of error in reading any of the raster files, this is used to create a empty 2D array. By default is None, throwing a exception if the raster doesn’t exists.

  • try_without_window – First, try to read using spatial_win, if fails try to read without it.

  • verbose – Use True to print the reading progress.


A 3D array, where the last dimension refers to the read files, and a list containing the read paths.

Return type

Tuple[Numpy.array, List[Path]]


[1] Float16 Precision


>>> import rasterio
>>> from eumap.raster import read_rasters
>>> # EUMAP COG layers - NDVI seasons for 2000
>>> raster_files = [
>>>     '', # winter
>>>     '', # spring
>>>     '', # summer
>>>     ''  # fall
>>> ]
>>> # Transform for the EPSG:3035
>>> eu_transform =[0]).transform
>>> # Bounding box window over Wageningen, NL
>>> window =, bottom=3213544, right=4023659, top=3216544, transform=eu_transform)
>>> data, _ = read_rasters(raster_files=raster_files, spatial_win=window, verbose=True)
>>> print(f'Data shape: {data.shape}')