swectral.create_example_raster#

swectral.create_example_raster(raster_path, width=100, height=50, bands=4, incl_nodata=None, nodata_value=0, dtype='uint16', data=None)#

Create a synthetic raster file for demonstration or testing purposes.

Generates a GeoTIFF raster with specified dimensions, number of bands, and data type. Custom data can also be provided. Optional nodata values can be applied to simulate missing data.

By default, it creates a 100x50 raster with 4 bands containing deterministic pseudo-random data.

Parameters:
raster_pathstr

Path to save the raster. Must end with .tif or .tiff. The directory must exist.

widthint, optional

Raster width in pixels. Default is 100.

heightint, optional

Raster height in pixels. Default is 50.

bandsint, optional

Number of bands. Default is 4.

incl_nodataint, float, or None, optional

Value to fill selected bands to simulate nodata regions. Default is None.

nodata_valueint or float, optional

Metadata nodata value. Default is 0.

dtypestr or type, optional

Data type of raster array. Default is 'uint16'.

datanumpy.ndarray, optional

Custom raster data of shape (bands, height, width).

If None, synthetic data is generated. Default is None.

Returns:
str

Path of the created raster file.

Return type:

str

Notes

  • The raster uses a simple linear gradient with pseudo-random noise.

  • No real CRS is assigned; transform is based on pixel coordinates.

  • If incl_nodata is set, first and last bands (if >3) are filled with this value.

Examples

Generate a default test raster:

>>> create_test_raster("test_raster.tif")

Generate a raster with custom dimensions and 3 bands:

>>> create_test_raster("custom_raster.tif", width=200, height=100, bands=3)

Provide custom data for the raster:

>>> import numpy as np
>>> data = np.random.randint(0, 256, size=(4, 50, 100), dtype='uint16')
>>> create_test_raster("custom_data_raster.tif", data=data)