ebm 0.99.5__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.
- ebm-0.99.5/LICENSE +21 -0
- ebm-0.99.5/MANIFEST.in +2 -0
- ebm-0.99.5/PKG-INFO +212 -0
- ebm-0.99.5/README.md +163 -0
- ebm-0.99.5/ebm/__init__.py +0 -0
- ebm-0.99.5/ebm/__main__.py +152 -0
- ebm-0.99.5/ebm/__version__.py +1 -0
- ebm-0.99.5/ebm/cmd/__init__.py +0 -0
- ebm-0.99.5/ebm/cmd/calibrate.py +83 -0
- ebm-0.99.5/ebm/cmd/calibrate_excel_com_io.py +128 -0
- ebm-0.99.5/ebm/cmd/heating_systems_by_year.py +18 -0
- ebm-0.99.5/ebm/cmd/helpers.py +134 -0
- ebm-0.99.5/ebm/cmd/initialize.py +167 -0
- ebm-0.99.5/ebm/cmd/migrate.py +92 -0
- ebm-0.99.5/ebm/cmd/pipeline.py +227 -0
- ebm-0.99.5/ebm/cmd/prepare_main.py +174 -0
- ebm-0.99.5/ebm/cmd/result_handler.py +272 -0
- ebm-0.99.5/ebm/cmd/run_calculation.py +221 -0
- ebm-0.99.5/ebm/data/area.csv +92 -0
- ebm-0.99.5/ebm/data/area_new_residential_buildings.csv +3 -0
- ebm-0.99.5/ebm/data/area_per_person.csv +12 -0
- ebm-0.99.5/ebm/data/building_code_parameters.csv +9 -0
- ebm-0.99.5/ebm/data/energy_need_behaviour_factor.csv +6 -0
- ebm-0.99.5/ebm/data/energy_need_improvements.csv +7 -0
- ebm-0.99.5/ebm/data/energy_need_original_condition.csv +534 -0
- ebm-0.99.5/ebm/data/heating_system_efficiencies.csv +13 -0
- ebm-0.99.5/ebm/data/heating_system_forecast.csv +9 -0
- ebm-0.99.5/ebm/data/heating_system_initial_shares.csv +1113 -0
- ebm-0.99.5/ebm/data/holiday_home_energy_consumption.csv +24 -0
- ebm-0.99.5/ebm/data/holiday_home_stock.csv +25 -0
- ebm-0.99.5/ebm/data/improvement_building_upgrade.csv +9 -0
- ebm-0.99.5/ebm/data/new_buildings_residential.csv +32 -0
- ebm-0.99.5/ebm/data/population_forecast.csv +51 -0
- ebm-0.99.5/ebm/data/s_curve.csv +40 -0
- ebm-0.99.5/ebm/energy_consumption.py +307 -0
- ebm-0.99.5/ebm/extractors.py +115 -0
- ebm-0.99.5/ebm/heating_system_forecast.py +472 -0
- ebm-0.99.5/ebm/holiday_home_energy.py +341 -0
- ebm-0.99.5/ebm/migrations.py +224 -0
- ebm-0.99.5/ebm/model/__init__.py +0 -0
- ebm-0.99.5/ebm/model/area.py +403 -0
- ebm-0.99.5/ebm/model/bema.py +149 -0
- ebm-0.99.5/ebm/model/building_category.py +150 -0
- ebm-0.99.5/ebm/model/building_condition.py +78 -0
- ebm-0.99.5/ebm/model/calibrate_energy_requirements.py +84 -0
- ebm-0.99.5/ebm/model/calibrate_heating_systems.py +180 -0
- ebm-0.99.5/ebm/model/column_operations.py +157 -0
- ebm-0.99.5/ebm/model/construction.py +827 -0
- ebm-0.99.5/ebm/model/data_classes.py +223 -0
- ebm-0.99.5/ebm/model/database_manager.py +410 -0
- ebm-0.99.5/ebm/model/dataframemodels.py +115 -0
- ebm-0.99.5/ebm/model/defaults.py +30 -0
- ebm-0.99.5/ebm/model/energy_need.py +6 -0
- ebm-0.99.5/ebm/model/energy_need_filter.py +182 -0
- ebm-0.99.5/ebm/model/energy_purpose.py +115 -0
- ebm-0.99.5/ebm/model/energy_requirement.py +353 -0
- ebm-0.99.5/ebm/model/energy_use.py +202 -0
- ebm-0.99.5/ebm/model/enums.py +8 -0
- ebm-0.99.5/ebm/model/exceptions.py +4 -0
- ebm-0.99.5/ebm/model/file_handler.py +388 -0
- ebm-0.99.5/ebm/model/filter_scurve_params.py +83 -0
- ebm-0.99.5/ebm/model/filter_tek.py +152 -0
- ebm-0.99.5/ebm/model/heat_pump.py +53 -0
- ebm-0.99.5/ebm/model/heating_systems.py +20 -0
- ebm-0.99.5/ebm/model/heating_systems_parameter.py +17 -0
- ebm-0.99.5/ebm/model/heating_systems_projection.py +3 -0
- ebm-0.99.5/ebm/model/heating_systems_share.py +28 -0
- ebm-0.99.5/ebm/model/scurve.py +224 -0
- ebm-0.99.5/ebm/model/tek.py +1 -0
- ebm-0.99.5/ebm/s_curve.py +515 -0
- ebm-0.99.5/ebm/services/__init__.py +0 -0
- ebm-0.99.5/ebm/services/calibration_writer.py +262 -0
- ebm-0.99.5/ebm/services/console.py +106 -0
- ebm-0.99.5/ebm/services/excel_loader.py +66 -0
- ebm-0.99.5/ebm/services/files.py +38 -0
- ebm-0.99.5/ebm/services/spreadsheet.py +289 -0
- ebm-0.99.5/ebm/temp_calc.py +99 -0
- ebm-0.99.5/ebm/validators.py +565 -0
- ebm-0.99.5/ebm.egg-info/PKG-INFO +212 -0
- ebm-0.99.5/ebm.egg-info/SOURCES.txt +86 -0
- ebm-0.99.5/ebm.egg-info/dependency_links.txt +1 -0
- ebm-0.99.5/ebm.egg-info/entry_points.txt +3 -0
- ebm-0.99.5/ebm.egg-info/requires.txt +34 -0
- ebm-0.99.5/ebm.egg-info/top_level.txt +1 -0
- ebm-0.99.5/pyproject.toml +66 -0
- ebm-0.99.5/setup.cfg +4 -0
- ebm-0.99.5/tests/test_energy_need_filter.py +59 -0
- ebm-0.99.5/tests/test_s_curve.py +65 -0
ebm-0.99.5/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Norges vassdrags- og energidirektorat
|
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.
|
ebm-0.99.5/MANIFEST.in
ADDED
ebm-0.99.5/PKG-INFO
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: ebm
|
3
|
+
Version: 0.99.5
|
4
|
+
Summary: A project for energy usage modeling
|
5
|
+
Author-email: Ny Forbruksmodell <ebm@nve.no>, Lars Petrusson <lfep@nve.no>, Mohammed Ettyabi <moe@nve.no>, Ketil Nordstad <kenord@nve.no>
|
6
|
+
License: MIT
|
7
|
+
Project-URL: Homepage, https://www.nve.no/
|
8
|
+
Project-URL: Documentation, https://nve.github.io/ebm-docs
|
9
|
+
Project-URL: Repository, https://github.com/NVE/ebm.git
|
10
|
+
Keywords: egg,bacon
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
18
|
+
Requires-Python: >=3.11
|
19
|
+
Description-Content-Type: text/markdown
|
20
|
+
License-File: LICENSE
|
21
|
+
Requires-Dist: loguru
|
22
|
+
Requires-Dist: numpy
|
23
|
+
Requires-Dist: openpyxl
|
24
|
+
Requires-Dist: pandas
|
25
|
+
Requires-Dist: python-dotenv
|
26
|
+
Requires-Dist: rich
|
27
|
+
Requires-Dist: pandera
|
28
|
+
Requires-Dist: XlsxWriter
|
29
|
+
Requires-Dist: pywin32; platform_system == "Windows"
|
30
|
+
Provides-Extra: test
|
31
|
+
Requires-Dist: pytest; extra == "test"
|
32
|
+
Provides-Extra: build
|
33
|
+
Requires-Dist: build; extra == "build"
|
34
|
+
Provides-Extra: dev
|
35
|
+
Requires-Dist: ebm[test]; extra == "dev"
|
36
|
+
Requires-Dist: ebm[build]; extra == "dev"
|
37
|
+
Requires-Dist: ruff; extra == "dev"
|
38
|
+
Requires-Dist: ruff-lsp; extra == "dev"
|
39
|
+
Provides-Extra: docs
|
40
|
+
Requires-Dist: sphinx; extra == "docs"
|
41
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
42
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
43
|
+
Requires-Dist: numpydoc; extra == "docs"
|
44
|
+
Requires-Dist: sphinx-tabs; extra == "docs"
|
45
|
+
Provides-Extra: tqdm
|
46
|
+
Requires-Dist: tqdm; extra == "tqdm"
|
47
|
+
Requires-Dist: XlsxWriter; extra == "tqdm"
|
48
|
+
Dynamic: license-file
|
49
|
+
|
50
|
+
# Introduction
|
51
|
+
|
52
|
+
EBM is a model used by the Norwegian Water Resources and Energy Directorates (NVE) to forecast energy use in the
|
53
|
+
building stock. EBM is an open-source model developed and managed by NVE. The model allows the user to analyze how
|
54
|
+
demographic trends and policy instruments impact the yearly energy use on a national and regional level. Energy use is
|
55
|
+
estimated by a bottom- up approach, based on the building stock floor area, energy need and distribution of heating
|
56
|
+
systems. The mathematical model is implemented in Python, with input and output files in excel or csv.
|
57
|
+
|
58
|
+
|
59
|
+
# Getting Started
|
60
|
+
|
61
|
+
## More information
|
62
|
+
|
63
|
+
|
64
|
+
- [Full documentation found here](https://nve.github.io/ebm-docs/index.html)
|
65
|
+
- [Model description](https://nve.github.io/ebm-docs/model_description/index.html)
|
66
|
+
- [Limitations](https://nve.github.io/ebm-docs/limitations.html)
|
67
|
+
- [Getting started](https://nve.github.io/ebm-docs/user_guide/getting_started.html)
|
68
|
+
- [Troubleshooting](https://nve.github.io/ebm-docs/user_guide/troubleshooting.html)
|
69
|
+
|
70
|
+
|
71
|
+
## 1. Installation process
|
72
|
+
|
73
|
+
Please refer to [getting started](https://nve.github.io/ebm-docs/user_guide/getting_started.html) for information on
|
74
|
+
how ti install EBM as a user.
|
75
|
+
|
76
|
+
Open a terminal application and navigate to wherever you want to do work.
|
77
|
+
|
78
|
+
### Clone the github repository
|
79
|
+
|
80
|
+
`git clone https://github.com/NVE/ebm`
|
81
|
+
|
82
|
+
`cd ebm`
|
83
|
+
|
84
|
+
### Make a python virtual environment (optional)
|
85
|
+
|
86
|
+
While optional, it is always recommended to install and run python modules in a discrete virtual environment. To create a
|
87
|
+
new python virtual environment (venv) type the following in a terminal.
|
88
|
+
|
89
|
+
`python -m venv venv`
|
90
|
+
|
91
|
+
## Activate virtual environment
|
92
|
+
To use your venv you need to activate it
|
93
|
+
### Using powershell
|
94
|
+
(Your command prompt starts with PS)
|
95
|
+
`\venv\Scripts\active.ps1`
|
96
|
+
|
97
|
+
### Using cmd
|
98
|
+
(Your command prompt starts with C:\ where C is any letter from A-Z)
|
99
|
+
`\venv\Scripts\active.bat`
|
100
|
+
|
101
|
+
### GNU/Linux and macOS
|
102
|
+
|
103
|
+
`source venv/bin/active`
|
104
|
+
|
105
|
+
More information on [Python virtual environments](https://realpython.com/python-virtual-environments-a-primer/)
|
106
|
+
|
107
|
+
|
108
|
+
### Install EBM
|
109
|
+
|
110
|
+
Make sure your current working directory is the EBM root.
|
111
|
+
|
112
|
+
```
|
113
|
+
python -m pip install -e .
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
The command will install install all dependencies and ebm as an editable module.
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
## 2. Software dependencies
|
122
|
+
- pandas
|
123
|
+
- loguru
|
124
|
+
- openpyxl
|
125
|
+
- pandera
|
126
|
+
|
127
|
+
Dependecies will be automatically installed when you install the package as described under Installation process.
|
128
|
+
See also [requirements.txt](requirements.txt)
|
129
|
+
|
130
|
+
## 3. Run the model
|
131
|
+
|
132
|
+
There are multiple ways to run the program. Listed bellow is running as a standalone program and running as a module. If
|
133
|
+
running as a program fails due to security restriction, you might be able to use the module approach instead.
|
134
|
+
|
135
|
+
See also [Running as code](#running-as-code)
|
136
|
+
|
137
|
+
|
138
|
+
### Running as a module
|
139
|
+
|
140
|
+
```cmd
|
141
|
+
python3 -m ebm
|
142
|
+
```
|
143
|
+
|
144
|
+
By default, the results will be written to the subdirectory `output`
|
145
|
+
|
146
|
+
For more information use `--help`
|
147
|
+
|
148
|
+
`python -m ebm --help`
|
149
|
+
|
150
|
+
```shell
|
151
|
+
usage: ebm [-h] [--version] [--debug] [--categories [CATEGORIES ...]] [--input [INPUT]] [--force] [--open]
|
152
|
+
[--csv-delimiter CSV_DELIMITER] [--create-input] [--horizontal-years]
|
153
|
+
[{area-forecast,energy-requirements,heating-systems,energy-use}] [output_file]
|
154
|
+
|
155
|
+
Calculate EBM energy use 1.2.15
|
156
|
+
|
157
|
+
positional arguments:
|
158
|
+
{area-forecast,energy-requirements,heating-systems,energy-use}
|
159
|
+
|
160
|
+
The calculation step you want to run. The steps are sequential. Any prerequisite to the chosen step will run
|
161
|
+
automatically.
|
162
|
+
output_file The location of the file you want to be written. default: output\ebm_output.xlsx
|
163
|
+
If the file already exists the program will terminate without overwriting.
|
164
|
+
Use "-" to output to the console instead
|
165
|
+
|
166
|
+
options:
|
167
|
+
-h, --help show this help message and exit
|
168
|
+
--version, -v show program's version number and exit
|
169
|
+
--debug Run in debug mode. (Extra information written to stdout)
|
170
|
+
--categories [CATEGORIES ...], --building-categories [CATEGORIES ...], -c [CATEGORIES ...]
|
171
|
+
|
172
|
+
One or more of the following building categories:
|
173
|
+
house, apartment_block, kindergarten, school, university, office, retail, hotel, hospital, nursing_home, culture, sports, storage_repairs.
|
174
|
+
The default is to use all categories.
|
175
|
+
--input [INPUT], --input-directory [INPUT], -i [INPUT]
|
176
|
+
path to the directory with input files
|
177
|
+
--force, -f Write to <filename> even if it already exists
|
178
|
+
--open, -o Open output file(s) automatically when finished writing. (Usually Excel)
|
179
|
+
--csv-delimiter CSV_DELIMITER, --delimiter CSV_DELIMITER, -e CSV_DELIMITER
|
180
|
+
A single character to be used for separating columns when writing csv. Default: "," Special characters like ; should be quoted ";"
|
181
|
+
--create-input
|
182
|
+
Create input directory containing all required files in the current working directory
|
183
|
+
--horizontal-years, --horizontal, --horisontal
|
184
|
+
Show years horizontal (left to right)
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
### Running as code
|
189
|
+
```python
|
190
|
+
|
191
|
+
from ebm.temp_calc import calculate_energy_use_wide
|
192
|
+
from ebm.model.file_handler import FileHandler
|
193
|
+
|
194
|
+
fh = FileHandler()
|
195
|
+
fh.create_missing_input_files()
|
196
|
+
|
197
|
+
df = calculate_energy_use_wide(ebm_input=fh.input_directory)
|
198
|
+
print(df)
|
199
|
+
|
200
|
+
```
|
201
|
+
|
202
|
+
## License
|
203
|
+
This project is licensed under the MIT License. You are free to use, modify, and distribute the software with proper attribution.
|
204
|
+
|
205
|
+
## Contributing
|
206
|
+
We welcome contributions! Please refer to the Contributing Guide (CONTRIBUTING.md) for details on how to get started.
|
207
|
+
|
208
|
+
## Documentation
|
209
|
+
Full documentation is available at the EBM User Guide: https://nve.github.io/ebm-docs/
|
210
|
+
|
211
|
+
|
212
|
+
|
ebm-0.99.5/README.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
EBM is a model used by the Norwegian Water Resources and Energy Directorates (NVE) to forecast energy use in the
|
4
|
+
building stock. EBM is an open-source model developed and managed by NVE. The model allows the user to analyze how
|
5
|
+
demographic trends and policy instruments impact the yearly energy use on a national and regional level. Energy use is
|
6
|
+
estimated by a bottom- up approach, based on the building stock floor area, energy need and distribution of heating
|
7
|
+
systems. The mathematical model is implemented in Python, with input and output files in excel or csv.
|
8
|
+
|
9
|
+
|
10
|
+
# Getting Started
|
11
|
+
|
12
|
+
## More information
|
13
|
+
|
14
|
+
|
15
|
+
- [Full documentation found here](https://nve.github.io/ebm-docs/index.html)
|
16
|
+
- [Model description](https://nve.github.io/ebm-docs/model_description/index.html)
|
17
|
+
- [Limitations](https://nve.github.io/ebm-docs/limitations.html)
|
18
|
+
- [Getting started](https://nve.github.io/ebm-docs/user_guide/getting_started.html)
|
19
|
+
- [Troubleshooting](https://nve.github.io/ebm-docs/user_guide/troubleshooting.html)
|
20
|
+
|
21
|
+
|
22
|
+
## 1. Installation process
|
23
|
+
|
24
|
+
Please refer to [getting started](https://nve.github.io/ebm-docs/user_guide/getting_started.html) for information on
|
25
|
+
how ti install EBM as a user.
|
26
|
+
|
27
|
+
Open a terminal application and navigate to wherever you want to do work.
|
28
|
+
|
29
|
+
### Clone the github repository
|
30
|
+
|
31
|
+
`git clone https://github.com/NVE/ebm`
|
32
|
+
|
33
|
+
`cd ebm`
|
34
|
+
|
35
|
+
### Make a python virtual environment (optional)
|
36
|
+
|
37
|
+
While optional, it is always recommended to install and run python modules in a discrete virtual environment. To create a
|
38
|
+
new python virtual environment (venv) type the following in a terminal.
|
39
|
+
|
40
|
+
`python -m venv venv`
|
41
|
+
|
42
|
+
## Activate virtual environment
|
43
|
+
To use your venv you need to activate it
|
44
|
+
### Using powershell
|
45
|
+
(Your command prompt starts with PS)
|
46
|
+
`\venv\Scripts\active.ps1`
|
47
|
+
|
48
|
+
### Using cmd
|
49
|
+
(Your command prompt starts with C:\ where C is any letter from A-Z)
|
50
|
+
`\venv\Scripts\active.bat`
|
51
|
+
|
52
|
+
### GNU/Linux and macOS
|
53
|
+
|
54
|
+
`source venv/bin/active`
|
55
|
+
|
56
|
+
More information on [Python virtual environments](https://realpython.com/python-virtual-environments-a-primer/)
|
57
|
+
|
58
|
+
|
59
|
+
### Install EBM
|
60
|
+
|
61
|
+
Make sure your current working directory is the EBM root.
|
62
|
+
|
63
|
+
```
|
64
|
+
python -m pip install -e .
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
The command will install install all dependencies and ebm as an editable module.
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
## 2. Software dependencies
|
73
|
+
- pandas
|
74
|
+
- loguru
|
75
|
+
- openpyxl
|
76
|
+
- pandera
|
77
|
+
|
78
|
+
Dependecies will be automatically installed when you install the package as described under Installation process.
|
79
|
+
See also [requirements.txt](requirements.txt)
|
80
|
+
|
81
|
+
## 3. Run the model
|
82
|
+
|
83
|
+
There are multiple ways to run the program. Listed bellow is running as a standalone program and running as a module. If
|
84
|
+
running as a program fails due to security restriction, you might be able to use the module approach instead.
|
85
|
+
|
86
|
+
See also [Running as code](#running-as-code)
|
87
|
+
|
88
|
+
|
89
|
+
### Running as a module
|
90
|
+
|
91
|
+
```cmd
|
92
|
+
python3 -m ebm
|
93
|
+
```
|
94
|
+
|
95
|
+
By default, the results will be written to the subdirectory `output`
|
96
|
+
|
97
|
+
For more information use `--help`
|
98
|
+
|
99
|
+
`python -m ebm --help`
|
100
|
+
|
101
|
+
```shell
|
102
|
+
usage: ebm [-h] [--version] [--debug] [--categories [CATEGORIES ...]] [--input [INPUT]] [--force] [--open]
|
103
|
+
[--csv-delimiter CSV_DELIMITER] [--create-input] [--horizontal-years]
|
104
|
+
[{area-forecast,energy-requirements,heating-systems,energy-use}] [output_file]
|
105
|
+
|
106
|
+
Calculate EBM energy use 1.2.15
|
107
|
+
|
108
|
+
positional arguments:
|
109
|
+
{area-forecast,energy-requirements,heating-systems,energy-use}
|
110
|
+
|
111
|
+
The calculation step you want to run. The steps are sequential. Any prerequisite to the chosen step will run
|
112
|
+
automatically.
|
113
|
+
output_file The location of the file you want to be written. default: output\ebm_output.xlsx
|
114
|
+
If the file already exists the program will terminate without overwriting.
|
115
|
+
Use "-" to output to the console instead
|
116
|
+
|
117
|
+
options:
|
118
|
+
-h, --help show this help message and exit
|
119
|
+
--version, -v show program's version number and exit
|
120
|
+
--debug Run in debug mode. (Extra information written to stdout)
|
121
|
+
--categories [CATEGORIES ...], --building-categories [CATEGORIES ...], -c [CATEGORIES ...]
|
122
|
+
|
123
|
+
One or more of the following building categories:
|
124
|
+
house, apartment_block, kindergarten, school, university, office, retail, hotel, hospital, nursing_home, culture, sports, storage_repairs.
|
125
|
+
The default is to use all categories.
|
126
|
+
--input [INPUT], --input-directory [INPUT], -i [INPUT]
|
127
|
+
path to the directory with input files
|
128
|
+
--force, -f Write to <filename> even if it already exists
|
129
|
+
--open, -o Open output file(s) automatically when finished writing. (Usually Excel)
|
130
|
+
--csv-delimiter CSV_DELIMITER, --delimiter CSV_DELIMITER, -e CSV_DELIMITER
|
131
|
+
A single character to be used for separating columns when writing csv. Default: "," Special characters like ; should be quoted ";"
|
132
|
+
--create-input
|
133
|
+
Create input directory containing all required files in the current working directory
|
134
|
+
--horizontal-years, --horizontal, --horisontal
|
135
|
+
Show years horizontal (left to right)
|
136
|
+
```
|
137
|
+
|
138
|
+
|
139
|
+
### Running as code
|
140
|
+
```python
|
141
|
+
|
142
|
+
from ebm.temp_calc import calculate_energy_use_wide
|
143
|
+
from ebm.model.file_handler import FileHandler
|
144
|
+
|
145
|
+
fh = FileHandler()
|
146
|
+
fh.create_missing_input_files()
|
147
|
+
|
148
|
+
df = calculate_energy_use_wide(ebm_input=fh.input_directory)
|
149
|
+
print(df)
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
## License
|
154
|
+
This project is licensed under the MIT License. You are free to use, modify, and distribute the software with proper attribution.
|
155
|
+
|
156
|
+
## Contributing
|
157
|
+
We welcome contributions! Please refer to the Contributing Guide (CONTRIBUTING.md) for details on how to get started.
|
158
|
+
|
159
|
+
## Documentation
|
160
|
+
Full documentation is available at the EBM User Guide: https://nve.github.io/ebm-docs/
|
161
|
+
|
162
|
+
|
163
|
+
|
File without changes
|
@@ -0,0 +1,152 @@
|
|
1
|
+
"""EBM start from where when running as a script or module"""
|
2
|
+
import os
|
3
|
+
import pathlib
|
4
|
+
import sys
|
5
|
+
|
6
|
+
import pandas as pd
|
7
|
+
from loguru import logger
|
8
|
+
|
9
|
+
from ebm.cmd import prepare_main
|
10
|
+
from ebm.cmd.helpers import configure_json_log, configure_loglevel, load_environment_from_dotenv
|
11
|
+
from ebm.cmd.initialize import create_output_directory, init
|
12
|
+
from ebm.cmd.migrate import migrate_directories
|
13
|
+
from ebm.cmd.pipeline import export_energy_model_reports
|
14
|
+
from ebm.cmd.result_handler import EbmDefaultHandler, append_result, transform_model_to_horizontal
|
15
|
+
from ebm.cmd.run_calculation import validate_years
|
16
|
+
from ebm.model.building_category import BuildingCategory
|
17
|
+
from ebm.model.database_manager import DatabaseManager
|
18
|
+
from ebm.model.enums import ReturnCode
|
19
|
+
from ebm.model.file_handler import FileHandler
|
20
|
+
|
21
|
+
df = None
|
22
|
+
|
23
|
+
|
24
|
+
def main() -> tuple[ReturnCode, pd.DataFrame | None]:
|
25
|
+
"""
|
26
|
+
Execute the EBM module as a script.
|
27
|
+
|
28
|
+
This function serves as the entry point for the script. It handles argument parsing,
|
29
|
+
initializes necessary components, and orchestrates the main workflow of the script.
|
30
|
+
|
31
|
+
Returns
|
32
|
+
-------
|
33
|
+
exit code : tuple[ReturnCode, pd.DataFrame]
|
34
|
+
zero when the program exits gracefully
|
35
|
+
|
36
|
+
"""
|
37
|
+
load_environment_from_dotenv()
|
38
|
+
configure_loglevel(log_format=os.environ.get('LOG_FORMAT', '{level.icon} <level>{message}</level>'))
|
39
|
+
configure_json_log()
|
40
|
+
|
41
|
+
logger.debug(f'Starting {sys.executable} {__file__}')
|
42
|
+
|
43
|
+
program_name = 'ebm'
|
44
|
+
default_path = pathlib.Path('output/ebm_output.xlsx')
|
45
|
+
|
46
|
+
arguments = prepare_main.make_arguments(program_name, default_path)
|
47
|
+
|
48
|
+
# Make local variable from arguments for clarity
|
49
|
+
building_categories = [BuildingCategory.from_string(b_c) for b_c in arguments.categories]
|
50
|
+
if not building_categories:
|
51
|
+
building_categories = list(BuildingCategory)
|
52
|
+
|
53
|
+
# `;` Will normally be interpreted as line end when typed in a shell. If the
|
54
|
+
# delimiter is empty make the assumption that the user used ;. An empty delimiter is not valid anyway.
|
55
|
+
csv_delimiter = arguments.csv_delimiter if arguments.csv_delimiter else ';'
|
56
|
+
|
57
|
+
# Make sure everything is working as expected
|
58
|
+
model_years = validate_years(start_year=arguments.start_year, end_year=arguments.end_year)
|
59
|
+
|
60
|
+
input_directory = arguments.input
|
61
|
+
logger.info(f'Using data from "{input_directory}"')
|
62
|
+
database_manager = DatabaseManager(file_handler=FileHandler(directory=input_directory))
|
63
|
+
|
64
|
+
# Create input directory if requested
|
65
|
+
if arguments.create_input:
|
66
|
+
if init(database_manager.file_handler):
|
67
|
+
logger.success('Finished creating input files in {input_directory}',
|
68
|
+
input_directory=database_manager.file_handler.input_directory)
|
69
|
+
return ReturnCode.OK, None
|
70
|
+
# Exit with 0 for success. The assumption is that the user would like to review the input before proceeding.
|
71
|
+
return ReturnCode.MISSING_INPUT_FILES, None
|
72
|
+
if arguments.migrate:
|
73
|
+
migrate_directories([database_manager.file_handler.input_directory])
|
74
|
+
logger.success('Finished migration')
|
75
|
+
return ReturnCode.OK, None
|
76
|
+
|
77
|
+
missing_input_error = f"""
|
78
|
+
Use `<program name> --create-input --input={input_directory}` to create an input directory with the default input files
|
79
|
+
""".strip().replace('\n', ' ')
|
80
|
+
|
81
|
+
# Make sure all required files exists
|
82
|
+
try:
|
83
|
+
missing_files = database_manager.file_handler.check_for_missing_files()
|
84
|
+
if missing_files:
|
85
|
+
print(missing_input_error, file=sys.stderr)
|
86
|
+
return ReturnCode.MISSING_INPUT_FILES, None
|
87
|
+
except FileNotFoundError as file_not_found:
|
88
|
+
if str(file_not_found).startswith('Input Directory Not Found'):
|
89
|
+
logger.error(f'Input Directory "{input_directory}" Not Found')
|
90
|
+
print(missing_input_error, file=sys.stderr)
|
91
|
+
return ReturnCode.FILE_NOT_ACCESSIBLE, None
|
92
|
+
|
93
|
+
database_manager.file_handler.validate_input_files()
|
94
|
+
|
95
|
+
output_file = arguments.output_file
|
96
|
+
create_output_directory(filename=output_file)
|
97
|
+
|
98
|
+
output_file_return_code = prepare_main.check_output_file_status(output_file, arguments.force, default_path,
|
99
|
+
program_name)
|
100
|
+
if output_file_return_code!= ReturnCode.OK:
|
101
|
+
return output_file_return_code, None
|
102
|
+
|
103
|
+
step_choice = arguments.step
|
104
|
+
|
105
|
+
convert_result_to_horizontal: bool = arguments.horizontal_years
|
106
|
+
|
107
|
+
default_handler = EbmDefaultHandler()
|
108
|
+
|
109
|
+
model = None
|
110
|
+
|
111
|
+
files_to_open = [output_file]
|
112
|
+
|
113
|
+
if step_choice == 'energy-use':
|
114
|
+
output_directory = output_file if output_file.is_dir() else output_file.parent
|
115
|
+
files_to_open = export_energy_model_reports(model_years, database_manager, output_directory)
|
116
|
+
else:
|
117
|
+
model = default_handler.extract_model(model_years, building_categories, database_manager, step_choice)
|
118
|
+
|
119
|
+
if convert_result_to_horizontal and (step_choice in ['area-forecast', 'energy-requirements']) and output_file.suffix=='.xlsx':
|
120
|
+
sheet_name_prefix = 'area' if step_choice == 'area-forecast' else 'energy'
|
121
|
+
logger.debug(f'Transform heating {step_choice}')
|
122
|
+
|
123
|
+
df = transform_model_to_horizontal(model.reset_index())
|
124
|
+
append_result(output_file, df, f'{sheet_name_prefix} condition')
|
125
|
+
|
126
|
+
model = model.reset_index()
|
127
|
+
# Demolition should not be summed any further
|
128
|
+
model = model[model.building_condition!='demolition']
|
129
|
+
model['building_condition'] = 'all'
|
130
|
+
df = transform_model_to_horizontal(model)
|
131
|
+
append_result(output_file, df, f'{sheet_name_prefix} TEK')
|
132
|
+
|
133
|
+
model['building_code'] = 'all'
|
134
|
+
df = transform_model_to_horizontal(model)
|
135
|
+
append_result(output_file, df, f'{sheet_name_prefix} category')
|
136
|
+
logger.success('Wrote {filename}', filename=output_file)
|
137
|
+
else:
|
138
|
+
default_handler.write_tqdm_result(output_file, model, csv_delimiter)
|
139
|
+
|
140
|
+
for file_to_open in files_to_open:
|
141
|
+
if arguments.open or os.environ.get('EBM_ALWAYS_OPEN', 'FALSE').upper() == 'TRUE':
|
142
|
+
logger.info(f'Open {file_to_open}')
|
143
|
+
os.startfile(file_to_open, 'open')
|
144
|
+
else:
|
145
|
+
logger.debug(f'Finished {file_to_open}')
|
146
|
+
|
147
|
+
return ReturnCode.OK, model
|
148
|
+
|
149
|
+
|
150
|
+
if __name__ == '__main__':
|
151
|
+
exit_code, result = main()
|
152
|
+
df = result
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "0.99.5"
|
File without changes
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import pathlib
|
2
|
+
|
3
|
+
from loguru import logger
|
4
|
+
import pandas as pd
|
5
|
+
|
6
|
+
from dotenv import load_dotenv
|
7
|
+
|
8
|
+
from ebm.model.bema import map_sort_order
|
9
|
+
|
10
|
+
from ebm.model.calibrate_heating_systems import extract_area_forecast, extract_energy_requirements, \
|
11
|
+
extract_heating_systems
|
12
|
+
from ebm.model.data_classes import YearRange
|
13
|
+
from ebm.services.files import make_unique_path
|
14
|
+
|
15
|
+
CALIBRATION_YEAR = 2023
|
16
|
+
|
17
|
+
model_period = YearRange(2020, 2050)
|
18
|
+
start_year = model_period.start
|
19
|
+
end_year = model_period.end
|
20
|
+
|
21
|
+
|
22
|
+
def run_calibration(database_manager,
|
23
|
+
calibration_year,
|
24
|
+
area_forecast: pd.DataFrame = None,
|
25
|
+
write_to_output = False):
|
26
|
+
"""
|
27
|
+
|
28
|
+
Parameters
|
29
|
+
----------
|
30
|
+
database_manager : ebm.model.database_manager.DatabaseManager
|
31
|
+
|
32
|
+
Returns
|
33
|
+
-------
|
34
|
+
pandas.core.frame.DataFrame
|
35
|
+
"""
|
36
|
+
load_dotenv(pathlib.Path('.env'))
|
37
|
+
|
38
|
+
input_directory = database_manager.file_handler.input_directory
|
39
|
+
|
40
|
+
logger.info(f'Using input directory "{input_directory}"')
|
41
|
+
logger.info('Extract area forecast')
|
42
|
+
area_forecast = extract_area_forecast(database_manager) if area_forecast is None else area_forecast
|
43
|
+
if write_to_output:
|
44
|
+
write_dataframe(area_forecast[area_forecast.year == calibration_year], 'area_forecast')
|
45
|
+
|
46
|
+
logger.info('Extract energy requirements')
|
47
|
+
energy_requirements = extract_energy_requirements(area_forecast, database_manager)
|
48
|
+
if write_to_output:
|
49
|
+
en_req = energy_requirements.xs(2023, level='year').reset_index().sort_values(
|
50
|
+
by='building_category', key=lambda x: x.map(map_sort_order))
|
51
|
+
write_dataframe(en_req, 'energy_requirements')
|
52
|
+
grouped = en_req[['building_category', 'm2', 'kwh_m2', 'energy_requirement']].groupby(
|
53
|
+
by=['building_category'], as_index=False).agg({'m2': 'first', 'kwh_m2': 'first', 'energy_requirement': 'sum'})
|
54
|
+
grouped = grouped.sort_values(by='building_category', key=lambda x: x.map(map_sort_order))
|
55
|
+
write_dataframe(grouped, 'energy_requirements_sum', sheet_name='sum')
|
56
|
+
|
57
|
+
logger.info('Extract heating systems')
|
58
|
+
heating_systems = extract_heating_systems(energy_requirements, database_manager)
|
59
|
+
if write_to_output:
|
60
|
+
write_dataframe(heating_systems.xs(2023, level='year'), 'heating_systems')
|
61
|
+
|
62
|
+
|
63
|
+
return heating_systems
|
64
|
+
|
65
|
+
|
66
|
+
def write_dataframe(df, name='dataframe', sheet_name='Sheet1'):
|
67
|
+
output_directory = pathlib.Path('output')
|
68
|
+
if output_directory.is_dir():
|
69
|
+
logger.debug(f'Writing {name} to file')
|
70
|
+
output_file = output_directory / f'{name}.xlsx'
|
71
|
+
output_file = make_unique_path(output_file)
|
72
|
+
df.to_excel(output_file, merge_cells=False, sheet_name=sheet_name)
|
73
|
+
logger.info(f'Wrote {name} to {output_file} ! {sheet_name if sheet_name!="Sheet1" else ""}')
|
74
|
+
else:
|
75
|
+
logger.warning(f'Cannot write to {output_directory}. Directory does not exists')
|
76
|
+
|
77
|
+
|
78
|
+
def main():
|
79
|
+
raise NotImplementedError('Running calibrate as a script is not supported')
|
80
|
+
|
81
|
+
|
82
|
+
if __name__ == '__main__':
|
83
|
+
main()
|