buildingcalibration 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.
- buildingcalibration-0.1.0/LICENSE +27 -0
- buildingcalibration-0.1.0/PKG-INFO +231 -0
- buildingcalibration-0.1.0/README.md +161 -0
- buildingcalibration-0.1.0/buildingcalibration/__init__.py +63 -0
- buildingcalibration-0.1.0/buildingcalibration/_logging.py +72 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/__init__.py +79 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/building_loader.py +305 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/calibration.py +110 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/constants.py +44 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/district_list.py +282 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/parameters.py +211 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/processing.py +509 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/results.py +131 -0
- buildingcalibration-0.1.0/buildingcalibration/calibration/simulation.py +322 -0
- buildingcalibration-0.1.0/buildingcalibration/clustering/__init__.py +61 -0
- buildingcalibration-0.1.0/buildingcalibration/clustering/clustering.py +460 -0
- buildingcalibration-0.1.0/buildingcalibration/clustering/unreliable_districts.py +342 -0
- buildingcalibration-0.1.0/buildingcalibration/plots/__init__.py +51 -0
- buildingcalibration-0.1.0/buildingcalibration/plots/_saving.py +47 -0
- buildingcalibration-0.1.0/buildingcalibration/plots/static_calibration.py +268 -0
- buildingcalibration-0.1.0/buildingcalibration/plots/validation.py +1542 -0
- buildingcalibration-0.1.0/buildingcalibration/seeding.py +108 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/__init__.py +202 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/aggregation.py +511 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/config.py +371 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/constants.py +112 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/metrics.py +455 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/simulation_io.py +453 -0
- buildingcalibration-0.1.0/buildingcalibration/validation/validator.py +533 -0
- buildingcalibration-0.1.0/buildingcalibration.egg-info/PKG-INFO +231 -0
- buildingcalibration-0.1.0/buildingcalibration.egg-info/SOURCES.txt +34 -0
- buildingcalibration-0.1.0/buildingcalibration.egg-info/dependency_links.txt +1 -0
- buildingcalibration-0.1.0/buildingcalibration.egg-info/requires.txt +19 -0
- buildingcalibration-0.1.0/buildingcalibration.egg-info/top_level.txt +1 -0
- buildingcalibration-0.1.0/pyproject.toml +117 -0
- buildingcalibration-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
=====================
|
|
3
|
+
|
|
4
|
+
- Copyright © `2026` `Yoann Chiche`
|
|
5
|
+
- Copyright © `2026` `Seddik Yassine Abdelouadoud`
|
|
6
|
+
- Copyright © `2026` `Anna Cocchi`
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person
|
|
9
|
+
obtaining a copy of this software and associated documentation
|
|
10
|
+
files (the “Software”), to deal in the Software without
|
|
11
|
+
restriction, including without limitation the rights to use,
|
|
12
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the
|
|
14
|
+
Software is furnished to do so, subject to the following
|
|
15
|
+
conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be
|
|
18
|
+
included in all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
22
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
24
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
25
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
26
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
27
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: buildingcalibration
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: District-scale static calibration, validation and representative-district clustering for the building-energy model family
|
|
5
|
+
Author-email: Yassine Abdelouadoud <yassine.abdelouadoud@gmail.com>
|
|
6
|
+
Maintainer-email: Yassine Abdelouadoud <yassine.abdelouadoud@gmail.com>
|
|
7
|
+
License: The MIT License (MIT)
|
|
8
|
+
=====================
|
|
9
|
+
|
|
10
|
+
- Copyright © `2026` `Yoann Chiche`
|
|
11
|
+
- Copyright © `2026` `Seddik Yassine Abdelouadoud`
|
|
12
|
+
- Copyright © `2026` `Anna Cocchi`
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person
|
|
15
|
+
obtaining a copy of this software and associated documentation
|
|
16
|
+
files (the “Software”), to deal in the Software without
|
|
17
|
+
restriction, including without limitation the rights to use,
|
|
18
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the
|
|
20
|
+
Software is furnished to do so, subject to the following
|
|
21
|
+
conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be
|
|
24
|
+
included in all copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
27
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
28
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
29
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
30
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
31
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
32
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
33
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
34
|
+
|
|
35
|
+
Project-URL: Homepage, https://git.persee.minesparis.psl.eu/planeterr/buildingcalibration
|
|
36
|
+
Project-URL: Repository, https://git.persee.minesparis.psl.eu/planeterr/buildingcalibration
|
|
37
|
+
Project-URL: Changelog, https://git.persee.minesparis.psl.eu/planeterr/buildingcalibration/-/blob/main/CHANGELOG.md
|
|
38
|
+
Classifier: Development Status :: 3 - Alpha
|
|
39
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
40
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
41
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
42
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
45
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
46
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
47
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
48
|
+
Requires-Python: <4.0.0,>=3.10
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
License-File: LICENSE
|
|
51
|
+
Requires-Dist: buildingmodel>=1.0.2
|
|
52
|
+
Requires-Dist: buildingdata>=0.2.0
|
|
53
|
+
Requires-Dist: colorlog
|
|
54
|
+
Requires-Dist: numpy
|
|
55
|
+
Requires-Dist: pandas
|
|
56
|
+
Requires-Dist: polars
|
|
57
|
+
Requires-Dist: geopandas
|
|
58
|
+
Requires-Dist: shapely
|
|
59
|
+
Requires-Dist: scipy
|
|
60
|
+
Requires-Dist: scikit-learn
|
|
61
|
+
Requires-Dist: fastcluster
|
|
62
|
+
Requires-Dist: matplotlib
|
|
63
|
+
Requires-Dist: seaborn
|
|
64
|
+
Requires-Dist: tqdm
|
|
65
|
+
Provides-Extra: dev
|
|
66
|
+
Requires-Dist: pytest; extra == "dev"
|
|
67
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
68
|
+
Requires-Dist: ruff>=0.16; extra == "dev"
|
|
69
|
+
Dynamic: license-file
|
|
70
|
+
|
|
71
|
+
# buildingcalibration
|
|
72
|
+
|
|
73
|
+
District-scale **static calibration, validation and representative-district
|
|
74
|
+
clustering** for the building-energy model family.
|
|
75
|
+
|
|
76
|
+
It covers the annual (non-hourly) half of the modelling chain:
|
|
77
|
+
|
|
78
|
+
- **Calibration** — the annual static calibration loop that fits a building
|
|
79
|
+
stock's energy model over [`buildingmodel`](https://gitlab.com/energytransition/buildingmodel)'s
|
|
80
|
+
static inference.
|
|
81
|
+
- **Validation** — the Eq. 5 error decomposition of simulated versus *measured*
|
|
82
|
+
district consumption (ORE / Enedis), read through
|
|
83
|
+
[`buildingdata`](https://gitlab.com/energytransition/buildingdata).
|
|
84
|
+
- **Clustering** — reduction of a national building stock to representative
|
|
85
|
+
districts, plus screening of districts whose measured data cannot support
|
|
86
|
+
calibration.
|
|
87
|
+
- **Plots** — the figures for both stages.
|
|
88
|
+
|
|
89
|
+
## Status
|
|
90
|
+
|
|
91
|
+
> **Pre-release.** The version is `0.1.0.dev0`: the modules have landed
|
|
92
|
+
> (extracted from `building_eload`'s core — `core/static_simulation`,
|
|
93
|
+
> `core/validation`, `core/clustering.py`, `core/unreliable_districts.py`,
|
|
94
|
+
> `core/building_loader.py`, `utils/district_list.py`,
|
|
95
|
+
> `plots/static_calibration.py`, `plots/validation.py`) and the test suite runs,
|
|
96
|
+
> but `0.1.0` has not been tagged and nothing is published to PyPI yet.
|
|
97
|
+
|
|
98
|
+
## Quick start
|
|
99
|
+
|
|
100
|
+
### Calibrate one district (static, annual)
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from buildingcalibration import StaticParameters, StaticSimulation
|
|
104
|
+
|
|
105
|
+
parameters = StaticParameters(
|
|
106
|
+
n_inference=5, # stochastic building-stock draws to average over
|
|
107
|
+
calibration_year=2023,
|
|
108
|
+
climate_year=2023,
|
|
109
|
+
output_root="results", # -> results/static_simulation/2023/
|
|
110
|
+
)
|
|
111
|
+
results = StaticSimulation("751010101", parameters).run()
|
|
112
|
+
results.save_results()
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Nothing else is needed: the building footprints (BDTOPO), the IRIS district
|
|
116
|
+
layer and the ORE per-IRIS annual consumption the calibration fits against are
|
|
117
|
+
all fetched through `buildingdata`. Pass `calibration_file=` (a frame or a path)
|
|
118
|
+
to pin a vintage, or `building_footprint_folder=` to use a local BDTOPO mirror.
|
|
119
|
+
|
|
120
|
+
### Validate reconstructed load curves against measurements
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from buildingcalibration import Validation
|
|
124
|
+
|
|
125
|
+
validation = Validation(
|
|
126
|
+
year=2023,
|
|
127
|
+
n_clusters=20,
|
|
128
|
+
scope="national",
|
|
129
|
+
building_type="residential",
|
|
130
|
+
input_path="results/dynamic_simulation/2023", # hourly parquets
|
|
131
|
+
output_path="results/validation/2023",
|
|
132
|
+
clustering_file=clustering_frame, # frame or path
|
|
133
|
+
unreliable_districts=unreliable_iris_frame, # frame, ids or path
|
|
134
|
+
)
|
|
135
|
+
validation.run()
|
|
136
|
+
error = validation.get_error() # paper Eq. 5 terms
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The measured Enedis load curves come from `buildingdata`
|
|
140
|
+
(`get_enedis_national()` / `get_enedis_regional()`) when
|
|
141
|
+
`validation_residential_file=` is left unset.
|
|
142
|
+
|
|
143
|
+
### Reduce a stock to representative districts
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from buildingcalibration import cluster_districts
|
|
147
|
+
from buildingcalibration.clustering import screen_unreliable_iris_from_parquet
|
|
148
|
+
|
|
149
|
+
unreliable = screen_unreliable_iris_from_parquet("enedis_iris_consumption.parquet")
|
|
150
|
+
|
|
151
|
+
result = cluster_districts(
|
|
152
|
+
district_data, # one row per district
|
|
153
|
+
n_clusters=20,
|
|
154
|
+
feature_columns=["heating_needs", "dhw_needs", "specific_needs"],
|
|
155
|
+
unreliable_ids=unreliable["code_iris"], # never pick these as medoids
|
|
156
|
+
seed=42,
|
|
157
|
+
)
|
|
158
|
+
result.medoid_ids # the districts to simulate
|
|
159
|
+
result.scaling_weights # count-based multiplier per medoid
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Doctrine: frames first, no path registry
|
|
163
|
+
|
|
164
|
+
Nothing in this package resolves a filesystem path at import time, and there is
|
|
165
|
+
no `data/` tree to install:
|
|
166
|
+
|
|
167
|
+
- **Pipeline intermediates** — dynamic-simulation results, clustering tables,
|
|
168
|
+
the unreliable-district list, output directories — are passed in as in-memory
|
|
169
|
+
frames or as explicit paths, and have **no default**. A missing one raises a
|
|
170
|
+
`ValueError` naming the parameter rather than reading from somewhere you did
|
|
171
|
+
not choose.
|
|
172
|
+
- **External open data** — BDTOPO footprints, IRIS districts, ORE annual
|
|
173
|
+
consumption, Enedis measured load curves — defaults to a
|
|
174
|
+
[`buildingdata`](https://gitlab.com/energytransition/buildingdata) getter
|
|
175
|
+
(`get_bdtopo()`, `get_districts()`, `get_ore()`, `get_enedis_national()` /
|
|
176
|
+
`get_enedis_regional()`), which owns the download, the cache and the vintage.
|
|
177
|
+
Pass a frame or a path to pin a specific vintage instead.
|
|
178
|
+
|
|
179
|
+
The one exception is the SDES *parc résidentiel* workbook read by
|
|
180
|
+
`plots.validation.read_sdes_data()`: `buildingdata` has no getter for it yet, so
|
|
181
|
+
it is a required frame-or-path argument (and reading the `.xlsx` form needs
|
|
182
|
+
`openpyxl`, which is not a declared dependency).
|
|
183
|
+
|
|
184
|
+
## Relationship to `building_eload`
|
|
185
|
+
|
|
186
|
+
`buildingcalibration` and `building_eload` have **no import relationship in
|
|
187
|
+
either direction**. `building_eload` becomes a pure hourly dynamic-simulation
|
|
188
|
+
library; this package owns the static/annual side. The two are coupled only by
|
|
189
|
+
**parquet data contracts on disk** — a calibrated stock written here is read
|
|
190
|
+
there, and vice versa. That seam already existed inside the old monolith; the
|
|
191
|
+
split just makes it a package boundary. A structural test
|
|
192
|
+
(`tests/test_data_path_doctrine.py`) enforces both halves of that: no path
|
|
193
|
+
registry, and no `building_eload` import anywhere in the package.
|
|
194
|
+
|
|
195
|
+
## The family
|
|
196
|
+
|
|
197
|
+
| Package | Role | Host |
|
|
198
|
+
|---|---|---|
|
|
199
|
+
| [`buildingdata`](https://gitlab.com/energytransition/buildingdata) | dataset access layer: BDTOPO/WFS, ERA5, INSEE census, Enedis/ORE, ELMAS | gitlab.com/energytransition |
|
|
200
|
+
| [`buildingmodel`](https://gitlab.com/energytransition/buildingmodel) | static inference engine: building-stock physical characteristics and annual demand | gitlab.com/energytransition |
|
|
201
|
+
| [`heatpumpmodel`](https://git.persee.minesparis.psl.eu/planeterr/heatpumpmodel) | shared heat-pump seasonal-performance physics (Rogeau et al. 2024) | git.persee |
|
|
202
|
+
| **`buildingcalibration`** | **static calibration, validation, representative-district clustering** | **git.persee** |
|
|
203
|
+
| [`building_eload`](https://git.persee.minesparis.psl.eu/planeterr/building_eload) | hourly dynamic simulation of district electric load | git.persee |
|
|
204
|
+
| [`building_eload_paper`](https://git.persee.minesparis.psl.eu/planeterr/building_eload_paper) | Snakemake reproduction workflow for the published paper; pinned to `building_eload==0.4.3` and unaffected by this split | git.persee |
|
|
205
|
+
|
|
206
|
+
## Install
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
pip install buildingcalibration
|
|
210
|
+
# or, from a checkout:
|
|
211
|
+
pip install -e ".[dev]"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Python 3.10–3.13.
|
|
215
|
+
|
|
216
|
+
## Tests
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pytest # full suite
|
|
220
|
+
pytest -m "not integration" # hermetic subset, what CI runs
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
The hermetic subset needs no data and no network. The `integration` tests run
|
|
224
|
+
the calibration and validation stages on real districts; they read a local
|
|
225
|
+
reference-data tree, `<repo>/data` by default, overridable with the
|
|
226
|
+
`BUILDING_ELOAD_DATA` environment variable (the name is shared with
|
|
227
|
+
`building_eload` on purpose, so one setting covers both checkouts).
|
|
228
|
+
|
|
229
|
+
## Licence
|
|
230
|
+
|
|
231
|
+
MIT — see `LICENSE`.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# buildingcalibration
|
|
2
|
+
|
|
3
|
+
District-scale **static calibration, validation and representative-district
|
|
4
|
+
clustering** for the building-energy model family.
|
|
5
|
+
|
|
6
|
+
It covers the annual (non-hourly) half of the modelling chain:
|
|
7
|
+
|
|
8
|
+
- **Calibration** — the annual static calibration loop that fits a building
|
|
9
|
+
stock's energy model over [`buildingmodel`](https://gitlab.com/energytransition/buildingmodel)'s
|
|
10
|
+
static inference.
|
|
11
|
+
- **Validation** — the Eq. 5 error decomposition of simulated versus *measured*
|
|
12
|
+
district consumption (ORE / Enedis), read through
|
|
13
|
+
[`buildingdata`](https://gitlab.com/energytransition/buildingdata).
|
|
14
|
+
- **Clustering** — reduction of a national building stock to representative
|
|
15
|
+
districts, plus screening of districts whose measured data cannot support
|
|
16
|
+
calibration.
|
|
17
|
+
- **Plots** — the figures for both stages.
|
|
18
|
+
|
|
19
|
+
## Status
|
|
20
|
+
|
|
21
|
+
> **Pre-release.** The version is `0.1.0.dev0`: the modules have landed
|
|
22
|
+
> (extracted from `building_eload`'s core — `core/static_simulation`,
|
|
23
|
+
> `core/validation`, `core/clustering.py`, `core/unreliable_districts.py`,
|
|
24
|
+
> `core/building_loader.py`, `utils/district_list.py`,
|
|
25
|
+
> `plots/static_calibration.py`, `plots/validation.py`) and the test suite runs,
|
|
26
|
+
> but `0.1.0` has not been tagged and nothing is published to PyPI yet.
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
### Calibrate one district (static, annual)
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from buildingcalibration import StaticParameters, StaticSimulation
|
|
34
|
+
|
|
35
|
+
parameters = StaticParameters(
|
|
36
|
+
n_inference=5, # stochastic building-stock draws to average over
|
|
37
|
+
calibration_year=2023,
|
|
38
|
+
climate_year=2023,
|
|
39
|
+
output_root="results", # -> results/static_simulation/2023/
|
|
40
|
+
)
|
|
41
|
+
results = StaticSimulation("751010101", parameters).run()
|
|
42
|
+
results.save_results()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Nothing else is needed: the building footprints (BDTOPO), the IRIS district
|
|
46
|
+
layer and the ORE per-IRIS annual consumption the calibration fits against are
|
|
47
|
+
all fetched through `buildingdata`. Pass `calibration_file=` (a frame or a path)
|
|
48
|
+
to pin a vintage, or `building_footprint_folder=` to use a local BDTOPO mirror.
|
|
49
|
+
|
|
50
|
+
### Validate reconstructed load curves against measurements
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from buildingcalibration import Validation
|
|
54
|
+
|
|
55
|
+
validation = Validation(
|
|
56
|
+
year=2023,
|
|
57
|
+
n_clusters=20,
|
|
58
|
+
scope="national",
|
|
59
|
+
building_type="residential",
|
|
60
|
+
input_path="results/dynamic_simulation/2023", # hourly parquets
|
|
61
|
+
output_path="results/validation/2023",
|
|
62
|
+
clustering_file=clustering_frame, # frame or path
|
|
63
|
+
unreliable_districts=unreliable_iris_frame, # frame, ids or path
|
|
64
|
+
)
|
|
65
|
+
validation.run()
|
|
66
|
+
error = validation.get_error() # paper Eq. 5 terms
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The measured Enedis load curves come from `buildingdata`
|
|
70
|
+
(`get_enedis_national()` / `get_enedis_regional()`) when
|
|
71
|
+
`validation_residential_file=` is left unset.
|
|
72
|
+
|
|
73
|
+
### Reduce a stock to representative districts
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from buildingcalibration import cluster_districts
|
|
77
|
+
from buildingcalibration.clustering import screen_unreliable_iris_from_parquet
|
|
78
|
+
|
|
79
|
+
unreliable = screen_unreliable_iris_from_parquet("enedis_iris_consumption.parquet")
|
|
80
|
+
|
|
81
|
+
result = cluster_districts(
|
|
82
|
+
district_data, # one row per district
|
|
83
|
+
n_clusters=20,
|
|
84
|
+
feature_columns=["heating_needs", "dhw_needs", "specific_needs"],
|
|
85
|
+
unreliable_ids=unreliable["code_iris"], # never pick these as medoids
|
|
86
|
+
seed=42,
|
|
87
|
+
)
|
|
88
|
+
result.medoid_ids # the districts to simulate
|
|
89
|
+
result.scaling_weights # count-based multiplier per medoid
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Doctrine: frames first, no path registry
|
|
93
|
+
|
|
94
|
+
Nothing in this package resolves a filesystem path at import time, and there is
|
|
95
|
+
no `data/` tree to install:
|
|
96
|
+
|
|
97
|
+
- **Pipeline intermediates** — dynamic-simulation results, clustering tables,
|
|
98
|
+
the unreliable-district list, output directories — are passed in as in-memory
|
|
99
|
+
frames or as explicit paths, and have **no default**. A missing one raises a
|
|
100
|
+
`ValueError` naming the parameter rather than reading from somewhere you did
|
|
101
|
+
not choose.
|
|
102
|
+
- **External open data** — BDTOPO footprints, IRIS districts, ORE annual
|
|
103
|
+
consumption, Enedis measured load curves — defaults to a
|
|
104
|
+
[`buildingdata`](https://gitlab.com/energytransition/buildingdata) getter
|
|
105
|
+
(`get_bdtopo()`, `get_districts()`, `get_ore()`, `get_enedis_national()` /
|
|
106
|
+
`get_enedis_regional()`), which owns the download, the cache and the vintage.
|
|
107
|
+
Pass a frame or a path to pin a specific vintage instead.
|
|
108
|
+
|
|
109
|
+
The one exception is the SDES *parc résidentiel* workbook read by
|
|
110
|
+
`plots.validation.read_sdes_data()`: `buildingdata` has no getter for it yet, so
|
|
111
|
+
it is a required frame-or-path argument (and reading the `.xlsx` form needs
|
|
112
|
+
`openpyxl`, which is not a declared dependency).
|
|
113
|
+
|
|
114
|
+
## Relationship to `building_eload`
|
|
115
|
+
|
|
116
|
+
`buildingcalibration` and `building_eload` have **no import relationship in
|
|
117
|
+
either direction**. `building_eload` becomes a pure hourly dynamic-simulation
|
|
118
|
+
library; this package owns the static/annual side. The two are coupled only by
|
|
119
|
+
**parquet data contracts on disk** — a calibrated stock written here is read
|
|
120
|
+
there, and vice versa. That seam already existed inside the old monolith; the
|
|
121
|
+
split just makes it a package boundary. A structural test
|
|
122
|
+
(`tests/test_data_path_doctrine.py`) enforces both halves of that: no path
|
|
123
|
+
registry, and no `building_eload` import anywhere in the package.
|
|
124
|
+
|
|
125
|
+
## The family
|
|
126
|
+
|
|
127
|
+
| Package | Role | Host |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| [`buildingdata`](https://gitlab.com/energytransition/buildingdata) | dataset access layer: BDTOPO/WFS, ERA5, INSEE census, Enedis/ORE, ELMAS | gitlab.com/energytransition |
|
|
130
|
+
| [`buildingmodel`](https://gitlab.com/energytransition/buildingmodel) | static inference engine: building-stock physical characteristics and annual demand | gitlab.com/energytransition |
|
|
131
|
+
| [`heatpumpmodel`](https://git.persee.minesparis.psl.eu/planeterr/heatpumpmodel) | shared heat-pump seasonal-performance physics (Rogeau et al. 2024) | git.persee |
|
|
132
|
+
| **`buildingcalibration`** | **static calibration, validation, representative-district clustering** | **git.persee** |
|
|
133
|
+
| [`building_eload`](https://git.persee.minesparis.psl.eu/planeterr/building_eload) | hourly dynamic simulation of district electric load | git.persee |
|
|
134
|
+
| [`building_eload_paper`](https://git.persee.minesparis.psl.eu/planeterr/building_eload_paper) | Snakemake reproduction workflow for the published paper; pinned to `building_eload==0.4.3` and unaffected by this split | git.persee |
|
|
135
|
+
|
|
136
|
+
## Install
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install buildingcalibration
|
|
140
|
+
# or, from a checkout:
|
|
141
|
+
pip install -e ".[dev]"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Python 3.10–3.13.
|
|
145
|
+
|
|
146
|
+
## Tests
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pytest # full suite
|
|
150
|
+
pytest -m "not integration" # hermetic subset, what CI runs
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The hermetic subset needs no data and no network. The `integration` tests run
|
|
154
|
+
the calibration and validation stages on real districts; they read a local
|
|
155
|
+
reference-data tree, `<repo>/data` by default, overridable with the
|
|
156
|
+
`BUILDING_ELOAD_DATA` environment variable (the name is shared with
|
|
157
|
+
`building_eload` on purpose, so one setting covers both checkouts).
|
|
158
|
+
|
|
159
|
+
## Licence
|
|
160
|
+
|
|
161
|
+
MIT — see `LICENSE`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""District-scale static calibration, validation and clustering.
|
|
2
|
+
|
|
3
|
+
This package holds the *annual/static* half of the building-energy model
|
|
4
|
+
family: calibrating a building stock against measured consumption, decomposing
|
|
5
|
+
the residual error, and reducing a national stock to representative districts.
|
|
6
|
+
The hourly dynamic simulation lives in ``building_eload``; there is no import
|
|
7
|
+
relationship in either direction — the two are coupled only through parquet
|
|
8
|
+
data contracts on disk.
|
|
9
|
+
|
|
10
|
+
Subpackages
|
|
11
|
+
-----------
|
|
12
|
+
``buildingcalibration.calibration``
|
|
13
|
+
Annual static calibration of the building stock over ``buildingmodel``
|
|
14
|
+
(:class:`~buildingcalibration.calibration.StaticSimulation`), plus building
|
|
15
|
+
footprint loading and representative-district selection.
|
|
16
|
+
``buildingcalibration.validation``
|
|
17
|
+
Eq. 5 error decomposition against measured ORE / Enedis consumption
|
|
18
|
+
(:class:`~buildingcalibration.validation.Validation`).
|
|
19
|
+
``buildingcalibration.clustering``
|
|
20
|
+
Representative-district clustering
|
|
21
|
+
(:func:`~buildingcalibration.clustering.cluster_districts`) and
|
|
22
|
+
unreliable-district screening.
|
|
23
|
+
``buildingcalibration.plots``
|
|
24
|
+
Figures for the calibration and validation stages (imported explicitly, so
|
|
25
|
+
``matplotlib`` is only loaded when you ask for it).
|
|
26
|
+
|
|
27
|
+
Doctrine
|
|
28
|
+
--------
|
|
29
|
+
**No path registry, frames first.** Nothing here resolves a filesystem path at
|
|
30
|
+
import time. Pipeline intermediates (dynamic-simulation results, clustering
|
|
31
|
+
tables, the unreliable-district list) are passed in as in-memory frames or as
|
|
32
|
+
explicit paths, with no default; external open data (BDTOPO, IRIS districts,
|
|
33
|
+
ORE annual consumption, Enedis measured load curves) is fetched through
|
|
34
|
+
``buildingdata`` getters, which own the download, cache and vintage. A clean
|
|
35
|
+
checkout therefore needs no ``data/`` tree.
|
|
36
|
+
|
|
37
|
+
Examples
|
|
38
|
+
--------
|
|
39
|
+
>>> from buildingcalibration import StaticParameters, StaticSimulation # doctest: +SKIP
|
|
40
|
+
>>> results = StaticSimulation("751010101", StaticParameters(n_inference=5)).run() # doctest: +SKIP
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
from buildingcalibration.calibration import (
|
|
44
|
+
BuildingLoader,
|
|
45
|
+
StaticParameters,
|
|
46
|
+
StaticResults,
|
|
47
|
+
StaticSimulation,
|
|
48
|
+
)
|
|
49
|
+
from buildingcalibration.clustering import ClusteringResult, cluster_districts
|
|
50
|
+
from buildingcalibration.validation import Validation
|
|
51
|
+
|
|
52
|
+
__version__ = "0.1.0"
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
"StaticSimulation",
|
|
56
|
+
"StaticParameters",
|
|
57
|
+
"StaticResults",
|
|
58
|
+
"BuildingLoader",
|
|
59
|
+
"Validation",
|
|
60
|
+
"cluster_districts",
|
|
61
|
+
"ClusteringResult",
|
|
62
|
+
"__version__",
|
|
63
|
+
]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Console logging setup for the package's own logger tree.
|
|
2
|
+
|
|
3
|
+
Copied verbatim (bar the logger name) from the shared logging helper of the
|
|
4
|
+
model family's original single-package layout, when the calibration modules
|
|
5
|
+
were extracted from ``building_eload``'s core in 0.1.0. The two packages have
|
|
6
|
+
no import relationship, so the helper is duplicated rather than shared: it is
|
|
7
|
+
~30 lines of handler wiring, and a dependency edge between the dynamic and
|
|
8
|
+
static halves would exist for nothing else.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
import colorlog
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def setup_logger(level=logging.INFO, capture_buildingmodel=False):
|
|
18
|
+
"""Attach a colourised console handler to the ``buildingcalibration`` logger.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
level: logging level for both the logger and its console handler.
|
|
22
|
+
capture_buildingmodel: also route the ``buildingmodel`` logger through
|
|
23
|
+
the same handler (its static-inference messages then interleave
|
|
24
|
+
with the calibration loop's own).
|
|
25
|
+
"""
|
|
26
|
+
logger_name = "buildingcalibration"
|
|
27
|
+
|
|
28
|
+
# --- Main application logger ---
|
|
29
|
+
logger = logging.getLogger(logger_name)
|
|
30
|
+
|
|
31
|
+
# Remove existing handlers to avoid duplicates
|
|
32
|
+
for handler in logger.handlers[:]:
|
|
33
|
+
logger.removeHandler(handler)
|
|
34
|
+
|
|
35
|
+
logger.setLevel(level)
|
|
36
|
+
logger.propagate = False # Prevent propagation to the root logger
|
|
37
|
+
|
|
38
|
+
# --- Colored formatter configuration ---
|
|
39
|
+
log_colors_config = {
|
|
40
|
+
"DEBUG": "cyan",
|
|
41
|
+
"INFO": "green",
|
|
42
|
+
"WARNING": "yellow",
|
|
43
|
+
"ERROR": "red",
|
|
44
|
+
"CRITICAL": "bold_red",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
formatter = colorlog.ColoredFormatter(
|
|
48
|
+
"%(asctime)s | %(name)-20s | %(log_color)s%(levelname)-8s%(reset)s | %(message)s",
|
|
49
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
50
|
+
log_colors=log_colors_config,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Create console handler
|
|
54
|
+
console_handler = logging.StreamHandler(sys.stdout)
|
|
55
|
+
console_handler.setFormatter(formatter)
|
|
56
|
+
console_handler.setLevel(level)
|
|
57
|
+
|
|
58
|
+
logger.addHandler(console_handler)
|
|
59
|
+
|
|
60
|
+
# --- Optional: capture logs from 'buildingmodel' package ---
|
|
61
|
+
if capture_buildingmodel:
|
|
62
|
+
bm_logger = logging.getLogger("buildingmodel")
|
|
63
|
+
|
|
64
|
+
# Remove existing handlers to prevent duplicate logs
|
|
65
|
+
for handler in bm_logger.handlers[:]:
|
|
66
|
+
bm_logger.removeHandler(handler)
|
|
67
|
+
|
|
68
|
+
bm_logger.setLevel(level)
|
|
69
|
+
bm_logger.addHandler(console_handler)
|
|
70
|
+
|
|
71
|
+
# Disable propagation to avoid double logging via root
|
|
72
|
+
bm_logger.propagate = False
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Annual static calibration of a building stock over ``buildingmodel``.
|
|
2
|
+
|
|
3
|
+
Façade for the calibration package: the calibration loop itself (a single
|
|
4
|
+
1035-line ``core/static_simulation.py`` in the model family's original
|
|
5
|
+
single-package layout, since split into cohesive sub-modules) plus the two
|
|
6
|
+
stock-selection helpers it needs. Extracted from ``building_eload``'s core in
|
|
7
|
+
0.1.0; every name the original façade exported is exported here unchanged.
|
|
8
|
+
|
|
9
|
+
====================================== =====================================
|
|
10
|
+
Sub-module Responsibility
|
|
11
|
+
====================================== =====================================
|
|
12
|
+
:mod:`~.constants` Usage vocabulary, unit conversions
|
|
13
|
+
:mod:`~.parameters` :class:`StaticParameters` run configuration
|
|
14
|
+
:mod:`~.results` :class:`StaticResults`, :class:`BuildingModelResults`, parquet I/O
|
|
15
|
+
:mod:`~.simulation` :class:`StaticSimulation` orchestrator
|
|
16
|
+
:mod:`~.processing` :class:`StaticProcessor` calibration + non-residential
|
|
17
|
+
:mod:`~.calibration` Paper Eq. 4 gap expressions (standalone)
|
|
18
|
+
:mod:`~.building_loader` :class:`BuildingLoader` -- district footprints via ``buildingdata``
|
|
19
|
+
:mod:`~.district_list` Medoid (representative) district selection
|
|
20
|
+
====================================== =====================================
|
|
21
|
+
|
|
22
|
+
No module here evaluates a filesystem path at import time: pipeline
|
|
23
|
+
intermediates are passed in as frames or explicit paths, and external open data
|
|
24
|
+
(BDTOPO footprints, IRIS districts, the ORE annual district consumption) comes
|
|
25
|
+
from ``buildingdata`` getters.
|
|
26
|
+
|
|
27
|
+
Examples
|
|
28
|
+
--------
|
|
29
|
+
>>> from buildingcalibration.calibration import ( # doctest: +SKIP
|
|
30
|
+
... StaticParameters, StaticSimulation
|
|
31
|
+
... )
|
|
32
|
+
>>> results = StaticSimulation("751010101", StaticParameters(n_inference=5)).run() # doctest: +SKIP
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from buildingcalibration.calibration.building_loader import BuildingLoader
|
|
36
|
+
from buildingcalibration.calibration.calibration import (
|
|
37
|
+
corrected_gap_expression,
|
|
38
|
+
relative_gap_expression,
|
|
39
|
+
)
|
|
40
|
+
from buildingcalibration.calibration.constants import (
|
|
41
|
+
KWH_TO_MWH_CONVERSION,
|
|
42
|
+
NON_RESIDENTIAL_USAGE,
|
|
43
|
+
USAGE_DICT,
|
|
44
|
+
USAGE_OPEN_DATA_MAPPING,
|
|
45
|
+
)
|
|
46
|
+
from buildingcalibration.calibration.district_list import (
|
|
47
|
+
get_national_representative_districts,
|
|
48
|
+
get_regional_representative_districts,
|
|
49
|
+
get_representative_districts,
|
|
50
|
+
get_representative_feeders_districts,
|
|
51
|
+
)
|
|
52
|
+
from buildingcalibration.calibration.parameters import StaticParameters
|
|
53
|
+
from buildingcalibration.calibration.processing import StaticProcessor
|
|
54
|
+
from buildingcalibration.calibration.results import BuildingModelResults, StaticResults
|
|
55
|
+
from buildingcalibration.calibration.simulation import StaticSimulation
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
# Public API (README + workflow repo + contract tests)
|
|
59
|
+
"StaticParameters",
|
|
60
|
+
"StaticSimulation",
|
|
61
|
+
"StaticResults",
|
|
62
|
+
"BuildingModelResults",
|
|
63
|
+
"StaticProcessor",
|
|
64
|
+
# Building stock loading
|
|
65
|
+
"BuildingLoader",
|
|
66
|
+
# Representative-district selection (clustering output consumers)
|
|
67
|
+
"get_representative_districts",
|
|
68
|
+
"get_representative_feeders_districts",
|
|
69
|
+
"get_national_representative_districts",
|
|
70
|
+
"get_regional_representative_districts",
|
|
71
|
+
# Calibration gap (paper Eq. 4)
|
|
72
|
+
"corrected_gap_expression",
|
|
73
|
+
"relative_gap_expression",
|
|
74
|
+
# Constants (historically module-level in core/static_simulation.py)
|
|
75
|
+
"KWH_TO_MWH_CONVERSION",
|
|
76
|
+
"NON_RESIDENTIAL_USAGE",
|
|
77
|
+
"USAGE_DICT",
|
|
78
|
+
"USAGE_OPEN_DATA_MAPPING",
|
|
79
|
+
]
|