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_path
str Path to save the raster. Must end with
.tifor.tiff. The directory must exist.- width
int,optional Raster width in pixels. Default is 100.
- height
int,optional Raster height in pixels. Default is 50.
- bands
int,optional Number of bands. Default is 4.
- incl_nodata
int,float,orNone,optional Value to fill selected bands to simulate nodata regions. Default is
None.- nodata_value
intorfloat,optional Metadata nodata value. Default is 0.
- dtype
strortype,optional Data type of raster array. Default is
'uint16'.- data
numpy.ndarray,optional Custom raster data of shape
(bands, height, width).If
None, synthetic data is generated. Default is None.
- raster_path
- Returns:
strPath of the created raster file.
- Return type:
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)