src.util

src.util.misc

src.util.misc.saveraster(gdal_data, filename, raster)[source]

Unchanged function to save raster data to a GeoTIFF file, using another opened in GDAL .TIFF file as basis.

Input:

gdal_data (gdal.Open): Basis gdal dataset filename (str): filename to save to raster (np.ndarray): raster array

src.util.shadowingfunctions

src.util.shadowingfunctions.shadowingfunction_20_3d(a, vegdem, vegdem2, azimuth, altitude, scale, amaxvalue, bush)[source]

Computes 3D building shadows and Vegetation shadows based on sun position using stepped projection.

This CuPy-accelerated method calculates shadow masks from a layered DSM (building & gap heights) & a CHM, simulating how shadows are cast given sun azimuth and altitude. Works on a 3D stack of DSM layers.

Parameters:
  • a (cp.ndarray) – 3D Layered DSM.

  • vegdem (cp.ndarray) – Vegetation height layer (CHM).

  • vegdem2 (cp.ndarray) – Secondary vegetation height layer (trunk heights).

  • azimuth (float) – Sun azimuth in degrees (clockwise from north).

  • altitude (float) – Sun altitude in degrees (0° = horizon, 90° = zenith).

  • scale (float) – Scale factor (pixel size in meters)

  • amaxvalue (float) – Maximum vertical height to simulate in the shadow projection.

Returns:

{

‘sh’: cp.ndarray, binary mask of building shadows on base layer (1 = lit, 0 = shadow), ‘vegsh’: cp.ndarray, binary mask of vegetation shadows on base layer (1 = lit, 0 = shadow), ‘vbshvegsh’: cp.ndarray, vegetation shadows not blocked by buildings on base layer.

}

Return type:

dict

src.util.shadowingfunctions.shadowingfunction_20_3d_90(a, vegdem, vegdem2)[source]

Computes binary shadow masks from buildings and vegetation for 3D DSM input under direct overhead sunlight (solar altitude = 90°).

Building shadows are determined by vertically projecting non-gap layers of the 3D DSM. Vegetation shadows are computed where both vegdem and vegdem2 are non-zero and not blocked by buildings.

Parameters:
  • a (cp.ndarray) – Layered 3D DSM.

  • vegdem (cp.ndarray) – Vegetation height layer (CHM).

  • vegdem2 (cp.ndarray) – Secondary vegetation height layer (trunk heights).

Returns:

{

‘sh’: cp.ndarray, binary mask of building shadows (1 = lit, 0 = shadow), ‘vegsh’: cp.ndarray, binary mask of vegetation shadows (1 = lit, 0 = shadow), ‘vbshvegsh’: cp.ndarray, vegetation shadows not blocked by buildings

}

Return type:

dict

src.util.shadowingfunctions.shadowingfunction_20_cupy(a, vegdem, vegdem2, azimuth, altitude, scale, amaxvalue, bush)[source]

Computes shadow masks for buildings and vegetation using a stepped projection method, based on sun position (azimuth, altitude) and elevation data. This is a CuPy-accelerated version optimized for GPU use. Two temporary arrays related to vegetation shading have been removed, and several optimizations applied to improve performance.

The function simulates shadow casting by iteratively stepping through the DSM and CHM along the direction of the sun, lowering the sun’s ray with each step, and comparing it to terrain heights to determine shadowed pixels.

Parameters:
  • a (cp.ndarray) – DSM.

  • vegdem (cp.ndarray) – Vegetation height layer (CHM).

  • vegdem2 (cp.ndarray) – Secondary vegetation height layer (trunk heights).

  • azimuth (float) – Sun azimuth in degrees (clockwise from north).

  • altitude (float) – Sun altitude in degrees (0° = horizon, 90° = zenith).

  • scale (float) – Scale factor (pixel size in meters)

  • amaxvalue (float) – Maximum vertical height to simulate in the shadow projection.

  • bush (cp.ndarray) – Bush indicator array (values > 1 indicate presence).

Returns:

