functions.SOLWEIGpython¶
In this directory, all functions supporting SOLWEIG are found. Most of the functions are unchanged or only placed on the GPU.
Subpackages¶
- src.functions.SOLWEIGpython.UTIL
- functions.SOLWEIGpython.UTIL.Perez_v3
- functions.SOLWEIGpython.UTIL.Solweig_v2015_metdata_noload
- functions.SOLWEIGpython.UTIL.clearnessindex_2013b
- functions.SOLWEIGpython.UTIL.create_patches
- functions.SOLWEIGpython.UTIL.diffusefraction
- functions.SOLWEIGpython.UTIL.shadowingfunction_wallheight_13_cupy
- functions.SOLWEIGpython.UTIL.shadowingfunction_wallheight_23_cupy
- functions.SOLWEIGpython.UTIL.sun_distance
functions.SOLWEIGpython.Kside_veg_v2022a_cupy¶
- src.functions.SOLWEIGpython.Kside_veg_v2022a_cupy.Kside_veg_v2022a(radI, radD, radG, shadow, svfS, svfW, svfN, svfE, svfEveg, svfSveg, svfWveg, svfNveg, azimuth, altitude, psi, t, albedo, F_sh, KupE, KupS, KupW, KupN, cyl, lv, anisotropic_diffuse, diffsh, rows, cols, asvf, shmat, vegshmat, vbshvegshmat)[source]¶
Unchanged function to calculate shortwave radiation from the cardinal directions for vegetation.
functions.SOLWEIGpython.Kup_veg_2015a¶
- src.functions.SOLWEIGpython.Kup_veg_2015a.Kup_veg_2015a(radI, radD, radG, altitude, svfbuveg, albedo_b, F_sh, gvfalb, gvfalbE, gvfalbS, gvfalbW, gvfalbN, gvfalbnosh, gvfalbnoshE, gvfalbnoshS, gvfalbnoshW, gvfalbnoshN)[source]¶
Unchanged function to calculate upwards shortwave radiation for vegetation, eq 16 in lindberg influence of ground surf temp (2016)
functions.SOLWEIGpython.Kvikt_veg¶
functions.SOLWEIGpython.Lcyl_v2022a_cupy¶
- src.functions.SOLWEIGpython.Lcyl_v2022a_cupy.Lcyl_v2022a_cupy(esky, sky_patches, Ta, Tgwall, ewall, Lup, shmat, vegshmat, vbshvegshmat, solar_altitude, solar_azimuth, rows, cols, asvf)[source]¶
Function updated to use CuPy. This function combines the method to divide the sky vault into patches (Tregenza (1987) and Robinson & Stone (2004)) and the approach by Unsworth & Monteith or Martin & Berdahl (1984) or Bliss (1961) to calculate emissivities of the different parts of the sky vault.
- Parameters:
esky (float) – Effective hemispherical sky emissivity.
sky_patches (ndarray) – Array with patch altitude and azimuth in degrees.
Ta (float) – Air temperature in degrees Celsius.
Tgwall (ndarray) – Wall surface temperatures (°C).
ewall (ndarray) – Wall surface emissivities.
Lup (ndarray) – Upward longwave radiation.
shmat (cp.ndarray) – c
vegshmat (cp.ndarray) – c
vbshvegshmat (cp.ndarray) – c
solar_altitude (float) – Solar altitude angle in degrees.
solar_azimuth (float) – Solar azimuth angle in degrees.
rows (int) – Number of rows in the grid.
cols (int) – Number of columns in the grid.
asvf (ndarray) – Anisotropic Sky View Factor.
- Returns:
Ldown (cp.ndarray) – Longwave radiation from downward direction.
Lside (cp.ndarray) – Longwave radiation from side directions.
Lx (cp.ndarray) – Longwave radiation from (x = east, west, north, south) direction.
functions.SOLWEIGpython.Lside_veg_v2022a_cupy¶
- src.functions.SOLWEIGpython.Lside_veg_v2022a_cupy.Lside_veg_v2022a_cupy(svfS, svfW, svfN, svfE, svfEveg, svfSveg, svfWveg, svfNveg, svfEaveg, svfSaveg, svfWaveg, svfNaveg, azimuth, altitude, Ta, Tw, SBC, ewall, Ldown, esky, t, F_sh, CI, LupE, LupS, LupW, LupN, anisotropic_longwave)[source]¶
Function updated to use CuPy. Function computes directional longwave radiation fluxes from east, south, west, and north walls, accounting for shadowing, vegetation, and anisotropic sky contributions using a modified cylindrical wedge model.
- Parameters:
svfX (cp.ndarray) – Directional Sky View Factors (SVFs) (X = E, S, W, N).
svfXveg (cp.ndarray) – Vegetation-blocked SVFs.
svfXa_veg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
azimuth (float) – Solar azimuth angle in degrees.
altitude (float) – Solar altitude angle in degrees.
Ta (float) – Air temperature in °C.
Tw (float) – Wall surface temperature offset component.
SBC (float) – Stefan–Boltzmann constant.
ewall (float) – Emissivity of wall surfaces.
Ldown (cp.ndarray) – Downwelling longwave radiation from the sky.
esky (float) – Sky emissivity.
t (float) – Time correction factor (in degrees) to shift solar angles.
F_sh (cp.ndarray) – Fraction of the wall in direct sunlight (scaled 0–1).
CI (float) – Cloud index (0 = overcast, 1 = clear).
LupX (cp.ndarray) – Upwelling longwave radiation from ground for each direction (X = E, S, W, N).
anisotropic_longwave (bool) – If True, anisotropic scheme is used.
- Returns:
Longwave radiation received from the east-facing wall. Lsouth (cp.ndarray):
Longwave radiation received from the south-facing wall.
- Lwest (cp.ndarray):
Longwave radiation received from the west-facing wall.
- Lnorth (cp.ndarray):
Longwave radiation received from the north-facing wall.
- Ldown (cp.ndarray):
Longwave radiation received from above (sky).
- Lup (cp.ndarray):
Longwave radiation emitted upward from the surface.
- Return type:
Least (cp.ndarray)
functions.SOLWEIGpython.Lvikt_veg¶
functions.SOLWEIGpython.Solweig_2022a_calc_forprocessing_cupy¶
- src.functions.SOLWEIGpython.Solweig_2022a_calc_forprocessing_cupy.Solweig_2022a_calc(i, dsm, scale, rows, cols, svf, svfN, svfW, svfE, svfS, svfveg, svfNveg, svfEveg, svfSveg, svfWveg, svfaveg, svfEaveg, svfSaveg, svfWaveg, svfNaveg, vegdem, vegdem2, albedo_b, absK, absL, ewall, Fside, Fup, Fcyl, altitude, azimuth, zen, jday, usevegdem, onlyglobal, buildings, location, psi, landcover, lc_grid, dectime, altmax, dirwalls, walls, cyl, elvis, Ta, RH, radG, radD, radI, P, amaxvalue, amaxvalue_dsm, bush, Twater, TgK, Tstart, alb_grid, emis_grid, TgK_wall, Tstart_wall, TmaxLST, TmaxLST_wall, first, second, svfalfa, svfbuveg, firstdaytime, timeadd, timestepdec, Tgmap1, Tgmap1E, Tgmap1S, Tgmap1W, Tgmap1N, CI, TgOut1, diffsh, shmat, vegshmat, vbshvegshmat, anisotropic_sky, asvf, patch_option)[source]¶
Core computation function for SOLWEIG (SOlar and LongWave Environmental Irradiance Geometry) in the 3D-enabled version.
Originally developed by Fredrik Lindberg (2016-08-28), Gothenburg Urban Climate Group, University of Gothenburg. This version (2025, Jessica Monahan) includes support for 3D geometry and GPU acceleration using CuPy.
- Parameters:
i (int) – Index of current timestep or iteration.
dsm (cp.ndarray) – DSM containing building and ground elevations.
scale (float) – Height-to-pixel size ratio (e.g., 2m pixel → scale = 0.5).
rows (int) – Number of rows in the raster grid.
cols (int) – Number of columns in the raster grid.
svf (cp.ndarray) – Sky View Factor (total).
svfN (cp.ndarray) – Directional Sky View Factors (North, West, East, South).
svfW (cp.ndarray) – Directional Sky View Factors (North, West, East, South).
svfE (cp.ndarray) – Directional Sky View Factors (North, West, East, South).
svfS (cp.ndarray) – Directional Sky View Factors (North, West, East, South).
svfveg (cp.ndarray) – SVF blocked by vegetation (total).
svfNveg (cp.ndarray) – Directional vegetation-blocked SVFs.
svfEveg (cp.ndarray) – Directional vegetation-blocked SVFs.
svfSveg (cp.ndarray) – Directional vegetation-blocked SVFs.
svfWveg (cp.ndarray) – Directional vegetation-blocked SVFs.
svfaveg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
svfEaveg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
svfSaveg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
svfWaveg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
svfNaveg (cp.ndarray) – Vegetation SVFs blocking buildings (all directions).
vegdem (cp.ndarray) – Vegetation canopy height model (chm)
vegdem2 (cp.ndarray) – Vegetation trunk zone DSM.
albedo_b (float) – Wall albedo for buildings.
absK (float) – Human shortwave & longwave absorption coefficient.
asbL (float) – Human shortwave & longwave absorption coefficient.
ewall (float) – Emissivity of building walls.
Fside (float) – Angular view factors for a person (sides, upwards, cylindrical model).
Fup (float) – Angular view factors for a person (sides, upwards, cylindrical model).
Fcyl (float) – Angular view factors for a person (sides, upwards, cylindrical model).
altitude (float) – Solar altitude angle (degrees).
azimuth (float) – Solar azimuth angle (degrees).
zen (float) – Solar zenith angle (radians).
jday (int) – Julian day of year.
usevegdem (bool) – Flag to enable vegetation canopy effects.
onlyglobal (bool) – Use global shortwave input to estimate direct and diffuse (Reindl et al. 1990).
buildings (cp.ndarray) – Boolean grid identifying building locations.
location (tuple) – Geographic location (latitude, longitude).
psi (float) – Vegetation transmissivity (1 - transmissivity of shortwave).
landcover (bool) – Enable land cover classification scheme.
lc_grid (cp.ndarray) – Land cover classification grid.
dectime (float) – Decimal time of day.
altmax (float) – Maximum solar altitude.
dirwalls (cp.ndarray) – Wall aspect directions.
walls (cp.ndarray) – Wall height (one pixel thick row around building footprints).
cyl (bool) – If True, represent person as a cylinder (otherwise box).
elvis (int) – Dummy parameter for compatibility.
Ta (float) – Air temperature (°C).
RH (float) – Relative humidity (%).
radG (float) – Global solar radiation.
radD (float) – Diffuse solar radiation.
radI (float) – Direct solar radiation.
P (float) – Atmospheric pressure (hPa).
amaxvalue (float) – Maximum building height in DSM.
amaxvalue_dsm (float) – Max height for DSM layers.
bush (cp.ndarray) – Grid indicating bush locations.
Twater (float) – Daily water surface temperature (°C).
TgK (float) – Ground surface temperature (Kelvin).
Tstart (float) – Initial ground temperature (Kelvin).
alb_grid (cp.ndarray) – Ground albedo grid.
emis_grid (cp.ndarray) – Ground emissivity grid.
TgK_wall (float) – Initial wall surface temperature (Kelvin).
Tstart_wall (float) – Starting temperature for wall surface.
TmaxLST (float) – Max land surface temperature (ground).
TmaxLST_wall (float) – Max land surface temperature (wall).
first (float) – First height (sensor height) and second (sensor* 20) for Radiative surface influence
second (float) – First height (sensor height) and second (sensor* 20) for Radiative surface influence
svfalfa (cp.ndarray) – SVF recalculated to angular format.
svfbuveg (cp.ndarray) – Combined SVF including both buildings and vegetation.
firstdaytime (float) – Time of day for initialization (decimal hours).
timeadd (float) – Time step to add (hours).
timestepdec (float) – Time step (decimal hours).
Tgmap1 (cp.ndarray) – Ground temperature history maps (center + directions).
Tgmap1E (cp.ndarray) – Ground temperature history maps (center + directions).
Tgmap1S (cp.ndarray) – Ground temperature history maps (center + directions).
Tgmap1W (cp.ndarray) – Ground temperature history maps (center + directions).
Tgmap1N (cp.ndarray) – Ground temperature history maps (center + directions).
CI (float) – Clearness index.
TgOut1 (cp.ndarray) – Output ground temperature map from previous model run.
diffsh (float) – Shadowing fraction from vegetation or terrain.
shmat (cp.ndarray) – Shadow matrices (buildings, vegetation, and vegetation not blocked by buildings).
vegshmat (cp.ndarray) – Shadow matrices (buildings, vegetation, and vegetation not blocked by buildings).
vbshvegshmat (cp.ndarray) – Shadow matrices (buildings, vegetation, and vegetation not blocked by buildings).
anisotropic_sky (bool) – Enable anisotropic sky model (Wallenberg et al. 2019/2022).
asvf (cp.ndarray) – Anisotropic Sky View Factor.
patch_option (int) – Option for amount of patches.
- Returns:
Updated radiation and thermal comfort model outputs.
- src.functions.SOLWEIGpython.Solweig_2022a_calc_forprocessing_cupy.Solweig_2022a_calc_3d(i, dsms, scale, rows, cols, svf, svfN, svfW, svfE, svfS, svfveg, svfNveg, svfEveg, svfSveg, svfWveg, svfaveg, svfEaveg, svfSaveg, svfWaveg, svfNaveg, vegdem, vegdem2, albedo_b, absK, absL, ewall, Fside, Fup, Fcyl, altitude, azimuth, zen, jday, usevegdem, onlyglobal, buildings, location, psi, landcover, lc_grid, dectime, altmax, dirwalls, walls, cyl, elvis, Ta, RH, radG, radD, radI, P, amaxvalue, amaxvalue_dsm, bush, Twater, TgK, Tstart, alb_grid, emis_grid, TgK_wall, Tstart_wall, TmaxLST, TmaxLST_wall, first, second, svfalfa, svfbuveg, firstdaytime, timeadd, timestepdec, Tgmap1, Tgmap1E, Tgmap1S, Tgmap1W, Tgmap1N, CI, TgOut1, diffsh, shmat, vegshmat, vbshvegshmat, anisotropic_sky, asvf, patch_option, version)[source]¶
Core computation function for SOLWEIG (SOlar and LongWave Environmental Irradiance Geometry) in the 3D-enabled version.
Originally developed by Fredrik Lindberg (2016-08-28), Gothenburg Urban Climate Group, University of Gothenburg. This version (2025, Jessica Monahan) includes support for 3D geometry and GPU acceleration using CuPy.
- Parameters:
dsms (cp.ndarray) – 3D-layered DSM containing building and ground elevations, and gap layers.
other_parameters – see Solweig_2022a_calc for the others
- Returns:
Updated radiation and thermal comfort model outputs.
functions.SOLWEIGpython.Tgmaps_v1_cupy¶
functions.SOLWEIGpython.TsWaveDelay_2015a¶
functions.SOLWEIGpython.WriteMetadataSOLWEIG¶
- src.functions.SOLWEIGpython.WriteMetadataSOLWEIG.writeRunInfo(folderPath, filepath_dsm, gdal_dsm, usevegdem, filePath_cdsm, trunkfile, filePath_tdsm, lat, lon, UTC, landcover, filePath_lc, metfileexist, filePath_metfile, metdata, absK, absL, albedo_b, albedo_g, ewall, eground, onlyglobal, trunkratio, trans, rows, cols, pos, elvis, cyl, demforbuild, ani)[source]¶
Unchanged function to store the model run info for SOLWEIG
functions.SOLWEIGpython.cylindric_wedge_cupy¶
- src.functions.SOLWEIGpython.cylindric_wedge_cupy.cylindric_wedge_cupy(zen, svfalfa, rows, cols)[source]¶
Function has been updated to use CuPy. Function Computes the fraction of sunlit wall surface based on the solar zenith angle and a sky-view-factor-related wall angle using the cylindric wedge model.
This model estimates how much of a wall is sunlit based on urban canyon geometry. It assumes the canyon walls form a cylindrical wedge and calculates the projected sunlit fraction analytically.
- Parameters:
zen (float) – Solar zenith angle in radians (angle between the sun and the vertical).
svfalfa (float or cp.ndarray) – Scalar or 2D CuPy array representing the SVF-weighted building wall inclination angle (in radians).
rows (int) – Number of rows in the output grid.
cols (int) – Number of columns in the output grid.
- Returns:
Array representing the fraction of the wall surface that is directly sunlit for each grid cell.
- Return type:
F_sh (cp.ndarray)
functions.SOLWEIGpython.daylen¶
- src.functions.SOLWEIGpython.daylen.daylen(DOY, XLAT)[source]¶
Unchanged function: Calculate solar declination, daylength, and sunrise/sunset times based on day of year and latitude.
- Parameters:
DOY (int) – Day of year (1–365), with 1 = Jan 1.
XLAT (float) – Latitude in degrees (positive = Northern Hemisphere, negative = Southern Hemisphere).
- Returns:
Daylength in hours. DEC (float): Solar declination angle in degrees. SNDN (float): Sunset time in decimal hours (e.g., 18.0 = 6:00 PM). SNUP (float): Sunrise time in decimal hours (e.g., 6.0 = 6:00 AM).
- Return type:
DAYL (float)
Notes
Declination is calculated using a cosine-based approximation with amplitude ±23.45°.
Valid for most latitudes; limited accuracy near polar circles.
functions.SOLWEIGpython.emissivity_models¶
These are the functions of the emissivity models implemented in the SOLWEIGpython module. These models are used to calculate emissivity from the sky sphere.
- src.functions.SOLWEIGpython.emissivity_models.model1(sky_patches, esky, Ta)[source]¶
Model 1 is based on Unsworth & Monteith, 1975
functions.SOLWEIGpython.gvf_2018a_cupy¶
- src.functions.SOLWEIGpython.gvf_2018a_cupy.gvf_2018a_cupy(wallsun, walls, buildings, scale, shadow, first, second, dirwalls, Tg, Tgwall, Ta, emis_grid, ewall, alb_grid, SBC, albedo_b, rows, cols, Twater, lc_grid, landcover)[source]¶
Calculates ground view factors for longwave and shortwave radiation from urban surfaces using GPU-accelerated computation with CuPy, based on directional azimuths.
- Parameters:
wallsun (cp.ndarray) – Array representing sunlit portions of walls.
walls (cp.ndarray) – Array of wall heights.
buildings (cp.ndarray) – 2D boolean grid indicating building pixels.
scale (float) – Scale factor converting units to pixels.
shadow (cp.ndarray) – 2D binary shadow mask (1 = shadowed, 0 = sunlit).
first (float) – First sensor height for radiative surface influence.
second (float) – Second sensor height (usually first * 20) for radiative surface influence.
dirwalls (float) – Direction of building walls in degrees.
Tg (cp.ndarray) – 2D grid of ground temperatures [°C].
Tgwall (cp.ndarray) – 2D grid of wall temperatures [°C].
Ta (float) – Air temperature [°C].
emis_grid (cp.ndarray) – Emissivity grid for surfaces.
ewall (float) – Wall emissivity.
alb_grid (cp.ndarray) – Albedo grid for surfaces.
SBC (float) – Stefan-Boltzmann constant.
albedo_b (float) – Building wall albedo.
rows (int) – Number of rows in grids.
cols (int) – Number of columns in grids.
Twater (float) – Water temperature [°C].
lc_grid (cp.ndarray) – Landcover classification grid.
landcover (int) – Landcover type indicator.
- Returns:
gvfLup (cp.ndarray) – Grid of longwave upwelling radiation view factors (averaged over azimuths).
gvfalb (cp.ndarray) – Grid of albedo-weighted view factors including shadows (averaged over azimuths).
gvfalbnosh (cp.ndarray) – Grid of albedo-weighted view factors excluding shadows (averaged over azimuths).
gvfLupE (cp.ndarray) – East-facing longwave upwelling radiation view factors.
gvfalbE (cp.ndarray) – East-facing albedo-weighted view factors including shadows.
gvfalbnoshE (cp.ndarray) – East-facing albedo-weighted view factors excluding shadows.
gvfLupS (cp.ndarray) – South-facing longwave upwelling radiation view factors.
gvfalbS (cp.ndarray) – South-facing albedo-weighted view factors including shadows.
gvfalbnoshS (cp.ndarray) – South-facing albedo-weighted view factors excluding shadows.
gvfLupW (cp.ndarray) – West-facing longwave upwelling radiation view factors.
gvfalbW (cp.ndarray) – West-facing albedo-weighted view factors including shadows.
gvfalbnoshW (cp.ndarray) – West-facing albedo-weighted view factors excluding shadows.
gvfLupN (cp.ndarray) – North-facing longwave upwelling radiation view factors.
gvfalbN (cp.ndarray) – North-facing albedo-weighted view factors including shadows.
gvfalbnoshN (cp.ndarray) – North-facing albedo-weighted view factors excluding shadows.
gvfSum (cp.ndarray) – Sum of combined sun/shadow view factors across all azimuth directions.
gvfNorm (cp.ndarray) – Normalized view factor grid where non-building areas are set to 1.
functions.SOLWEIGpython.patch_characteristics_cupy¶
- src.functions.SOLWEIGpython.patch_characteristics_cupy.define_patch_characteristics(solar_altitude, solar_azimuth, patch_altitude, patch_azimuth, steradian, asvf, shmat, vegshmat, vbshvegshmat, Lsky_down, Lsky_side, Lsky, Lup, Ta, Tgwall, ewall, rows, cols)[source]¶
This unchanged function defines if a patch seen from a pixel is sky, building or vegetation. It also calculates if a building patch is sunlit or shaded. From this it estimates corresponding longwave radiation originating from each surface.
functions.SOLWEIGpython.sunlit_shaded_patches¶
functions.SOLWEIGpython.sunonsurface_2018a_cupy¶
- src.functions.SOLWEIGpython.sunonsurface_2018a_cupy.sunonsurface_2018a_cupy(azimuthA, scale, buildings, shadow, sunwall, first, second, aspect, walls, Tg, Tgwall, Ta, emis_grid, ewall, alb_grid, SBC, albedo_b, Twater, lc_grid, landcover)[source]¶
Calculates surface and wall sun/shadow and radiation interactions based on building geometry and sun position. This CuPy-accelerated implementation simulates sunlit and shadowed surfaces on buildings and ground, including longwave upwelling radiation (Lup) and albedo effects modulated by landcover and shadow patterns.
- Parameters:
azimuthA (float) – Search directions for Ground View Factors (clockwise from north).
scale (float) – Scale factor converting units to pixels.
buildings (cp.ndarray) – 2D boolean grid indicating building pixels.
shadow (cp.ndarray) – 2D binary shadow mask (1 = shadowed, 0 = sunlit).
sunwall (cp.ndarray) – 2D array marking sunlit building walls.
first (float) – First height (sensor height) for Radiative surface influence
second (float) – Second height (sensor height * 20) for Radiative surface influence
aspect (cp.ndarray) – 2D array of building wall aspect (orientation in radians).
walls (cp.ndarray) – 2D array of wall heights.
Tg (cp.ndarray) – 2D grid of ground temperatures [°C].
Tgwall (cp.ndarray) – 2D grid of wall temperatures [°C].
Ta (float) – Air temperature [°C].
emis_grid (cp.ndarray) – Emissivity grid for surfaces.
ewall (float) – Wall emissivity.
alb_grid (cp.ndarray) – Albedo grid for surfaces.
SBC (float) – Stefan-Boltzmann constant.
albedo_b (float) – Building wall albedo.
Twater (float) – Water temperature [°C].
lc_grid (cp.ndarray) – Landcover classification grid.
landcover (int) – Landcover type indicator.
- Returns:
gvf (cp.ndarray) – Grid of combined sun/shadow view factors on surfaces.
gvfLup (cp.ndarray) – Grid of longwave upwelling radiation view factors.
gvfalb (cp.ndarray) – Grid of albedo-weighted view factors including shadows.
gvfalbnosh (cp.ndarray) – Grid of albedo-weighted view factors excluding shadows.
gvf2 (cp.ndarray) – Grid of secondary view factors combining wall and surface shadows.