eumap.raster.save_rasters¶
- save_rasters(fn_base_raster, fn_raster_list, data, spatial_win=None, dtype=None, nodata=None, fit_in_dtype=False, n_jobs=4, verbose=False)[source]¶
Save a 3D array in multiple raster files using as reference one base raster. The last dimension is used to split the data in different rasters. GeoTIFF is the only output format supported. It always replaces the
np.nanvalue by the specifiednodata.- Parameters
fn_base_raster (
str) – The base raster path used to retrieve the parameters(height, width, n_bands, crs, dtype, transform)for the new rasters.fn_raster_list (
List) – A list containing the paths for the new raster. It creates the folder hierarchy if not exists.data (
array) – 3D data array.spatial_win (
Optional[Window]) – Save the data considering a spatial window, even if thefn_base_rastersrefers to a bigger area. For example, it’s possible to have a base raster covering the whole Europe and save the data using a window that cover just part of Wageningen. By default isNonesaving the raster data in position0, 0of the raster grid.dtype (
Optional[str]) – Convert the data to a specificdtypebefore save it. By default isNoneusing the samedtypefrom the base raster.nodata – Use the specified value as
nodatafor the new rasters. By default isNoneusing the samenodatafrom the base raster.fit_in_dtype (
bool) – IfTruethe values outside ofdtyperange are truncated to the minimum and maximum representation. It’s also change the minimum and maximum data values, if they exist, to avoid overlap withnodata(see the_fit_in_dtypefunction). For example, ifdtype='uint8'andnodata=0, all data values equal to0are re-scaled to1in the new rasters.n_jobs (
int) – Number of parallel jobs used to save the raster files.verbose (
bool) – UseTrueto print the saving progress.
- Returns
A list containing the path for new rasters.
- Return type
List[Path]
Examples
>>> import rasterio >>> from eumap.raster import read_rasters, save_rasters >>> >>> # EUMAP COG layers - NDVI seasons for 2019 >>> raster_files = [ >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201903_eumap_epsg3035_v1.0.tif', # winter >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201906_eumap_epsg3035_v1.0.tif', # spring >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201909_eumap_epsg3035_v1.0.tif', # summer >>> 'http://s3.eu-central-1.wasabisys.com/eumap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201912_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) >>> >>> # Save in the current execution folder >>> fn_raster_list = [ >>> './lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201903_wageningen_epsg3035_v1.0.tif', >>> './lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201906_wageningen_epsg3035_v1.0.tif', >>> './lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201909_wageningen_epsg3035_v1.0.tif', >>> './lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201912_wageningen_epsg3035_v1.0.tif' >>> ] >>> >>> save_rasters(raster_files[0], fn_raster_list, data, spatial_win=window, verbose=True)