eumap.raster.read_rasters¶
- 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
nodatavalue is replaced bynp.nanin case ofdtype=float*, and fordtype=*int*it’s replaced by the the lowest possible value inside the range (forint16this value is-32768).- Parameters
raster_dirs (
List) – A list of folders where the raster files are located. The raster are selected according to theraster_ext.raster_files (
List) – A list with the raster paths. Provide it and theraster_dirsis ignored.raster_ext (
str) – The raster file extension.spatial_win (
Optional[Window]) – Read the data according to the spatial window. By default isNone, reading all the raster data.dtype (
str) – Convert the read data to specificdtype. By default it reads infloat16to save memory, however pay attention in the precision limitations for thisdtype[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 equal0are converted tonp.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
Trueto print the reading progress.
- Returns
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]]
References
Examples
>>> import rasterio >>> from eumap.raster import read_rasters >>> >>> # EUMAP COG layers - NDVI seasons for 2000 >>> raster_files = [ >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_200003_eumap_epsg3035_v1.0.tif', # winter >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_200006_eumap_epsg3035_v1.0.tif', # spring >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_200009_eumap_epsg3035_v1.0.tif', # summer >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_200012_eumap_epsg3035_v1.0.tif' # fall >>> ] >>> >>> # Transform for the EPSG:3035 >>> eu_transform = rasterio.open(raster_files[0]).transform >>> # Bounding box window over Wageningen, NL >>> window = rasterio.windows.from_bounds(left=4020659, 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}')