skmap.io.base.save_rasters#
- save_rasters(base_raster, raster_files, array, window=None, bounds=None, dtype=None, nodata=None, array_idx=[], fit_in_dtype=False, n_jobs=8, on_each_outfile=None, 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 array in different rasters. GeoTIFF is the only output format supported. It always replaces the
np.nanvalue by the specifiednodata.- Parameters:
base_raster (
str) – The base raster path used to retrieve the parameters(height, width, n_bands, crs, dtype, transform)for the new rasters.raster_files (
List) – A list containing the paths for the new raster. It creates the folder hierarchy if not exists.array – 3D data array.
window (
Window) – Save the data considering a spatial window, even if thebase_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 (
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 skmap.io.base import read_rasters, save_rasters >>> >>> # skmap COG layers - NDVI seasons for 2019 >>> raster_files = [ ... 'http://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201903_skmap_epsg3035_v1.0.tif', # winter ... 'http://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201906_skmap_epsg3035_v1.0.tif', # spring ... 'http://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201909_skmap_epsg3035_v1.0.tif', # summer ... 'http://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_ndvi_landsat.glad.ard_p50_30m_0..0cm_201912_skmap_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, window=window, verbose=True) >>> >>> # Save in the current execution folder >>> raster_files = [ ... './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], raster_files, data, window=window, verbose=True)