Skip to content

Texture Processors

Map land cover classes to a base material selection texture, then modify it with material-region and road overlays. See Texture generation.

Base selection texture

s2gos_generator.processors.terrain_texture.terrain_material.TerrainMaterialGenerator

TerrainMaterialGenerator(
    materials: Optional[List[Dict]] = None,
)

Generates terrain material selection textures from land cover data for use in 3D rendering.

Initialize the terrain material generator.

Parameters:

Name Type Description Default
materials Optional[List[Dict]]

List of material definitions. If None, uses default materials.

None

Functions

create_preview_texture

create_preview_texture(
    landcover_data: DataArray,
    output_path: UPath,
    flip_vertical: bool = True,
) -> np.ndarray

Creates a color preview texture showing the actual material colors.

Parameters:

Name Type Description Default
landcover_data DataArray

xarray DataArray containing land cover class values.

required
output_path UPath

UPath where the preview PNG will be saved.

required
flip_vertical bool

If True, flips the texture vertically.

True

Returns:

Type Description
ndarray

The preview texture as a numpy array with shape (height, width, 3).

generate_textures_from_file

generate_textures_from_file(
    landcover_file_path: UPath,
    output_dir: UPath,
    base_name: str,
    create_preview: bool = True,
    dem_file_path: Optional[UPath] = None,
    season_month: Optional[str] = None,
    snow_material_index: Optional[int] = None,
    coordinate_system=None,
    snow_thermoprops: Optional[UPath] = None,
    random_seed: Optional[int] = None,
) -> Tuple[UPath, Optional[UPath]]

Complete pipeline: loads land cover from file and generates textures.

Parameters:

Name Type Description Default
landcover_file_path UPath

UPath to the land cover NetCDF file.

required
output_dir UPath

Directory where textures will be saved.

required
base_name str

Base name for output files.

required
create_preview bool

Whether to create a color preview texture.

True
dem_file_path Optional[UPath]

Optional UPath to DEM file for seasonal snow adjustment.

None
season_month Optional[str]

Optional month name for seasonal snow adjustment.

None
snow_material_index Optional[int]

Optional material index for snow.

None
coordinate_system

Optional CoordinateSystem for scene-to-latlon conversion.

None
snow_thermoprops Optional[UPath]

Optional path to CAMS thermoprops NetCDF file.

None

Returns:

Type Description
Tuple[UPath, Optional[UPath]]

Tuple of (selection_texture_path, preview_texture_path).

get_material_info

get_material_info() -> Dict

Returns information about the configured materials.

Returns:

Type Description
Dict

Dictionary containing material configuration details.

landcover_to_selection_texture

landcover_to_selection_texture(
    landcover_data: DataArray,
    output_path: UPath,
    flip_vertical: bool = False,
    default_material_index: int = PERMANENT_WATER_MATERIAL_INDEX,
    dem_data: Optional[DataArray] = None,
    season_month: Optional[str] = None,
    snow_material_index: Optional[int] = None,
    coordinate_system=None,
    snow_thermoprops: Optional[UPath] = None,
    random_seed: Optional[int] = None,
) -> np.ndarray

Converts land cover classification data to a material selection texture.

Parameters:

Name Type Description Default
landcover_data DataArray

xarray DataArray containing land cover class values.

required
output_path UPath

UPath where the texture PNG will be saved.

required
flip_vertical bool

If True, flips the texture vertically (for Mitsuba compatibility).

False
default_material_index int

Material index to use for unknown classes.

PERMANENT_WATER_MATERIAL_INDEX
dem_data Optional[DataArray]

Optional DEM DataArray for seasonal snow adjustment.

None
season_month Optional[str]

Optional month name for seasonal snow adjustment.

None
snow_material_index Optional[int]

Optional material index to use for snow.

None
coordinate_system

Optional CoordinateSystem for scene-to-latlon conversion.

None
snow_thermoprops Optional[UPath]

Optional path to CAMS thermoprops NetCDF file.

None

Returns:

Type Description
ndarray

The selection texture as a numpy array.

Region & road overlays

s2gos_generator.processors.terrain_texture.overlays.apply_region_materials

apply_region_materials(
    texture_2d: ndarray,
    landcover_path: Path,
    applicable_regions: list,
    coord_system,
    material_index_map: dict[str, int],
    area_name: str = "texture",
) -> tuple[np.ndarray, bool]

Apply material region overlays to an in-memory texture array.

Parameters:

Name Type Description Default
texture_2d ndarray

2-D array

required
landcover_path Path

Path to landcover zarr file

required
applicable_regions list

List of MaterialRegion configs to apply

required
coord_system

Scene coordinate system (from ctx.coordinate_system)

required
material_index_map dict[str, int]

Mapping of material name to texture index

required
area_name str

Name for logging (e.g., "target texture", "buffer texture")

'texture'

Returns:

Type Description
tuple[ndarray, bool]

(texture_2d, modified) where modified is True if any pixels were changed.

s2gos_generator.processors.terrain_texture.overlays.apply_roads

apply_roads(
    texture_2d: ndarray,
    landcover_path: Path,
    road_polygons_by_material: dict,
    road_material_indices: dict[str, int],
    texture_resolution_m: Optional[float] = None,
    area_name: str = "target",
) -> tuple[np.ndarray, Optional[np.ndarray]]

Rasterize road polygons onto an in-memory texture array.

Parameters:

Name Type Description Default
texture_2d ndarray

2-D uint8 array to modify (may be resized if texture_resolution_m is finer than the landcover resolution)

required
landcover_path Path

Path to landcover zarr (for resolution/bounds)

required
road_polygons_by_material dict

Merged road polygon per material name (from ctx.road_polygons_by_material)

required
road_material_indices dict[str, int]

Mapping of material_name to texture index

required
texture_resolution_m Optional[float]

Target texture resolution (from ctx.config.texture_resolution_m); upsamples when finer than native

None
area_name str

Logging label

'target'

Returns:

Type Description
ndarray

(texture_2d, union_mask) — texture_2d may have new dimensions after

Optional[ndarray]

upsampling; union_mask is a boolean array of every painted road pixel

tuple[ndarray, Optional[ndarray]]

(same shape as the returned texture_2d), or None if no roads were

tuple[ndarray, Optional[ndarray]]

applied. The caller can reuse it to overlay roads on the preview texture.

s2gos_generator.processors.terrain_texture.overlays.apply_roads_to_preview

apply_roads_to_preview(
    preview_path: Path,
    road_mask: ndarray,
    debug_color: tuple[int, int, int] = (50, 50, 50),
) -> None

Resize the RGB preview to match road_mask and paint roads on it.