urban-system-generator 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.
Files changed (30) hide show
  1. urban_system_generator-0.1.0/LICENSE +28 -0
  2. urban_system_generator-0.1.0/MANIFEST.in +7 -0
  3. urban_system_generator-0.1.0/PKG-INFO +378 -0
  4. urban_system_generator-0.1.0/README.md +309 -0
  5. urban_system_generator-0.1.0/pyproject.toml +79 -0
  6. urban_system_generator-0.1.0/requirements.txt +16 -0
  7. urban_system_generator-0.1.0/setup.cfg +4 -0
  8. urban_system_generator-0.1.0/tests/test_basic.py +101 -0
  9. urban_system_generator-0.1.0/tests/test_geojson_processor.py +0 -0
  10. urban_system_generator-0.1.0/tests/test_inference.py +0 -0
  11. urban_system_generator-0.1.0/tests/test_integration.py +114 -0
  12. urban_system_generator-0.1.0/urban_system_generator.egg-info/PKG-INFO +378 -0
  13. urban_system_generator-0.1.0/urban_system_generator.egg-info/SOURCES.txt +28 -0
  14. urban_system_generator-0.1.0/urban_system_generator.egg-info/dependency_links.txt +1 -0
  15. urban_system_generator-0.1.0/urban_system_generator.egg-info/entry_points.txt +3 -0
  16. urban_system_generator-0.1.0/urban_system_generator.egg-info/requires.txt +17 -0
  17. urban_system_generator-0.1.0/urban_system_generator.egg-info/top_level.txt +1 -0
  18. urban_system_generator-0.1.0/usg/__init__.py +24 -0
  19. urban_system_generator-0.1.0/usg/cli.py +527 -0
  20. urban_system_generator-0.1.0/usg/geojson_processor.py +445 -0
  21. urban_system_generator-0.1.0/usg/inference.py +289 -0
  22. urban_system_generator-0.1.0/usg/model.py +70 -0
  23. urban_system_generator-0.1.0/usg/postprocessor.py +1154 -0
  24. urban_system_generator-0.1.0/usg/resources/model_attributes.py +131 -0
  25. urban_system_generator-0.1.0/usg/resources/postprocessor/consistency_rules.json +1571 -0
  26. urban_system_generator-0.1.0/usg/resources/postprocessor/options_lookup.tsv +14022 -0
  27. urban_system_generator-0.1.0/usg/resources/pretrained_model/adaptive_model_1.keras +0 -0
  28. urban_system_generator-0.1.0/usg/resources/pretrained_model/cat_scaler.pkl +0 -0
  29. urban_system_generator-0.1.0/usg/resources/pretrained_model/encoding_mapper.json +1596 -0
  30. urban_system_generator-0.1.0/usg/resources/pretrained_model/num_scaler.pkl +0 -0
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025-2026 Alliance for Energy Innovation, LLC
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,7 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ recursive-include usg/resources *
5
+ recursive-exclude * __pycache__
6
+ recursive-exclude * *.py[co]
7
+ recursive-exclude * .DS_Store
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: urban-system-generator
3
+ Version: 0.1.0
4
+ Summary: Machine learning tool for completing building attributes in urban energy models with URBANopt-BuildStock post-processing
5
+ Author-email: Rawad El Kontar <rawad.elkontar@nlr.gov>
6
+ Maintainer-email: Rawad El Kontar <rawad.elkontar@nlr.gov>
7
+ License: BSD 3-Clause License
8
+
9
+ Copyright (c) 2025-2026 Alliance for Energy Innovation, LLC
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ this list of conditions and the following disclaimer in the documentation
19
+ and/or other materials provided with the distribution.
20
+
21
+ 3. Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived from
23
+ this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+ Project-URL: Homepage, https://github.com/NatLabRockies/urban-system-generator
36
+ Project-URL: Repository, https://github.com/NatLabRockies/urban-system-generator
37
+ Project-URL: Documentation, https://github.com/NatLabRockies/urban-system-generator#readme
38
+ Project-URL: Bug Tracker, https://github.com/NatLabRockies/urban-system-generator/issues
39
+ Keywords: urban,energy,buildings,machine-learning,artificial-intelligence,GenAI,data-completion,URBANopt,BuildStock
40
+ Classifier: Development Status :: 3 - Alpha
41
+ Classifier: Intended Audience :: Science/Research
42
+ Classifier: License :: OSI Approved :: BSD License
43
+ Classifier: Programming Language :: Python :: 3
44
+ Classifier: Programming Language :: Python :: 3.8
45
+ Classifier: Programming Language :: Python :: 3.9
46
+ Classifier: Programming Language :: Python :: 3.10
47
+ Classifier: Programming Language :: Python :: 3.11
48
+ Classifier: Programming Language :: Python :: 3.12
49
+ Classifier: Topic :: Scientific/Engineering
50
+ Requires-Python: >=3.8
51
+ Description-Content-Type: text/markdown
52
+ License-File: LICENSE
53
+ Requires-Dist: numpy>=1.21.0
54
+ Requires-Dist: pandas>=1.3.0
55
+ Requires-Dist: tensorflow>=2.10.0
56
+ Requires-Dist: scikit-learn>=1.0.0
57
+ Requires-Dist: click>=8.0.0
58
+ Provides-Extra: dev
59
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
60
+ Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
61
+ Requires-Dist: black>=22.0.0; extra == "dev"
62
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
63
+ Requires-Dist: build; extra == "dev"
64
+ Requires-Dist: twine; extra == "dev"
65
+ Provides-Extra: docs
66
+ Requires-Dist: sphinx>=4.0.0; extra == "docs"
67
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
68
+ Dynamic: license-file
69
+
70
+ # Urban System Generator
71
+
72
+ [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
73
+
74
+ **NLR Software Record:** SWR 25-36
75
+
76
+ Urban System Generator (USG) is a machine learning-based tool for completing missing building attributes in urban energy modeling workflows. Given partial building information from GeoJSON files, USG predicts missing characteristics like HVAC systems, insulation levels, and other energy-relevant properties. The tool includes post-processing for URBANopt-BuildStock compatibility.
77
+
78
+ ## Features
79
+
80
+ - **GeoJSON Processing**: Extract and convert building data from GeoJSON files
81
+ - **Attribute Prediction**: Use trained neural networks to predict missing building attributes
82
+ - **Batch Processing**: Process multiple buildings efficiently
83
+ - **Post-Processing Pipeline**: Validate and fix outputs for URBANopt-BuildStock compatibility
84
+ - Missing column filler for required URBANopt parameters
85
+ - Schema validation against options_lookup.tsv
86
+ - Cross-field consistency enforcement (HVAC, PV, foundations, etc.)
87
+ - **Simulation Ready**: Output formatted for URBANopt and other urban energy simulation tools
88
+
89
+ ## Installation
90
+
91
+ ```bash
92
+ # Clone the repository
93
+ git clone https://github.com/NatLabRockies/urban-system-generator.git
94
+ cd urban-system-generator
95
+
96
+ # Create a virtual environment
97
+ python3 -m venv .venv # Or try `python -m venv .venv` if `python3` doesn't work
98
+
99
+ # Activate the virtual environment
100
+ source .venv/bin/activate
101
+
102
+ # Upgrade packaging tools
103
+ pip install --upgrade pip setuptools wheel
104
+
105
+ # Install the package and dependencies
106
+ pip install -e .
107
+
108
+ ```
109
+
110
+ ## Command Line Interface (CLI)
111
+
112
+ After installation, the `usg` command will be available. The CLI provides easy access to all functionality:
113
+
114
+ ```bash
115
+ # Convert GeoJSON to CSV
116
+ usg geojson2csv -i buildings.json -o buildings.csv
117
+
118
+ # Predict missing attributes for a single building
119
+ usg predict-single -a "Vintage" "2000s" -a "Bedrooms" "3"
120
+
121
+ # Process batch of buildings (ML inference)
122
+ usg complete -i incomplete.csv -o completed.csv
123
+
124
+ # Post-process for URBANopt-BuildStock compatibility
125
+ usg process -i completed.csv -o uo_buildstock_mapping.csv -g buildings.json
126
+
127
+ # Run complete workflow (GeoJSON → Inference → Post-processing)
128
+ usg workflow -i buildings.json -o uo_buildstock_mapping.csv --verbose
129
+
130
+ # Get help
131
+ usg --help
132
+ ```
133
+
134
+ For detailed CLI documentation, see [docs/cli_usage.md](docs/cli_usage.md).
135
+
136
+ ## Quick Start (Python API)
137
+
138
+ ### 1. Convert GeoJSON to CSV
139
+
140
+ ```python
141
+ from usg.geojson_processor import GeoJSONProcessor
142
+ from usg.resources.model_attributes import all_model_attributes
143
+
144
+ processor = GeoJSONProcessor()
145
+ processor.geojson_to_csv(
146
+ geojson_path="buildings.json",
147
+ output_csv_path="buildings_incomplete.csv",
148
+ all_model_attributes=all_model_attributes,
149
+ )
150
+ ```
151
+
152
+ ### 2. Predict Missing Attributes
153
+
154
+ ```python
155
+ from usg.inference import USGInference
156
+ from pathlib import Path
157
+
158
+ # Get the path to bundled resources
159
+ usg_dir = Path(__file__).parent / "usg" / "resources" / "pretrained_model"
160
+
161
+ # Initialize inference engine
162
+ inference = USGInference(
163
+ model_path=usg_dir / "adaptive_model_1.keras",
164
+ cat_scaler_path=usg_dir / "cat_scaler.pkl",
165
+ num_scaler_path=usg_dir / "num_scaler.pkl",
166
+ encoding_dict_path=usg_dir / "encoding_mapper.json",
167
+ )
168
+
169
+ # Process buildings
170
+ inference.process_buildings_batch(
171
+ input_csv_path="buildings_incomplete.csv",
172
+ output_csv_path="buildings_complete.csv",
173
+ )
174
+ ```
175
+
176
+ **Note:** When using the CLI (`usg` command), resource paths are automatically resolved. The manual paths above are only needed for direct Python API usage.
177
+
178
+ ### 3. Single Building Prediction
179
+
180
+ ```python
181
+ known_attrs = {
182
+ 'Geometry Building Type RECS': 'Single-Family Detached',
183
+ 'Vintage': '2000s',
184
+ 'Geometry Floor Area': '1500-1999',
185
+ 'Geometry Stories': '2',
186
+ 'Bedrooms': '3',
187
+ }
188
+
189
+ completed = inference.predict_missing_single(known_attrs)
190
+ print(completed)
191
+ ```
192
+
193
+ ### 4. Post-Process for URBANopt-BuildStock
194
+
195
+ ```python
196
+ from usg.postprocessor import USGPostProcessor, get_default_resource_paths
197
+
198
+ # Get bundled resource paths (recommended)
199
+ options_lookup, consistency_rules = get_default_resource_paths()
200
+
201
+ # Initialize post-processor
202
+ postprocessor = USGPostProcessor(
203
+ options_lookup_path=options_lookup,
204
+ consistency_rules_path=consistency_rules,
205
+ )
206
+
207
+ # Process inference output for URBANopt compatibility
208
+ postprocessor.process(
209
+ input_csv_path="buildings_complete.csv",
210
+ output_csv_path="uo_buildstock_mapping.csv",
211
+ geojson_path="buildings.json", # Optional: for climate zone extraction
212
+ generate_reports=True, # Generate validation reports
213
+ )
214
+ ```
215
+
216
+ The post-processor performs three steps:
217
+ 1. **Missing Column Filler**: Adds required URBANopt-BuildStock columns with appropriate defaults
218
+ 2. **Schema Validator**: Validates all values against options_lookup.tsv and fixes invalid entries
219
+ 3. **Consistency Processor**: Enforces cross-field constraints (HVAC configurations, PV systems, etc.)
220
+
221
+ ## Repository Structure
222
+
223
+ ```
224
+ urban-system-generator/
225
+ ├── usg/ # Main package
226
+ │ ├── __init__.py # Package initialization
227
+ │ ├── inference.py # Inference engine
228
+ │ ├── geojson_processor.py # GeoJSON processing
229
+ │ ├── postprocessor.py # URBANopt post-processing
230
+ │ ├── model.py # Neural network model
231
+ │ ├── cli.py # Command-line interface
232
+ │ └── resources/ # Bundled model and post-processor resources
233
+ │ ├── pretrained_model/ # Trained model files
234
+ │ │ ├── adaptive_model_1.keras
235
+ │ │ ├── cat_scaler.pkl
236
+ │ │ ├── num_scaler.pkl
237
+ │ │ └── encoding_mapper.json
238
+ │ ├── postprocessor/ # Post-processor resources
239
+ │ │ ├── options_lookup.tsv # URBANopt-BuildStock schema
240
+ │ │ └── consistency_rules.json # Cross-field constraints
241
+ │ └── model_attributes.py # Model schema
242
+ ├── examples/ # Usage examples
243
+ ├── docs/ # Documentation
244
+ └── tests/ # Unit tests
245
+ ```
246
+
247
+ ## Input Data Format
248
+
249
+ ### GeoJSON Requirements
250
+
251
+ Buildings in your GeoJSON should have the following properties:
252
+
253
+ ```json
254
+ {
255
+ "type": "Feature",
256
+ "properties": {
257
+ "id": "building_001",
258
+ "type": "Building",
259
+ "building_type": "Single-Family Detached",
260
+ "year_built": 2005,
261
+ "floor_area": 2000,
262
+ "number_of_stories": 2,
263
+ "number_of_bedrooms": 3,
264
+ "number_of_residential_units": 1
265
+ },
266
+ "geometry": {...}
267
+ }
268
+ ```
269
+
270
+ ### Supported Building Types
271
+
272
+ - Single-Family Detached
273
+ - Single-Family Attached
274
+ - Multifamily (2-4 units)
275
+ - Multifamily (5+ units)
276
+ - Mobile Home
277
+
278
+ ## Model Attributes
279
+
280
+ The model can predict the following building attributes:
281
+
282
+ - HVAC Cooling Type
283
+ - HVAC Heating Type
284
+ - Heating Fuel
285
+ - Foundation Type
286
+ - Attic Type
287
+ - Insulation levels
288
+ - Window characteristics
289
+ - And more...
290
+
291
+ See `usg/resources/model_attributes.py` for the complete list.
292
+
293
+ ## Examples
294
+
295
+ See the `examples/` directory for complete usage examples:
296
+
297
+ - `example_usage.py` - Complete workflow demonstrations
298
+ - `example_geojson.json` - Sample GeoJSON file
299
+
300
+ ## Testing
301
+
302
+ The repository includes comprehensive unit and integration tests.
303
+
304
+ ```bash
305
+ # Run all tests
306
+ python run_tests.py
307
+
308
+ # Run only unit tests
309
+ python run_tests.py unit
310
+
311
+ # Run integration tests
312
+ python run_tests.py integration
313
+
314
+ # Run specific test module
315
+ python run_tests.py inference
316
+ python run_tests.py geojson
317
+
318
+ # Using pytest (alternative)
319
+ pytest tests/
320
+
321
+ # Run with coverage
322
+ pytest --cov=usg tests/
323
+ ```
324
+
325
+ ### Test Structure
326
+
327
+ - `tests/test_inference.py` - Unit tests for the inference engine
328
+ - `tests/test_geojson_processor.py` - Unit tests for GeoJSON processing
329
+ - `tests/test_integration.py` - End-to-end integration tests
330
+
331
+ ## Authors & Contributors
332
+
333
+ **Lead Developer:** Rawad El Kontar
334
+
335
+ **Organization:** National Laboratory of the Rockies (NLR)
336
+
337
+ ## Contributing
338
+
339
+ Contributions are welcome! Please:
340
+
341
+ 1. Fork the repository
342
+ 2. Create a feature branch
343
+ 3. Make your changes
344
+ 4. Add tests
345
+ 5. Submit a pull request
346
+
347
+ ## License
348
+
349
+ Copyright (c) 2025-2026, Alliance for Energy Innovation, LLC
350
+
351
+
352
+ This project is licensed under the BSD 3-Clause License. See the [LICENSE](LICENSE) file for details.
353
+
354
+ ## Citation
355
+
356
+ If you use this software in your research, please cite:
357
+
358
+ ```bibtex
359
+ @software{urban_system_generator,
360
+ title={Urban System Generator},
361
+ author={El Kontar, Rawad},
362
+ organization={National Laboratory of the Rockies},
363
+ year={2025},
364
+ url={https://github.com/NatLabRockies/urban-system-generator}
365
+ }
366
+ ```
367
+
368
+ ## Acknowledgments
369
+
370
+ This work was authored by the National Laboratory of the Rockies(NLR) for the U.S. Department of Energy (DOE), operated under Contract No. DE-AC36-08GO28308. Funding provided by NLR’s Laboratory Directed Research and Development program, and the DOE Office of Science. The views expressed in the article do not necessarily represent the views of the DOE or the U.S. Government. The U.S. Government retains and the publisher, by accepting the article for publication, acknowledges that the U.S. Government retains a nonexclusive, paid-up, irrevocable, worldwide license to publish or reproduce the published form of this work, or allow others to do so, for U.S. Government purposes.
371
+
372
+ ## Contact
373
+
374
+ For questions or support, please contact Rawad El Kontar (rawad.elkontar@nlr.gov) or open an issue on GitHub.
375
+
376
+ ---
377
+
378
+ **NLR Software Record:** SWR 25-36