{

‘sh’: cp.ndarray, binary mask of building shadows (1 = lit, 0 = shadow), ‘vegsh’: cp.ndarray, binary mask of vegetation shadows (1 = lit, 0 = shadow), ‘vbshvegsh’: cp.ndarray, vegetation shadows not blocked by buildings.

}

Return type:

dict

src.util.shadowingfunctions.shadowingfunction_20v2(a, vegdem, vegdem2, azimuth, altitude, scale, amaxvalue, trunkcheck, bush, forsvf)[source]

Computes shadow masks from buildings and vegetation based on sun position and elevation data.

This is a first attempt at a faster version of shadowing_20, designed to reduce computation by terminating the trunk zone shade casting early once all trunk heights are below the shadow casting threshold. It steps through the grid in the sun’s direction, checking for shadowing effects from buildings and vegetation.

Parameters:
  • a (ndarray) – DSM.

  • vegdem (ndarray) – Vegetation height layer (CHM).

  • vegdem2 (ndarray) – Secondary vegetation height layer (trunk heights).

  • azimuth (float) – Sun azimuth in degrees.

  • altitude (float) – Sun altitude in degrees.

  • scale (float) – Scale factor.

  • amaxvalue (float) – Maximum vertical extent to simulate shadows.

  • trunkcheck (boolean) – If True, use the trunk height check to stop trunk shade casting.

  • bush (ndarray) – Bush indicator array (values > 1 indicate presence).

  • forsvf (int) – Flag to indicate if called from SVF plugin (0 enables progress output).

Returns:

{

‘sh’: ndarray, binary mask of building shadows (1 = lit, 0 = shadow), ‘vegsh’: ndarray, binary mask of vegetation shadows (1 = lit, 0 = shadow), ‘vbshvegsh’: ndarray, vegetation shadows not blocked by buildings

}

Return type:

dict

src.util.shadowingfunctions.shadowingfunctionglobalradiation_3d(a, amaxvalue, azimuth, altitude, scale)[source]

Computes 3D building shadows based on sun position using stepped projection.

This CuPy-accelerated method calculates shadow masks from a layered DSM (building & gap heights), simulating how shadows are cast given sun azimuth and altitude. Works on a 3D stack of DSM layers.

Parameters:
  • a (cp.ndarray) – 3D Layered DSM.

  • azimuth (float) – Sun azimuth in degrees (clockwise from north).

  • altitude (float) – Sun altitude in degrees (0° = horizon, 90° = zenith).

  • scale (float) – Scale factor (pixel size in meters)

  • amaxvalue (float) – Maximum vertical height to simulate in the shadow projection.

Returns:

Binary mask of building shadows on base layer (1 = lit, 0 = shadow),

Return type:

sh (cp.ndarray)

src.util.shadowingfunctions.shadowingfunctionglobalradiation_3d_90(a)[source]

Computes building shadow mask for a 3D DSM input assuming a solar altitude of 90 degrees.

Shadows are determined by vertically projecting all values in the DSM layers (excluding gaps) that are greater than 1, simulating direct overhead sunlight.

Parameters:

a (cp.ndarray) – Layered 3D DSM.

Returns:

2D binary shadow mask (1 = illuminated, 0 = shadow).

Return type:

sh (cp.ndarray)

src.util.shadowingfunctions.shadowingfunctionglobalradiation_cupy(a, amaxvalue, azimuth, altitude, scale)[source]

Computes shadow masks for buildings using a stepped projection method, based on sun position (azimuth, altitude) and elevation data. This is a CuPy-accelerated version optimized for GPU use.

The function simulates shadow casting by iteratively stepping through the DSM grid along the direction of the sun, lowering the sun’s ray with each step, and comparing it to terrain heights to determine shadowed pixels.

Parameters:
  • a (cp.ndarray) – DSM.

  • azimuth (float) – Sun azimuth in degrees (clockwise from north).

  • altitude (float) – Sun altitude in degrees (0° = horizon, 90° = zenith).

  • scale (float) – Scale factor (pixel size in meters)

  • amaxvalue (float) – Maximum vertical height to simulate in the shadow projection.

Returns:

Binary mask of building shadows (1 = lit, 0 = shadow),

Return type:

sh (cp.ndarray)