Scoring¶
Sky-patch weight dispatch and threshold selection:
- Weight dispatch (
get_weights): calls the sky-patch weighting function for the selected mode (Perez irradiance, heating benefit, CIE daylight luminance, or radiative cooling). - Thresholds, applied by the thresholding stage to the raw scores of the occupied voxels:
carve_fraction_threshold: the cutoff above which the voxels hold a given fraction of the total score mass.headtail_threshold: Jiang (2013) head/tail breaks for heavy-tailed score distributions.- A numeric cutoff from the config is used as given.
urbansolarcarver.scoring
¶
UrbanSolarCarver scoring module
Sky-patch weight computation and threshold selection for voxel carving.
-
get_weights(mode, device, epw_file, hoys, …) → torch.Tensor Per-patch weight vector for the specified mode. Delegates to compute_EPW_based_weights (sky_patches.py) for irradiance, benefit and daylight, and to compute_radiative_cooling_weights for radiative_cooling. Inside a CarverSession the result is cached, keyed by every argument and by the contents of the EPW and simulated-weights files, so a preprocessing run with unchanged weather settings skips the sky matrix.
-
carve_fraction_threshold(scores, fraction) → float Score cutoff above which the highest-scoring voxels hold fraction of the total score.
-
headtail_threshold(scores) → float Head/tail breaks (Jiang 2013): repeatedly splits a right-skewed score distribution at its arithmetic mean. Suited to obstruction scores, which are usually heavy-tailed.
get_weights(mode, device=None, epw_file=None, hoys=None, dew_point_celsius=14.0, bliss_k=1.8, balance_temperature=15.0, balance_offset=2.0, north_deg=0.0, min_sky_elevation_deg=0.0, include_harm=False, simulated_weights_path=None)
¶
Return one weight per Tregenza sky patch for the given analysis mode.
- irradiance: cumulative direct + diffuse irradiance per patch over the hours in hoys (kWh/m²), from the EPW via a Ladybug sky matrix.
- benefit: the same, counted only in hours below the heating balance point (balance_temperature minus balance_offset); with include_harm, irradiance in hours above balance_temperature plus balance_offset is subtracted (clipped at 0).
- daylight: CIE standard overcast sky luminance; needs no EPW.
- radiative_cooling: long-wave cooling potential from the dew point (Martin-Berdahl emissivity, Bliss angular law), normalized to sum to 1.
'time-based' and 'tilted_plane' do not use sky-patch weights and raise ValueError here.
Inside a CarverSession the weights are cached (see the module notes): the returned tensor may be shared, so callers must not modify it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
One of 'irradiance', 'benefit', 'daylight', 'radiative_cooling' (case and surrounding spaces are ignored). |
required |
device
|
device or str
|
Device of the returned tensor; default CUDA if available, else CPU. |
None
|
epw_file
|
str
|
EPW weather file; required for irradiance and benefit. |
None
|
hoys
|
Sequence[int]
|
Hour-of-year indices (0..8759); required for irradiance and benefit. |
None
|
dew_point_celsius
|
float
|
Dew-point temperature for radiative_cooling (°C). |
14.0
|
bliss_k
|
float
|
Bliss angular-attenuation constant for radiative_cooling. |
1.8
|
balance_temperature
|
float
|
Free-running balance-point temperature for benefit (°C). |
15.0
|
balance_offset
|
float
|
Dead band around the balance point for benefit (°C). |
2.0
|
north_deg
|
float
|
Model north, degrees clockwise from +Y (irradiance, benefit, daylight). |
0.0
|
min_sky_elevation_deg
|
float
|
radiative_cooling only: patches below this elevation get weight 0. |
0.0
|
include_harm
|
bool
|
benefit only: subtract hot-hour irradiance, as described above. |
False
|
simulated_weights_path
|
str
|
benefit only: file of simulated hourly benefit/harm weights, read
with :func: |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Shape (P,), one non-negative weight per sky patch (P = 145). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mode is not a non-empty string. |
ValueError
|
If mode is not supported, or epw_file / hoys are missing for irradiance or benefit. |
FileNotFoundError
|
If epw_file is given but does not exist (irradiance, benefit). |
carve_fraction_threshold(scores, fraction, mass=None)
¶
Score-mass cutoff: the threshold above which voxels collectively account for fraction of the total score mass.
Equivalent to sorting all scores descending and walking the cumulative
sum until it reaches fraction * total. With mass, the voxels are
ranked by scores but the sum counts mass (thresholding ranks by the
cutoff at which carve_above removes a voxel and counts each voxel's own
score, so the fraction includes what carve_above removes). A full sort of a large grid
is O(N log N) and takes seconds to minutes at 300³ voxels and above, so
this implementation makes two O(N) passes instead:
- A weighted histogram locates the bin containing the cutoff.
- Only the scores inside that single bin (N / n_bins expected) are sorted exactly, reproducing the argsort result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
ndarray
|
Array of non-negative voxel scores (any shape). |
required |
fraction
|
float
|
Fraction of the total score mass to carve, in [0, 1]. |
required |
mass
|
ndarray
|
Non-negative mass of each voxel, same shape as scores; default scores itself. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Threshold value; voxels scoring strictly above it are carved. |
headtail_threshold(scores, max_iterations=50, head_limit=0.4)
¶
Head/tail breaks cutoff (Jiang, 2013).
Split the scores at their mean. If the part above the mean (the head) is a minority (at most head_limit of the values), the mean is a valid break; split the head again at its own mean, and so on. Stop when the head is no longer a minority (or is empty).
Returns the last valid break, so only the heaviest obstructors score above it. If even the first split has a majority head (no heavy tail), the overall mean is returned.
Example: 80 values of 1, 16 of 10 and 4 of 100 give breaks 6.4 (head 20 %) and 28 (head 20 %), then an empty head: the cutoff is 28.