lczlite 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lczlite-0.1.0/CHANGELOG.md +32 -0
- lczlite-0.1.0/CITATION.cff +21 -0
- lczlite-0.1.0/LICENSE +21 -0
- lczlite-0.1.0/MANIFEST.in +10 -0
- lczlite-0.1.0/PKG-INFO +238 -0
- lczlite-0.1.0/README.md +202 -0
- lczlite-0.1.0/examples/quickstart.py +72 -0
- lczlite-0.1.0/pyproject.toml +110 -0
- lczlite-0.1.0/setup.cfg +4 -0
- lczlite-0.1.0/src/lczlite/__init__.py +115 -0
- lczlite-0.1.0/src/lczlite/__main__.py +7 -0
- lczlite-0.1.0/src/lczlite/_common.py +68 -0
- lczlite-0.1.0/src/lczlite/_version.py +1 -0
- lczlite-0.1.0/src/lczlite/classes.py +208 -0
- lczlite-0.1.0/src/lczlite/classify.py +306 -0
- lczlite-0.1.0/src/lczlite/cli.py +258 -0
- lczlite-0.1.0/src/lczlite/data/stewart_oke_2012.json +46 -0
- lczlite-0.1.0/src/lczlite/grid.py +196 -0
- lczlite-0.1.0/src/lczlite/io.py +122 -0
- lczlite-0.1.0/src/lczlite/parameters.py +321 -0
- lczlite-0.1.0/src/lczlite/py.typed +0 -0
- lczlite-0.1.0/src/lczlite/ranges.py +370 -0
- lczlite-0.1.0/src/lczlite/summary.py +137 -0
- lczlite-0.1.0/src/lczlite.egg-info/PKG-INFO +238 -0
- lczlite-0.1.0/src/lczlite.egg-info/SOURCES.txt +32 -0
- lczlite-0.1.0/src/lczlite.egg-info/dependency_links.txt +1 -0
- lczlite-0.1.0/src/lczlite.egg-info/entry_points.txt +2 -0
- lczlite-0.1.0/src/lczlite.egg-info/requires.txt +7 -0
- lczlite-0.1.0/src/lczlite.egg-info/top_level.txt +1 -0
- lczlite-0.1.0/tests/conftest.py +29 -0
- lczlite-0.1.0/tests/test_classes_ranges.py +205 -0
- lczlite-0.1.0/tests/test_classify_summary.py +191 -0
- lczlite-0.1.0/tests/test_io_cli.py +150 -0
- lczlite-0.1.0/tests/test_parameters_grid.py +193 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-11-15
|
|
8
|
+
### Added
|
|
9
|
+
- The 17 Local Climate Zones with keys, names, WUDAPT integer codes (1-17, 0 =
|
|
10
|
+
unclassified) and a default colour table; RGB rendering, QGIS `.qml` palette and colour
|
|
11
|
+
CSV writers.
|
|
12
|
+
- Range tables loaded from CSV or JSON (`read_range_table`, percent option for surface
|
|
13
|
+
fractions), range-cell parser, plausibility checks and an empty 17-class template
|
|
14
|
+
writer.
|
|
15
|
+
- The property ranges of all 17 classes from Stewart & Oke (2012), Tables 3 and 4, bundled
|
|
16
|
+
as package data (`stewart_oke_table()`, `lczlite/data/stewart_oke_2012.json`) and used
|
|
17
|
+
as the default table of `lczlite classify`.
|
|
18
|
+
- Fuzzy range scoring (`classify`) with weights, softness, absolute tolerances, minimum
|
|
19
|
+
parameter count, minimum score and mixed-class margin; `LCZResult` with labels, codes,
|
|
20
|
+
confidence, margin, mixed flags, per-site explanations and records.
|
|
21
|
+
- Canopy parameters: surface fractions, regular-array street width, aspect ratio, canyon
|
|
22
|
+
sky view factor (floor-averaged and centre), frontal area index, Macdonald et al. (1998)
|
|
23
|
+
displacement height and roughness length, Davenport roughness class, plan-weighted
|
|
24
|
+
albedo; `canopy_parameters` combining them.
|
|
25
|
+
- Building-to-grid aggregation (`GridSpec`, `buildings_to_grid`) with area-weighted,
|
|
26
|
+
geometric and maximum heights and frontal areas; `BuildingGrid.parameters` uses the
|
|
27
|
+
geometric mean height by default, as in the Stewart & Oke (2012) definition of the
|
|
28
|
+
height of roughness elements.
|
|
29
|
+
- Class summaries, mixed-pair counts, map agreement (`compare_maps`) and a majority filter.
|
|
30
|
+
- Command line: `lczlite classify | params | grid | ranges | template | colours`.
|
|
31
|
+
- `DAVENPORT_Z0` documents that Stewart & Oke (2012, Table 5) print 0.0005 m for class 2,
|
|
32
|
+
where the Davenport-Wieringa classification gives the 0.005 m used here.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
authors:
|
|
4
|
+
- family-names: "Eminoğlu"
|
|
5
|
+
given-names: "Yusuf"
|
|
6
|
+
email: "geospacephilo@gmail.com"
|
|
7
|
+
orcid: "https://orcid.org/0009-0005-6000-2934"
|
|
8
|
+
title: "lczlite"
|
|
9
|
+
version: "0.1.0"
|
|
10
|
+
date-released: "2026-11-15"
|
|
11
|
+
license: "MIT"
|
|
12
|
+
repository-code: "https://gitlab.com/geophilo1/lczlite_sdk"
|
|
13
|
+
url: "https://pypi.org/project/lczlite/"
|
|
14
|
+
abstract: "Local Climate Zone classification (Stewart & Oke 2012) from urban canopy parameters: fuzzy range scoring of sites or grid cells with best class, confidence and mixed-class flags; canopy parameters from building footprint grids (surface fractions, aspect ratio, canyon sky view factor, Macdonald roughness, Davenport roughness class); WUDAPT integer codes, colour table, class summaries and map agreement. Ships the Stewart & Oke (2012) Table 3-4 property ranges as the default range table; local tables load from CSV or JSON."
|
|
15
|
+
keywords:
|
|
16
|
+
- local climate zones
|
|
17
|
+
- urban climate
|
|
18
|
+
- urban heat island
|
|
19
|
+
- WUDAPT
|
|
20
|
+
- urban morphology
|
|
21
|
+
- gis
|
lczlite-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yusuf Eminoğlu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
include CITATION.cff
|
|
5
|
+
include pyproject.toml
|
|
6
|
+
include src/lczlite/py.typed
|
|
7
|
+
recursive-include src/lczlite *.py
|
|
8
|
+
recursive-include tests *.py
|
|
9
|
+
recursive-include examples *.py
|
|
10
|
+
include src/lczlite/data/*.json
|
lczlite-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lczlite
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local Climate Zone (Stewart & Oke 2012) classification from urban canopy parameters: fuzzy range scoring with confidence and mixed-class flags, parameters from building footprint grids, WUDAPT codes, colour table and summaries.
|
|
5
|
+
Author-email: Yusuf Eminoğlu <geospacephilo@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/geophilo1/lczlite_sdk
|
|
8
|
+
Project-URL: Repository, https://gitlab.com/geophilo1/lczlite_sdk
|
|
9
|
+
Project-URL: Issues, https://gitlab.com/geophilo1/lczlite_sdk/-/work_items
|
|
10
|
+
Project-URL: Changelog, https://gitlab.com/geophilo1/lczlite_sdk/-/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: local-climate-zones,lcz,urban-climate,urban-heat-island,wudapt,urban-canopy-parameters,sky-view-factor,aspect-ratio,roughness-length,urban-morphology,classification,urban-planning,gis
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Environment :: Console
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
23
|
+
Classifier: Intended Audience :: Science/Research
|
|
24
|
+
Classifier: Intended Audience :: Developers
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: numpy>=1.21
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# lczlite
|
|
38
|
+
|
|
39
|
+
[](https://pypi.org/project/lczlite/)
|
|
40
|
+
[](https://pypi.org/project/lczlite/)
|
|
41
|
+
[](https://gitlab.com/geophilo1/lczlite_sdk/-/pipelines)
|
|
42
|
+
[](https://gitlab.com/geophilo1/lczlite_sdk/-/blob/main/LICENSE)
|
|
43
|
+
|
|
44
|
+
Local Climate Zone classification from urban canopy parameters.
|
|
45
|
+
|
|
46
|
+
`lczlite` assigns sites or grid cells to the Local Climate Zones of Stewart & Oke (2012)
|
|
47
|
+
by comparing their urban canopy parameters with the property ranges of each zone:
|
|
48
|
+
|
|
49
|
+
- **Range scoring**: trapezoidal (fuzzy) membership of each parameter in each class's
|
|
50
|
+
range, weighted class scores, best class, confidence, runner-up, margin and mixed-class
|
|
51
|
+
flags; crisp in/out tests with `softness=0`.
|
|
52
|
+
- **Parameters from simple inputs**: building, impervious and pervious surface fractions;
|
|
53
|
+
aspect ratio; canyon sky view factor; frontal area index; displacement height and
|
|
54
|
+
roughness length (Macdonald et al. 1998); Davenport terrain roughness class.
|
|
55
|
+
- **Building grids**: footprint areas and heights (with x, y) summed into grid cells with
|
|
56
|
+
area-weighted, geometric and maximum heights and frontal areas.
|
|
57
|
+
- **Outputs**: WUDAPT integer codes (1-17, 0 = unclassified), LCZ colour table, RGB
|
|
58
|
+
images, QGIS `.qml` palette, class summaries, mixed-pair counts, agreement between two
|
|
59
|
+
maps, majority filter.
|
|
60
|
+
- **Published range table bundled**: the property ranges of all 17 classes from Stewart &
|
|
61
|
+
Oke (2012), Tables 3 and 4 (`stewart_oke_table()`); local tables load from CSV or JSON,
|
|
62
|
+
with an empty 17-class template.
|
|
63
|
+
|
|
64
|
+
It needs only NumPy. A command-line tool is included.
|
|
65
|
+
|
|
66
|
+
The default range table holds the values of Stewart & Oke (2012), Table 3 (sky view
|
|
67
|
+
factor, aspect ratio, building / impervious / pervious surface fraction, height of
|
|
68
|
+
roughness elements, terrain roughness class) and Table 4 (surface admittance, albedo,
|
|
69
|
+
anthropogenic heat), read from the published article and shipped as
|
|
70
|
+
`lczlite/data/stewart_oke_2012.json`. Surface fractions are converted from percent to
|
|
71
|
+
0-1. Two cells are blank in the paper and stay blank: the admittance of LCZ A ("unknown")
|
|
72
|
+
and the height of roughness elements of LCZ G.
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install lczlite
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Requires Python 3.9 or newer.
|
|
81
|
+
|
|
82
|
+
## Quickstart
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import numpy as np
|
|
86
|
+
import lczlite as lz
|
|
87
|
+
|
|
88
|
+
table = lz.stewart_oke_table() # Stewart & Oke (2012), Tables 3-4
|
|
89
|
+
# or a local adaptation: lz.read_range_table("my_ranges.csv", percent=True)
|
|
90
|
+
|
|
91
|
+
# Parameters per site (any shape; NaN = unknown)
|
|
92
|
+
params = {
|
|
93
|
+
"svf": [0.45, 0.75, 0.95],
|
|
94
|
+
"aspect_ratio": [1.2, 0.5, 0.05],
|
|
95
|
+
"bsf": [0.50, 0.30, 0.03],
|
|
96
|
+
"isf": [0.40, 0.30, 0.02],
|
|
97
|
+
"psf": [0.10, 0.40, 0.95],
|
|
98
|
+
"height": [15.0, 6.0, 0.5],
|
|
99
|
+
}
|
|
100
|
+
res = lz.classify(params, table, mixed_margin=0.1)
|
|
101
|
+
res.labels # best LCZ key per site, '' = unclassified
|
|
102
|
+
res.codes # WUDAPT codes 1-17, 0 = unclassified
|
|
103
|
+
res.confidence # best score (0-1)
|
|
104
|
+
res.margin # gap to the runner-up
|
|
105
|
+
res.mixed # True where the two best classes are close
|
|
106
|
+
res.explain(0) # per-parameter memberships of site 0
|
|
107
|
+
lz.class_summary(res)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
From building footprints to classified cells:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
spec = lz.GridSpec(x0=500000, y0=4300000, cell_size=200, shape=(50, 50))
|
|
114
|
+
grid = lz.buildings_to_grid(x, y, footprint_area, height, spec)
|
|
115
|
+
params = grid.parameters(impervious_area, height="mean",
|
|
116
|
+
admittance=adm, albedo=alb, anthropogenic_heat=qf)
|
|
117
|
+
res = lz.classify(params, table)
|
|
118
|
+
rgb = res.to_rgb() # (rows, cols, 3) uint8
|
|
119
|
+
lz.write_qml("lcz.qml") # palette for a WUDAPT-coded GeoTIFF in QGIS
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A complete synthetic run is in [`examples/quickstart.py`](examples/quickstart.py).
|
|
123
|
+
|
|
124
|
+
## Feature overview
|
|
125
|
+
|
|
126
|
+
| Area | Functions / classes |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| Classes | `LCZ_CLASSES`, `LCZ_KEYS`, `normalize_key`, `wudapt_code`, `key_from_code`, `lcz_class` |
|
|
129
|
+
| Colours | `colour_table`, `to_rgb`, `hex_to_rgb`, `write_qml`, `write_colour_csv` |
|
|
130
|
+
| Range tables | `RangeTable`, `Range`, `parse_range`, `stewart_oke_table`, `read_range_table`, `write_template`, `PARAMETERS` |
|
|
131
|
+
| Parameters | `surface_fractions`, `street_width_regular`, `aspect_ratio`, `svf_canyon`, `frontal_area_index`, `macdonald`, `roughness_class`, `albedo_plan_weighted`, `canopy_parameters`, `DAVENPORT_Z0` |
|
|
132
|
+
| Grids | `GridSpec`, `buildings_to_grid -> BuildingGrid` (`parameters()`) |
|
|
133
|
+
| Classification | `membership`, `classify -> LCZResult` (`labels`, `codes`, `confidence`, `margin`, `mixed`, `explain`, `records`, `to_rgb`) |
|
|
134
|
+
| Summaries | `class_summary`, `mixed_pairs`, `compare_maps`, `majority_filter` |
|
|
135
|
+
| I/O | `read_sites_csv`, `result_rows`, `write_results_csv`, `write_csv` |
|
|
136
|
+
|
|
137
|
+
Parameter names: `svf`, `aspect_ratio`, `bsf` (building surface fraction), `isf`
|
|
138
|
+
(impervious), `psf` (pervious), `height` (height of roughness elements), `roughness_class`,
|
|
139
|
+
`admittance`, `albedo`, `anthropogenic_heat`; common long names are accepted as aliases.
|
|
140
|
+
Surface fractions are 0-1 inside the package; use `percent=True` for tables or site files
|
|
141
|
+
in percent.
|
|
142
|
+
|
|
143
|
+
## Methods and sources
|
|
144
|
+
|
|
145
|
+
**Local Climate Zones.** Seventeen classes (built types 1-10, land-cover types A-G)
|
|
146
|
+
defined by ranges of geometric, surface-cover, thermal, radiative and metabolic properties
|
|
147
|
+
(Stewart & Oke 2012). WUDAPT products store them as integers 1-17 with A-G as 11-17
|
|
148
|
+
(Demuzere et al. 2021); the default colours follow the palette commonly used for WUDAPT
|
|
149
|
+
maps and can be overridden.
|
|
150
|
+
|
|
151
|
+
**Scoring.** For a range `[lo, hi]` the membership is 1 inside and falls linearly to 0 at
|
|
152
|
+
a distance `w` outside; `w = softness · (hi − lo)` for two-sided ranges,
|
|
153
|
+
`softness · |bound|` for one-sided ones, or an absolute `tolerance` per parameter. A class
|
|
154
|
+
score is the weighted mean membership over the parameters the class constrains and the
|
|
155
|
+
site has. The best class gives the confidence; the margin to the second class drives the
|
|
156
|
+
mixed flag. The membership shape and the defaults (`softness=0.5`, `mixed_margin=0.1`,
|
|
157
|
+
`min_score=0`) are design choices of this package, not values from the paper.
|
|
158
|
+
|
|
159
|
+
**Parameters.**
|
|
160
|
+
|
|
161
|
+
| Parameter | Computation | Source |
|
|
162
|
+
| --- | --- | --- |
|
|
163
|
+
| BSF, ISF, PSF | plan-area shares of the cell; PSF = remainder unless given | definition |
|
|
164
|
+
| Street width | `W = L (1/√λp − 1)`, `L = √(mean footprint)` | regular array of square blocks (assumption of this package) |
|
|
165
|
+
| Aspect ratio | `H / W` | definition |
|
|
166
|
+
| SVF, floor-averaged | `√(1 + (H/W)²) − H/W` | infinite canyon, Hottel's crossed-strings rule |
|
|
167
|
+
| SVF, floor centre | `cos(arctan(2H/W))` | Oke (1987) |
|
|
168
|
+
| λf | frontal area / cell area; default frontal width `√footprint` | definition |
|
|
169
|
+
| zd, z0 | `zd/H = 1 + A^(−λp)(λp − 1)`, `z0/H = (1 − zd/H) exp(−(0.5 β C_D/κ² (1 − zd/H) λf)^(−1/2))`, `A = 4.43`, `β = 1.0`, `C_D = 1.2`, `κ = 0.4` (staggered arrays) | Macdonald, Griffiths & Hall (1998) |
|
|
170
|
+
| Roughness class | Davenport class whose nominal z0 (0.0002, 0.005, 0.03, 0.10, 0.25, 0.5, 1.0, ≥2 m) is nearest on a log scale | Davenport et al. (2000); nearest-class rule is this package's convention. Stewart & Oke (2012, Table 5) print 0.0005 m for class 2; 0.005 m is the Davenport-Wieringa value |
|
|
171
|
+
| Albedo (optional) | plan-area-weighted component albedos | approximation, ignores canyon trapping |
|
|
172
|
+
| Admittance, anthropogenic heat | passed through | user data |
|
|
173
|
+
|
|
174
|
+
Buildings are assigned whole to the cell containing their reference point.
|
|
175
|
+
|
|
176
|
+
## Values left to the user
|
|
177
|
+
|
|
178
|
+
- Local adaptations of the LCZ property ranges (the published ranges are bundled).
|
|
179
|
+
- Impervious and pervious areas, surface admittance, albedo and anthropogenic heat.
|
|
180
|
+
- Membership softness, tolerances, weights, `min_score` and `mixed_margin`.
|
|
181
|
+
|
|
182
|
+
## Command line
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
lczlite ranges -o so2012.csv # bundled Stewart & Oke ranges as CSV
|
|
186
|
+
lczlite template lcz_ranges.csv # empty 17-class table for local ranges
|
|
187
|
+
lczlite grid buildings.csv --cell-size 200 -o cells.csv # x,y,area,height -> cells
|
|
188
|
+
# add impervious_area (and optional albedo, admittance, ...) to cells.csv, then:
|
|
189
|
+
lczlite params cells.csv --height-col height_geometric -o params.csv
|
|
190
|
+
lczlite classify params.csv \
|
|
191
|
+
--weights svf=2 --mixed-margin 0.1 --scores -o lcz.csv --summary summary.json
|
|
192
|
+
lczlite colours --qml lcz.qml --csv lcz_colours.csv
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`params` expects `cell_area`, `building_area`, `impervious_area` and a height column, and
|
|
196
|
+
uses `mean_footprint`, `street_width`, `frontal_area`, `svf`, `pervious_area`,
|
|
197
|
+
`admittance`, `albedo`, `anthropogenic_heat` when present.
|
|
198
|
+
|
|
199
|
+
## Limitations
|
|
200
|
+
|
|
201
|
+
- Range scoring is a rule-based approach on known parameters, not the WUDAPT
|
|
202
|
+
remote-sensing workflow; it does not use training areas or satellite imagery.
|
|
203
|
+
- Canyon formulas assume long symmetric canyons and regular arrays; real urban fabric
|
|
204
|
+
differs, so measured SVF and street widths are preferable where available.
|
|
205
|
+
- The result depends on the range table, which should be cited with the classification.
|
|
206
|
+
Stewart & Oke present their ranges as generic values; local fabric may need adapted
|
|
207
|
+
ranges (`--ranges my_ranges.csv --table-percent`).
|
|
208
|
+
|
|
209
|
+
## References
|
|
210
|
+
|
|
211
|
+
- Davenport, A. G., Grimmond, C. S. B., Oke, T. R. & Wieringa, J. (2000). Estimating the
|
|
212
|
+
roughness of cities and sheltered country. *12th Conference on Applied Climatology*,
|
|
213
|
+
American Meteorological Society, 96-99.
|
|
214
|
+
- Demuzere, M., Kittner, J. & Bechtel, B. (2021). LCZ Generator: a web application to
|
|
215
|
+
create Local Climate Zone maps. *Frontiers in Environmental Science* 9, 637455.
|
|
216
|
+
- Macdonald, R. W., Griffiths, R. F. & Hall, D. J. (1998). An improved method for the
|
|
217
|
+
estimation of surface roughness of obstacle arrays. *Atmospheric Environment* 32(11),
|
|
218
|
+
1857-1864.
|
|
219
|
+
- Oke, T. R. (1987). *Boundary Layer Climates*, 2nd ed. Routledge, London.
|
|
220
|
+
- Stewart, I. D. & Oke, T. R. (2012). Local Climate Zones for urban temperature studies.
|
|
221
|
+
*Bulletin of the American Meteorological Society* 93(12), 1879-1900.
|
|
222
|
+
https://doi.org/10.1175/BAMS-D-11-00019.1
|
|
223
|
+
|
|
224
|
+
## Academic citation
|
|
225
|
+
|
|
226
|
+
```bibtex
|
|
227
|
+
@software{eminoglu_lczlite,
|
|
228
|
+
author = {Eminoğlu, Yusuf},
|
|
229
|
+
title = {lczlite},
|
|
230
|
+
year = {2026},
|
|
231
|
+
version = {0.1.0},
|
|
232
|
+
url = {https://gitlab.com/geophilo1/lczlite_sdk}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT, see [LICENSE](LICENSE).
|
lczlite-0.1.0/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# lczlite
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/lczlite/)
|
|
4
|
+
[](https://pypi.org/project/lczlite/)
|
|
5
|
+
[](https://gitlab.com/geophilo1/lczlite_sdk/-/pipelines)
|
|
6
|
+
[](https://gitlab.com/geophilo1/lczlite_sdk/-/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Local Climate Zone classification from urban canopy parameters.
|
|
9
|
+
|
|
10
|
+
`lczlite` assigns sites or grid cells to the Local Climate Zones of Stewart & Oke (2012)
|
|
11
|
+
by comparing their urban canopy parameters with the property ranges of each zone:
|
|
12
|
+
|
|
13
|
+
- **Range scoring**: trapezoidal (fuzzy) membership of each parameter in each class's
|
|
14
|
+
range, weighted class scores, best class, confidence, runner-up, margin and mixed-class
|
|
15
|
+
flags; crisp in/out tests with `softness=0`.
|
|
16
|
+
- **Parameters from simple inputs**: building, impervious and pervious surface fractions;
|
|
17
|
+
aspect ratio; canyon sky view factor; frontal area index; displacement height and
|
|
18
|
+
roughness length (Macdonald et al. 1998); Davenport terrain roughness class.
|
|
19
|
+
- **Building grids**: footprint areas and heights (with x, y) summed into grid cells with
|
|
20
|
+
area-weighted, geometric and maximum heights and frontal areas.
|
|
21
|
+
- **Outputs**: WUDAPT integer codes (1-17, 0 = unclassified), LCZ colour table, RGB
|
|
22
|
+
images, QGIS `.qml` palette, class summaries, mixed-pair counts, agreement between two
|
|
23
|
+
maps, majority filter.
|
|
24
|
+
- **Published range table bundled**: the property ranges of all 17 classes from Stewart &
|
|
25
|
+
Oke (2012), Tables 3 and 4 (`stewart_oke_table()`); local tables load from CSV or JSON,
|
|
26
|
+
with an empty 17-class template.
|
|
27
|
+
|
|
28
|
+
It needs only NumPy. A command-line tool is included.
|
|
29
|
+
|
|
30
|
+
The default range table holds the values of Stewart & Oke (2012), Table 3 (sky view
|
|
31
|
+
factor, aspect ratio, building / impervious / pervious surface fraction, height of
|
|
32
|
+
roughness elements, terrain roughness class) and Table 4 (surface admittance, albedo,
|
|
33
|
+
anthropogenic heat), read from the published article and shipped as
|
|
34
|
+
`lczlite/data/stewart_oke_2012.json`. Surface fractions are converted from percent to
|
|
35
|
+
0-1. Two cells are blank in the paper and stay blank: the admittance of LCZ A ("unknown")
|
|
36
|
+
and the height of roughness elements of LCZ G.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install lczlite
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Requires Python 3.9 or newer.
|
|
45
|
+
|
|
46
|
+
## Quickstart
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import numpy as np
|
|
50
|
+
import lczlite as lz
|
|
51
|
+
|
|
52
|
+
table = lz.stewart_oke_table() # Stewart & Oke (2012), Tables 3-4
|
|
53
|
+
# or a local adaptation: lz.read_range_table("my_ranges.csv", percent=True)
|
|
54
|
+
|
|
55
|
+
# Parameters per site (any shape; NaN = unknown)
|
|
56
|
+
params = {
|
|
57
|
+
"svf": [0.45, 0.75, 0.95],
|
|
58
|
+
"aspect_ratio": [1.2, 0.5, 0.05],
|
|
59
|
+
"bsf": [0.50, 0.30, 0.03],
|
|
60
|
+
"isf": [0.40, 0.30, 0.02],
|
|
61
|
+
"psf": [0.10, 0.40, 0.95],
|
|
62
|
+
"height": [15.0, 6.0, 0.5],
|
|
63
|
+
}
|
|
64
|
+
res = lz.classify(params, table, mixed_margin=0.1)
|
|
65
|
+
res.labels # best LCZ key per site, '' = unclassified
|
|
66
|
+
res.codes # WUDAPT codes 1-17, 0 = unclassified
|
|
67
|
+
res.confidence # best score (0-1)
|
|
68
|
+
res.margin # gap to the runner-up
|
|
69
|
+
res.mixed # True where the two best classes are close
|
|
70
|
+
res.explain(0) # per-parameter memberships of site 0
|
|
71
|
+
lz.class_summary(res)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
From building footprints to classified cells:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
spec = lz.GridSpec(x0=500000, y0=4300000, cell_size=200, shape=(50, 50))
|
|
78
|
+
grid = lz.buildings_to_grid(x, y, footprint_area, height, spec)
|
|
79
|
+
params = grid.parameters(impervious_area, height="mean",
|
|
80
|
+
admittance=adm, albedo=alb, anthropogenic_heat=qf)
|
|
81
|
+
res = lz.classify(params, table)
|
|
82
|
+
rgb = res.to_rgb() # (rows, cols, 3) uint8
|
|
83
|
+
lz.write_qml("lcz.qml") # palette for a WUDAPT-coded GeoTIFF in QGIS
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A complete synthetic run is in [`examples/quickstart.py`](examples/quickstart.py).
|
|
87
|
+
|
|
88
|
+
## Feature overview
|
|
89
|
+
|
|
90
|
+
| Area | Functions / classes |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| Classes | `LCZ_CLASSES`, `LCZ_KEYS`, `normalize_key`, `wudapt_code`, `key_from_code`, `lcz_class` |
|
|
93
|
+
| Colours | `colour_table`, `to_rgb`, `hex_to_rgb`, `write_qml`, `write_colour_csv` |
|
|
94
|
+
| Range tables | `RangeTable`, `Range`, `parse_range`, `stewart_oke_table`, `read_range_table`, `write_template`, `PARAMETERS` |
|
|
95
|
+
| Parameters | `surface_fractions`, `street_width_regular`, `aspect_ratio`, `svf_canyon`, `frontal_area_index`, `macdonald`, `roughness_class`, `albedo_plan_weighted`, `canopy_parameters`, `DAVENPORT_Z0` |
|
|
96
|
+
| Grids | `GridSpec`, `buildings_to_grid -> BuildingGrid` (`parameters()`) |
|
|
97
|
+
| Classification | `membership`, `classify -> LCZResult` (`labels`, `codes`, `confidence`, `margin`, `mixed`, `explain`, `records`, `to_rgb`) |
|
|
98
|
+
| Summaries | `class_summary`, `mixed_pairs`, `compare_maps`, `majority_filter` |
|
|
99
|
+
| I/O | `read_sites_csv`, `result_rows`, `write_results_csv`, `write_csv` |
|
|
100
|
+
|
|
101
|
+
Parameter names: `svf`, `aspect_ratio`, `bsf` (building surface fraction), `isf`
|
|
102
|
+
(impervious), `psf` (pervious), `height` (height of roughness elements), `roughness_class`,
|
|
103
|
+
`admittance`, `albedo`, `anthropogenic_heat`; common long names are accepted as aliases.
|
|
104
|
+
Surface fractions are 0-1 inside the package; use `percent=True` for tables or site files
|
|
105
|
+
in percent.
|
|
106
|
+
|
|
107
|
+
## Methods and sources
|
|
108
|
+
|
|
109
|
+
**Local Climate Zones.** Seventeen classes (built types 1-10, land-cover types A-G)
|
|
110
|
+
defined by ranges of geometric, surface-cover, thermal, radiative and metabolic properties
|
|
111
|
+
(Stewart & Oke 2012). WUDAPT products store them as integers 1-17 with A-G as 11-17
|
|
112
|
+
(Demuzere et al. 2021); the default colours follow the palette commonly used for WUDAPT
|
|
113
|
+
maps and can be overridden.
|
|
114
|
+
|
|
115
|
+
**Scoring.** For a range `[lo, hi]` the membership is 1 inside and falls linearly to 0 at
|
|
116
|
+
a distance `w` outside; `w = softness · (hi − lo)` for two-sided ranges,
|
|
117
|
+
`softness · |bound|` for one-sided ones, or an absolute `tolerance` per parameter. A class
|
|
118
|
+
score is the weighted mean membership over the parameters the class constrains and the
|
|
119
|
+
site has. The best class gives the confidence; the margin to the second class drives the
|
|
120
|
+
mixed flag. The membership shape and the defaults (`softness=0.5`, `mixed_margin=0.1`,
|
|
121
|
+
`min_score=0`) are design choices of this package, not values from the paper.
|
|
122
|
+
|
|
123
|
+
**Parameters.**
|
|
124
|
+
|
|
125
|
+
| Parameter | Computation | Source |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| BSF, ISF, PSF | plan-area shares of the cell; PSF = remainder unless given | definition |
|
|
128
|
+
| Street width | `W = L (1/√λp − 1)`, `L = √(mean footprint)` | regular array of square blocks (assumption of this package) |
|
|
129
|
+
| Aspect ratio | `H / W` | definition |
|
|
130
|
+
| SVF, floor-averaged | `√(1 + (H/W)²) − H/W` | infinite canyon, Hottel's crossed-strings rule |
|
|
131
|
+
| SVF, floor centre | `cos(arctan(2H/W))` | Oke (1987) |
|
|
132
|
+
| λf | frontal area / cell area; default frontal width `√footprint` | definition |
|
|
133
|
+
| zd, z0 | `zd/H = 1 + A^(−λp)(λp − 1)`, `z0/H = (1 − zd/H) exp(−(0.5 β C_D/κ² (1 − zd/H) λf)^(−1/2))`, `A = 4.43`, `β = 1.0`, `C_D = 1.2`, `κ = 0.4` (staggered arrays) | Macdonald, Griffiths & Hall (1998) |
|
|
134
|
+
| Roughness class | Davenport class whose nominal z0 (0.0002, 0.005, 0.03, 0.10, 0.25, 0.5, 1.0, ≥2 m) is nearest on a log scale | Davenport et al. (2000); nearest-class rule is this package's convention. Stewart & Oke (2012, Table 5) print 0.0005 m for class 2; 0.005 m is the Davenport-Wieringa value |
|
|
135
|
+
| Albedo (optional) | plan-area-weighted component albedos | approximation, ignores canyon trapping |
|
|
136
|
+
| Admittance, anthropogenic heat | passed through | user data |
|
|
137
|
+
|
|
138
|
+
Buildings are assigned whole to the cell containing their reference point.
|
|
139
|
+
|
|
140
|
+
## Values left to the user
|
|
141
|
+
|
|
142
|
+
- Local adaptations of the LCZ property ranges (the published ranges are bundled).
|
|
143
|
+
- Impervious and pervious areas, surface admittance, albedo and anthropogenic heat.
|
|
144
|
+
- Membership softness, tolerances, weights, `min_score` and `mixed_margin`.
|
|
145
|
+
|
|
146
|
+
## Command line
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
lczlite ranges -o so2012.csv # bundled Stewart & Oke ranges as CSV
|
|
150
|
+
lczlite template lcz_ranges.csv # empty 17-class table for local ranges
|
|
151
|
+
lczlite grid buildings.csv --cell-size 200 -o cells.csv # x,y,area,height -> cells
|
|
152
|
+
# add impervious_area (and optional albedo, admittance, ...) to cells.csv, then:
|
|
153
|
+
lczlite params cells.csv --height-col height_geometric -o params.csv
|
|
154
|
+
lczlite classify params.csv \
|
|
155
|
+
--weights svf=2 --mixed-margin 0.1 --scores -o lcz.csv --summary summary.json
|
|
156
|
+
lczlite colours --qml lcz.qml --csv lcz_colours.csv
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`params` expects `cell_area`, `building_area`, `impervious_area` and a height column, and
|
|
160
|
+
uses `mean_footprint`, `street_width`, `frontal_area`, `svf`, `pervious_area`,
|
|
161
|
+
`admittance`, `albedo`, `anthropogenic_heat` when present.
|
|
162
|
+
|
|
163
|
+
## Limitations
|
|
164
|
+
|
|
165
|
+
- Range scoring is a rule-based approach on known parameters, not the WUDAPT
|
|
166
|
+
remote-sensing workflow; it does not use training areas or satellite imagery.
|
|
167
|
+
- Canyon formulas assume long symmetric canyons and regular arrays; real urban fabric
|
|
168
|
+
differs, so measured SVF and street widths are preferable where available.
|
|
169
|
+
- The result depends on the range table, which should be cited with the classification.
|
|
170
|
+
Stewart & Oke present their ranges as generic values; local fabric may need adapted
|
|
171
|
+
ranges (`--ranges my_ranges.csv --table-percent`).
|
|
172
|
+
|
|
173
|
+
## References
|
|
174
|
+
|
|
175
|
+
- Davenport, A. G., Grimmond, C. S. B., Oke, T. R. & Wieringa, J. (2000). Estimating the
|
|
176
|
+
roughness of cities and sheltered country. *12th Conference on Applied Climatology*,
|
|
177
|
+
American Meteorological Society, 96-99.
|
|
178
|
+
- Demuzere, M., Kittner, J. & Bechtel, B. (2021). LCZ Generator: a web application to
|
|
179
|
+
create Local Climate Zone maps. *Frontiers in Environmental Science* 9, 637455.
|
|
180
|
+
- Macdonald, R. W., Griffiths, R. F. & Hall, D. J. (1998). An improved method for the
|
|
181
|
+
estimation of surface roughness of obstacle arrays. *Atmospheric Environment* 32(11),
|
|
182
|
+
1857-1864.
|
|
183
|
+
- Oke, T. R. (1987). *Boundary Layer Climates*, 2nd ed. Routledge, London.
|
|
184
|
+
- Stewart, I. D. & Oke, T. R. (2012). Local Climate Zones for urban temperature studies.
|
|
185
|
+
*Bulletin of the American Meteorological Society* 93(12), 1879-1900.
|
|
186
|
+
https://doi.org/10.1175/BAMS-D-11-00019.1
|
|
187
|
+
|
|
188
|
+
## Academic citation
|
|
189
|
+
|
|
190
|
+
```bibtex
|
|
191
|
+
@software{eminoglu_lczlite,
|
|
192
|
+
author = {Eminoğlu, Yusuf},
|
|
193
|
+
title = {lczlite},
|
|
194
|
+
year = {2026},
|
|
195
|
+
version = {0.1.0},
|
|
196
|
+
url = {https://gitlab.com/geophilo1/lczlite_sdk}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""lczlite quickstart on a synthetic town (no input files needed).
|
|
2
|
+
|
|
3
|
+
The range table is the bundled one from Stewart & Oke (2012), Tables 3-4. A local
|
|
4
|
+
adaptation can be filled into the template written at the end and loaded with
|
|
5
|
+
``lz.read_range_table("lcz_ranges.csv", percent=True)``.
|
|
6
|
+
|
|
7
|
+
Run: python examples/quickstart.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
import lczlite as lz
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def synthetic_buildings(rng: np.random.Generator) -> tuple:
|
|
18
|
+
"""A dense mid-rise core, an open low-rise ring and sparse houses outside."""
|
|
19
|
+
xs, ys, areas, heights = [], [], [], []
|
|
20
|
+
for _ in range(12000):
|
|
21
|
+
x, y = rng.uniform(0, 2000, 2)
|
|
22
|
+
r = np.hypot(x - 1000, y - 1000)
|
|
23
|
+
if r < 400:
|
|
24
|
+
keep, area, h = rng.random() < 0.6, rng.uniform(200, 400), rng.uniform(12, 22)
|
|
25
|
+
elif r < 800:
|
|
26
|
+
keep, area, h = rng.random() < 0.6, rng.uniform(100, 180), rng.uniform(4, 9)
|
|
27
|
+
else:
|
|
28
|
+
keep, area, h = rng.random() < 0.2, rng.uniform(80, 150), rng.uniform(3, 7)
|
|
29
|
+
if keep:
|
|
30
|
+
xs.append(x)
|
|
31
|
+
ys.append(y)
|
|
32
|
+
areas.append(area)
|
|
33
|
+
heights.append(h)
|
|
34
|
+
return np.array(xs), np.array(ys), np.array(areas), np.array(heights)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main() -> None:
|
|
38
|
+
rng = np.random.default_rng(3)
|
|
39
|
+
x, y, area, height = synthetic_buildings(rng)
|
|
40
|
+
spec = lz.GridSpec(x0=0, y0=2000, cell_size=200, shape=(10, 10))
|
|
41
|
+
grid = lz.buildings_to_grid(x, y, area, height, spec)
|
|
42
|
+
|
|
43
|
+
# paved non-building area per cell (from a land-cover map in practice)
|
|
44
|
+
cx, cy = spec.centres()
|
|
45
|
+
dist = np.hypot(cx - 1000, cy - 1000)
|
|
46
|
+
impervious = spec.cell_area * np.clip(0.45 - dist / 3000, 0.02, None)
|
|
47
|
+
impervious = np.minimum(impervious, spec.cell_area - grid.building_area)
|
|
48
|
+
|
|
49
|
+
params = grid.parameters(impervious, height="geometric")
|
|
50
|
+
print("Mean building surface fraction:", round(float(params["bsf"].mean()), 3))
|
|
51
|
+
print("Roughness classes present:", sorted(set(params["roughness_class"].ravel().tolist())))
|
|
52
|
+
|
|
53
|
+
res = lz.classify(params, lz.stewart_oke_table(), mixed_margin=0.15)
|
|
54
|
+
|
|
55
|
+
print("WUDAPT codes:\n", res.codes)
|
|
56
|
+
for row in lz.class_summary(res, cell_area=spec.cell_area / 1e4):
|
|
57
|
+
print(
|
|
58
|
+
f" LCZ {row['lcz'] or '-':>2} {row['name']:<16} {row['count']:3d} cells "
|
|
59
|
+
f"{row['area']:6.0f} ha confidence {row['mean_confidence']:.2f}"
|
|
60
|
+
)
|
|
61
|
+
print("Mixed cells:", int(res.mixed.sum()), lz.mixed_pairs(res)[:3])
|
|
62
|
+
cleaned = lz.majority_filter(res.codes)
|
|
63
|
+
print("Changed by the 3x3 majority filter:", int((cleaned != res.codes).sum()))
|
|
64
|
+
print("RGB image shape:", res.to_rgb().shape)
|
|
65
|
+
|
|
66
|
+
lz.write_template("lcz_ranges_template.csv")
|
|
67
|
+
lz.write_qml("lcz_palette.qml")
|
|
68
|
+
print("Wrote lcz_ranges_template.csv and lcz_palette.qml")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
main()
|