Sky Patches¶
Implements the Tregenza hemisphere subdivision (145 patches) used by all weighted carving modes. Each patch represents a solid-angle region of the sky dome; the weighting functions assign a weight to each patch depending on the analysis mode.
- Tregenza geometry: 145 direction vectors and their solid angles, following the standard subdivision used in climate-based daylight modelling.
- EPW-based weights (
compute_EPW_based_weights): forirradianceandbenefit, builds a cumulative sky matrix of direct and diffuse irradiance from an EPW weather file with the Perez all-weather sky model. Benefit keeps only hours with outdoor temperature below the balance point, or scales each hour by simulated weights. Fordaylight, returns the CIE overcast luminance distribution without reading an EPW. - Radiative cooling weights (
compute_radiative_cooling_weights): long-wave cooling potential per patch from the Martin-Berdahl clear-sky emissivity with Bliss angular attenuation.
urbansolarcarver.sky_patches
¶
UrbanSolarCarver Sky Patch Weighting Module
Generates sky-patch direction vectors, solid angles, and per-patch weight distributions for the voxel carving pipeline. P = 145 Tregenza patches.
Core Functions
-
fetch_tregenza_patch_directions(device) → torch.Tensor Lazily loads a Ladybug ViewSphere and returns a (P×3) tensor of unit vectors for the P Tregenza sky patches.
-
fetch_tregenza_patch_solid_angles(device) → torch.Tensor Returns a length-P tensor of solid angles (steradians) per patch.
tregenza_patch_cells() and sub_ray_directions(point_ids, patch_ids,
side, cells) define the jittered sub-rays that trace a patch as
side × side rays (rays_per_patch), which the Warp kernels compute.
-
compute_EPW_based_weights(mode, epw_path, hoys, device, ...) → torch.Tensor Per-patch weights for the modes time-based (uniform), daylight (CIE overcast sky), irradiance and benefit (climate-based, from a Ladybug SkyMatrix built with the Perez all-weather model; units kWh/m²).
-
compute_radiative_cooling_weights(dewpoint_celsius, bliss_k, device, min_elevation_deg) → torch.Tensor Theoretical long-wave radiative cooling potential per patch (Martin-Berdahl sky emissivity with Bliss angular variation). Assumes a horizontal analysis surface.
The weights are combined with per-voxel sky-patch visibility to accumulate exposure scores. The Tregenza vectors and solid angles are also usable on their own for diagnostics or custom weighting schemes.
gendaymtx_path()
¶
The gendaymtx program the sky matrix runs: the one in the pyradiance package, a dependency.
Before 0.12.2 Ladybug's SkyMatrix looked only for an installed Radiance (Ladybug Tools); on a computer without one, Solar energy and Solar heating stopped with "No Radiance installation was found". pyradiance's wheels carry Radiance's programs, so every installation runs the same gendaymtx. The package is located, not imported. Raises RuntimeError when pyradiance or its gendaymtx is missing.
fetch_tregenza_patch_directions(device)
¶
Return the 145 unit direction vectors of the Tregenza hemisphere subdivision (Tregenza, 1987). The dome divides the sky hemisphere into 145 patches of approximately equal solid angle, organized in 7 altitude rings (30, 30, 24, 24, 18, 12 and 6 patches) plus a zenith cap.
Returns a float32 tensor of shape [P, 3] (P = 145) on device, one
unit vector (x, y, z) per patch centre, with z pointing up (z = cos of
the zenith angle). Uses Ladybug's ViewSphere; the result is cached
per device for the session.
tregenza_solid_angles()
¶
Solid angle of each of the 145 Tregenza patches in steradians (float64).
Built from Ladybug's per-band constants rather than its
ViewSphere.tregenza_solid_angles property, which (ladybug-core
0.44) caches its result in the Reinhart attribute and so returns the
Reinhart list once reinhart_solid_angles has been read.
fetch_tregenza_patch_solid_angles(device)
¶
Return a float32 tensor of shape [P] (P = 145) with the solid angle of
each Tregenza sky patch in steradians, in the same order as
:func:fetch_tregenza_patch_directions (see :func:tregenza_solid_angles).
The result is cached per device for the session.
tregenza_patch_cells()
¶
The extent of each of the 145 Tregenza patches, (145, 4) float64.
Each row is (sin_alt_low, sin_alt_high, az_low, az_high): the patch
spans its band of altitude (12° per row, the zenith cap from 84° up) and
an equal share of azimuth around Ladybug's patch centre, azimuth in
radians clockwise from +Y like the centres themselves (a direction is
(cos alt sin az, cos alt cos az, sin alt)). The zenith cap spans
azimuth 0 to 2 pi. Equal steps of sin(altitude) and of azimuth inside a
patch cut it into cells of equal solid angle (:func:sub_ray_directions).
fetch_tregenza_patch_cells(device)
¶
:func:tregenza_patch_cells as a float32 (145, 4) tensor on device, cached for the session.
patch_facing_margin(cells, centres)
¶
sin of the largest angle between a patch's centre and any point of the patch.
A surface faces part of a patch only if dot(normal, centre) exceeds minus this value, so the sky-patch rays split into sub-rays keep every such patch (the sub-rays that face away are skipped in the kernels). Measured on 33 points along each edge of every patch.
sub_ray_directions(point_ids, patch_ids, side, cells)
¶
The side**2 sub-ray directions of each (sample point, sky patch) ray, (R * side**2, 3) float64.
The reference for the Warp kernels, which compute the same directions in
float32 (warp_kernels._sky_sub_ray_direction): ray r becomes
sub-rays r * side**2 + k. The patch is cut into side × side cells
of equal solid angle (equal steps of sin(altitude) and of azimuth, see
:func:tregenza_patch_cells), cell k being row k // side and
column k % side, and each sub-ray points at a place in its cell
drawn from a hash of the sample point, the patch and k: the same
point and patch give the same directions on every run, device and batch
size, and neighbouring points draw different ones, so their rays do not
line up into bands.
sky_emissivity_deficit(dewpoint_celsius, bliss_k, cos_zenith)
¶
1 - ε_dir, the share of a surface's long-wave emission the clear sky
does not return, toward directions at the zenith cosines cos_zenith
(float64).
Eq. 1 (Martin & Berdahl) and Eq. 2 (Bliss) of
:func:compute_radiative_cooling_weights, in NumPy and per direction,
for the sun and sky check: (1 - ε_sky) ** (1 / (k cos θ)) with
ε_sky clamped to [0, 0.999] and cos θ to at least 1e-3.
compute_radiative_cooling_weights(dewpoint_celsius, bliss_k, device, min_elevation_deg=0.0)
¶
Return a long-wave "cooling potential" weight for each Tregenza sky patch, given an outdoor dew-point temperature.
Scientific background
• Sky (hemispherical) emissivity, εₛky The clear-sky emissivity, integrated over the whole long-wave (thermal infrared) spectrum and the whole hemisphere, can be estimated from near-surface water-vapour content. Martin & Berdahl (1984) fit a quadratic in x = T_dp / 100, with the dew point T_dp in °C, to radiometer measurements of clear skies:
εₛky(x) = 0.758 + 0.521 x + 0.625 x² (Eq. 1)
A larger εₛky means the sky behaves more like a blackbody, sending more long-wave radiation back to the surface and therefore offering less cooling potential.
• Directional emissivity (ε_dir) Sky emissivity also depends on the zenith angle θ. Looking up, the line of sight crosses the thinnest layer of atmosphere, so the zenith has the lowest emissivity. Towards the horizon the path through the humid lower air grows like 1/cos θ and the emissivity approaches 1 (a blackbody). Bliss (1961) relates the hemispherical value of Eq. 1 to a direction-dependent value:
ε_dir(θ) = 1 - (1 - εₛky)^(1 /(k · cos θ)) (Eq. 2)
with k ≈ 1.8 for clear night skies. The code clamps cos θ to at least 1e-3 to avoid division by zero at the horizon (the lowest Tregenza patch centre is at 6° elevation, so the clamp does not change the result in practice).
• Radiative cooling potential Take a horizontal surface that is nearly black in the long wave and at about the air temperature. Its net long-wave loss towards patch p is proportional to the view factor of the patch times the emissivity deficit of that patch:
w_p ∝ (cos θ_p / π) · Ω_p · (1 - ε_dir(θ_p)) (Eq. 3)
(cos θ_p / π) · Ω_p is the view factor from the horizontal surface to a small patch of solid angle Ω_p. (1 - ε_dir) is the part of the surface's own emission that the sky does not return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dewpoint_celsius
|
float
|
Outdoor dew-point temperature [°C]. Acts as a proxy for absolute humidity in Eq. 1. A warning is issued outside [-15, 25] °C, the range treated as valid for the fit. |
required |
bliss_k
|
float
|
Empirical constant k from Bliss (1961) in Eq. 2. Must be positive; 1.8 is typical for clear skies, and values usually lie between 1.5 and 2.0. A larger k lowers the emissivity near the zenith, which increases the zenith-to-horizon contrast. |
required |
device
|
device
|
Target compute device for the returned tensor. |
required |
min_elevation_deg
|
float
|
Design-constraint protection cone: sky patches whose centre elevation is below this angle are excluded (weight 0) and the remaining weights renormalized. This is not part of the physical model. It declares which portion of the sky dome the design protects, similar to obstruction-angle rules in daylight codes. 0 (default) keeps the full hemisphere (pure physical model). |
0.0
|
Returns:
| Type | Description |
|---|---|
torch.Tensor (shape [P], P = 145 sky patches, dtype float32)
|
Cooling weights wᵢ ≥ 0 with Σ wᵢ = 1. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
- Assumes a horizontal analysis surface (flat roof). The view factor cos(θ)/π in Eq. 3 is only correct for an upward-facing horizontal surface. For tilted or vertical surfaces the cosine is taken to the surface normal instead, so applying these weights to them over-weights the zenith and under-weights low-altitude patches.
- Valid for clear nights; clouds would raise εₛky toward unity and flatten the weight distribution.
- The weights are normalized, dimensionless fractions; they can multiply any radiative heat-transfer quantity in further calculations.
References
- Bliss, R.W. 1961. "Atmospheric Radiation near the Surface of the Ground." Solar Energy 5 (3): 103-120.
- Martin, M. & Berdahl, P. 1984. "Characteristics of Infrared Sky Radiation in the United States." Solar Energy 33 (3-4): 321-336.
compute_EPW_based_weights(mode, epw_path, hoys, device=None, balance_temperature=15.0, balance_offset=2.0, north=0.0, include_harm=False, simulated_weights=None)
¶
Return a vector of sky-patch weights (length P = 145) derived from EnergyPlus Weather (EPW) data, or from the CIE overcast sky (daylight) or a uniform sky (time-based). Each weight expresses the relative importance of the corresponding Tregenza sky patch for a chosen metric:
┌──────────────┬──────────────────────────────────────────────┐
│ mode │ physical meaning of the weight wᵢ │
├──────────────┼──────────────────────────────────────────────┤
│ time-based │ uniform weight 1 for every patch │
│ daylight │ CIE overcast luminance Ω·(1+2 cos θ)/3 │
│ irradiance │ cumulative solar energy (direct+diffuse) │
│ benefit │ net *heating benefit* of solar gains │
└──────────────┴──────────────────────────────────────────────┘
Scientific background
-
Sky patch geometry: Tregenza subdivides the hemisphere into 145 patches of nearly equal solid angle.
fetch_tregenza_patch_directionsreturns the unit vectors d̂ᵢ = (xᵢ, yᵢ, zᵢ) with zᵢ = cos θᵢ (θ = zenith angle);fetch_tregenza_patch_solid_anglesreturns the solid angles Ωᵢ. -
time-based: uninformative baseline, wᵢ = 1 for every patch. Used for carving with traditional time-based solar envelope methods, where every unobstructed sun or sky direction counts equally.
-
daylight: the CIE Standard Overcast Sky (see Darula & Kittler 2002) prescribes a relative luminance L(θ) ∝ (1 + 2 cos θ)/3, three times brighter at the zenith than at the horizon. The weight is that luminance times the patch solid angle Ωᵢ, divided by its sum over the 145 patches: each weight is the patch's share of the overcast sky, and the weights sum to 1 (as the radiative_cooling ones do). A sample point whose whole sky is hidden then counts its whole area, so a daylight score is in m² of fully hidden sky.
-
irradiance: 'SkyMatrix.from_epw' (Ladybug Tools) builds a Perez all-weather sky for every hour, then sums the selected hours ('hoys') to obtain the cumulative short-wave energy per patch:
wᵢ = Σₜ (E_dirᵢₜ + E_difᵢₜ) [kWh m⁻²]
where E_dirᵢₜ is the direct-beam contribution and E_difᵢₜ the diffuse sky contribution of patch i in hour t.
-
benefit: heating-benefit filter. Only solar gains in hours cold enough to offset heating demand are credited,
wᵢ = Σₜ (E_dirᵢₜ + E_difᵢₜ) · H( T_bal - ΔT - Tₐₜ )
with the Heaviside step H (1 for a positive argument, else 0) and
Tₐₜ the outdoor dry-bulb temperature. The code selects the cold
hours from the EPW dry-bulb series and builds a plain cumulative
irradiance SkyMatrix over exactly those hours, so the formula above
is what is computed. Warm hours in the analysis period contribute
nothing, so a longer period does not dilute the result.
With include_harm=True (opt-in, experimental) the weights
instead follow Ladybug's composite radiation-benefit concept:
hot-hour (Tₐ > T_bal + ΔT) radiation is subtracted per patch and
the result clipped at zero,
wᵢ = max( Σ_cold E − Σ_hot E , 0 )
Results then depend on how much of the warm season the analysis
period includes. A patch's weight can drop to zero but not below,
because a negative weight (the value of shade) cannot be expressed
as a carving force.
'balance_temperature' (T_bal) is the building's free-running
balance point; derive project-specific values with the
Honeybee/EnergyPlus balance-point workflow. 'balance_offset' (ΔT)
is the half-width of the dead band around it (hours inside the band
count for neither side).
With simulated_weights the Heaviside step is replaced by hourly
weights in [0, 1] from an ISO 13790 zone model (see
:mod:urbansolarcarver.simulated_weights): each hour's irradiance
is scaled by benefit[t] (and, with include_harm, harm[t] is
subtracted the same way) before the sky matrix is summed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
(time - based, daylight, irradiance, benefit)
|
Weighting strategy (see table above). Case and surrounding whitespace are ignored. |
'time-based'
|
epw_path
|
str
|
Path to an EPW file. Required for irradiance and benefit. |
required |
hoys
|
Sequence[float]
|
Hour-of-year indices (0 to 8759) to sample. Required and non-empty for irradiance and benefit; ignored otherwise. For benefit, a full-year period is a sensible default: the balance filter selects the beneficial hours by itself. |
required |
device
|
device
|
Compute device for the returned tensor. |
'cuda' if available else 'cpu'
|
balance_temperature
|
float
|
Free-running balance-point temperature T_bal for the benefit filter. |
15 °C
|
balance_offset
|
float
|
Dead-band half-width ΔT: cold hours are below T_bal - ΔT; with
|
2 °C
|
north
|
float
|
North direction in degrees clockwise from +Y (USC convention). The weights are those of the sky turned by it, indexed by the patches in the model's frame (irradiance and benefit; the other skies are the same in every direction). |
0
|
include_harm
|
bool
|
Benefit mode only. Subtract hot-hour radiation per patch and clip at zero (experimental, see above). |
False
|
simulated_weights
|
tuple of two arrays
|
Benefit mode only. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Shape (P,), dtype float32, on |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
FileNotFoundError
|
If irradiance or benefit is requested without an existing EPW file. |
ValueError
|
If |
RuntimeError
|
If Ladybug's SkyMatrix does not return P patches. |
Notes
- The EPW-driven modes assume typical meteorology; rare events (e.g. > 99th percentile irradiance) may be under-represented.
- Without
simulated_weights, the benefit filter is purely temperature-based; construction, occupancy and HVAC control logic are not considered.
References
- Perez, R. et al. 1990. "Modeling daylight availability and irradiance components from direct and global irradiance." Solar Energy 44(5): 271-289.
- Darula, S. & Kittler, R. 2002. "CIE general sky standard defining luminance distributions." Proceedings eSim 11: 13.
- Ladybug Tools. "SkyMatrix": cumulative Radiance sky matrix (gendaymtx / Perez all-weather). https://www.ladybug.tools/ladybug-radiance/docs/