Modules
buildstock_fetch.main.fetch_bldg_ids(product, release_year, weather_file, release_version, state, upgrade_id)
¶
Fetch a list of Building ID's
Provided a state, returns a list of building ID's for that state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
ResCom
|
The product type (e.g., 'resstock', 'comstock') |
required |
release_year
|
ReleaseYear
|
The release year (e.g., '2021', '2022') |
required |
weather_file
|
Weather
|
The weather file type (e.g., 'tmy3') |
required |
release_version
|
str
|
The release version number (e.g., '1') |
required |
state
|
str
|
The state to fetch building ID's for. |
required |
Returns:
| Type | Description |
|---|---|
list[BuildingID]
|
A list of building ID's for the given state. |
Source code in buildstock_fetch/main.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
buildstock_fetch.main.fetch_bldg_data(bldg_ids, file_type, output_dir, max_workers=5, weather_states=None)
¶
Download building data for a given list of building ids
Downloads the data for the given building ids and returns list of paths to the downloaded files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bldg_ids
|
list[BuildingID]
|
A list of BuildingID objects to download data for. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[Path], list[str]]
|
A list of paths to the downloaded files. |
Source code in buildstock_fetch/main.py
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 | |
buildstock_fetch.read.BuildStockRead
¶
Reader class for BuildStock data downloaded with bsf.
This class provides methods to read metadata and load curve data from locally downloaded BuildStock files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
Path | S3Path | str
|
Path to the data directory (local path or S3 path). |
required |
release
|
ReleaseKey | BuildstockRelease
|
A BuildStockRelease enum member specifying the release. |
required |
states
|
USStateCode | Collection[USStateCode] | None
|
Optional State or list of States to filter data. If None, auto-detects states present on disk. |
None
|
sample_n
|
int | None
|
Optional number of buildings to sample. |
None
|
random
|
Random | int | None
|
Optional random state for reproducible sampling (Random instance or int seed). |
None
|
metadata_variant
|
Literal['standard', 'sb']
|
Metadata file variant to use. "standard" for metadata.parquet, "sb" for metadata-sb.parquet (Switchbox-specific). Defaults to "standard". |
'standard'
|
Example
from buildstock_fetch.read import BuildStockRead bsr = BuildStockRead( ... data_path="./data", ... release="res_2024_tmy_2", ... states="NY", ... ) metadata = bsr.read_metadata(upgrades=["0", "1"])
Source code in buildstock_fetch/read.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
buildstock_fetch.mixed_upgrade.MixedUpgradeScenario
¶
Class for orchestrating multi-year adoption trajectories across multiple upgrade scenarios.
This class enables defining and reading heterogeneous upgrade mixes where buildings progressively adopt different upgrades over time. Buildings are sampled once from a baseline upgrade, then allocated to different upgrades according to adoption fractions per year. Monotonic adoption is enforced: buildings can only move from baseline to an upgrade, never backwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
Path | S3Path | str
|
Path to the data directory (local path or S3 path). |
required |
scenario_name
|
str
|
Name of the pathway scenario. will be used to create subdirectories when writing out the metadata and load curves. |
required |
release
|
ReleaseKey | BuildstockRelease
|
A BuildstockRelease or release key string specifying the release. |
required |
states
|
USStateCode | Collection[USStateCode] | None
|
Optional state code or list of state codes to filter data. If None, auto-detects states present on disk. |
None
|
sample_n
|
int | None
|
Optional number of buildings to sample from baseline. |
None
|
random
|
Random | int | None
|
Optional Random instance or seed for reproducible sampling and allocation. |
None
|
scenario
|
dict[int, list[float]] | None
|
Dict mapping upgrade IDs to adoption fractions per year. Example: {4: [0.06, 0.18, 0.30], 8: [0.04, 0.12, 0.20]} represents 3 years where upgrade 4 grows from 6% to 30% adoption and upgrade 8 grows from 4% to 20% adoption. |
None
|
Example
from buildstock_fetch.mixed_upgrade import MixedUpgradeScenario from buildstock_fetch.scenarios import uniform_adoption scenario = uniform_adoption( ... upgrade_ids=[4, 8], ... weights={4: 0.6, 8: 0.4}, ... adoption_trajectory=[0.1, 0.3, 0.5], ... ) mus = MixedUpgradeScenario( ... data_path="./data", ... scenario_name="rapid_adoption", ... release="res_2024_tmy3_2", ... states="NY", ... sample_n=1000, ... random=42, ... scenario=scenario, ... ) metadata = mus.read_metadata().collect() mus.export_scenario_to_cairo("./scenario.csv") mus.save_metadata_parquet() # writes to disk or S3 mus.save_hourly_load_parquet() # writes to disk or S3
Source code in buildstock_fetch/mixed_upgrade.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
downloaded_metadata
cached
property
¶
Cached property for metadata file discovery only.
materialized_scenario
cached
property
¶
Materialize building allocations for all years in the scenario.
export_scenario_to_cairo(output_path)
¶
Export scenario to CAIRO-compatible CSV format.
Creates a CSV file with one row per building and one column per year. Each cell contains the upgrade ID for that building in that year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str | Path | S3Path
|
Path where the CSV file should be written (local or S3). |
required |
Output format
bldg_id,year_0,year_1,year_2 405821,0,0,0 612547,0,4,4 789234,0,0,8
Raises:
| Type | Description |
|---|---|
ScenarioDataNotFoundError
|
If data for scenario upgrades is not on disk. |
Example
mus.export_scenario_to_cairo("./scenario.csv") Exported scenario for 1000 buildings across 3 years to ./scenario.csv
Source code in buildstock_fetch/mixed_upgrade.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
read_load_curve_15min(years=None)
¶
Read 15-minute load curve data for specified years in the scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list[int] | None
|
List of year indices to include, or None for all years. |
None
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A Polars LazyFrame with columns: - bldg_id: Building ID - upgrade_id: Upgrade ID - year: Year index - timestamp: Timestamp of the load data - ...: Energy columns (e.g., out.electricity.total.energy_consumption) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any year index is out of range. |
ScenarioDataNotFoundError
|
If load curve data for scenario upgrades is not on disk. |
Source code in buildstock_fetch/mixed_upgrade.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
read_load_curve_annual(years=None)
¶
Read annual load curve data for specified years in the scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list[int] | None
|
List of year indices to include, or None for all years. |
None
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A Polars LazyFrame with columns: - bldg_id: Building ID - upgrade_id: Upgrade ID - year: Year index - ...: Annual energy totals |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any year index is out of range. |
ScenarioDataNotFoundError
|
If load curve data for scenario upgrades is not on disk. |
Source code in buildstock_fetch/mixed_upgrade.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
read_load_curve_daily(years=None)
¶
Read daily load curve data for specified years in the scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list[int] | None
|
List of year indices to include, or None for all years. |
None
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A Polars LazyFrame with columns: - bldg_id: Building ID - upgrade_id: Upgrade ID - year: Year index - timestamp: Timestamp of the load data - ...: Energy columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any year index is out of range. |
ScenarioDataNotFoundError
|
If load curve data for scenario upgrades is not on disk. |
Source code in buildstock_fetch/mixed_upgrade.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
read_load_curve_hourly(years=None)
¶
Read hourly load curve data for specified years in the scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list[int] | None
|
List of year indices to include, or None for all years. |
None
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A Polars LazyFrame with columns: - bldg_id: Building ID - upgrade_id: Upgrade ID - year: Year index - timestamp: Timestamp of the load data - ...: Energy columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any year index is out of range. |
ScenarioDataNotFoundError
|
If load curve data for scenario upgrades is not on disk. |
Source code in buildstock_fetch/mixed_upgrade.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
read_metadata(years=None)
¶
Read metadata for specified years in the scenario.
Returns a LazyFrame containing metadata for all buildings and years in the scenario. Each row represents one building in one year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list[int] | None
|
List of year indices to include (0-indexed), or None for all years. Example: [0, 1, 2] or None |
None
|
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A Polars LazyFrame with columns: - bldg_id: Building ID (from sampled baseline) - upgrade_id: Upgrade ID for this building in this year (0 or scenario upgrade) - year: Year index (0-indexed) - ...: Original metadata columns (e.g., in.state, in.vintage, etc.) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any year index is out of range. |
ScenarioDataNotFoundError
|
If metadata for scenario upgrades is not on disk. |
Example
Read metadata for all years¶
metadata = mus.read_metadata() df = metadata.collect()
Read metadata for specific years¶
metadata_early = mus.read_metadata(years=[0, 1])
Source code in buildstock_fetch/mixed_upgrade.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
save_hourly_load_parquet(path=None)
¶
Save mixed upgrade hourly load curves to partitioned parquet datasets.
Output structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | S3Path | str | None
|
Optional base path to write to. Defaults to the release path. |
None
|
Source code in buildstock_fetch/mixed_upgrade.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
save_metadata_parquet(path=None)
¶
Save mixed upgrade metadata to a partitioned parquet dataset.
Output structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | S3Path | str | None
|
Optional base path to write to. Defaults to data_path/release/mixed_upgrade. |
None
|
Source code in buildstock_fetch/mixed_upgrade.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
buildstock_fetch.scenarios.uniform_adoption(upgrade_ids, weights, adoption_trajectory)
¶
Generate a scenario from total adoption trajectory and fixed upgrade weights.
This helper function distributes a total adoption trajectory across multiple upgrades according to fixed weights. For example, if 30% of buildings adopt in year 1, and upgrade 4 has weight 0.6, then 18% of buildings will adopt upgrade 4 in year 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upgrade_ids
|
list[int]
|
List of upgrade IDs to include in the scenario. |
required |
weights
|
dict[int, float]
|
Per-upgrade share of total adopters. Must sum to 1.0 (±1e-6). Example: {4: 0.6, 8: 0.4} means 60% choose upgrade 4, 40% choose upgrade 8. |
required |
adoption_trajectory
|
list[float]
|
Total adoption fraction per year. Must be non-decreasing. Example: [0.1, 0.3, 0.5] means 10%, 30%, 50% total adoption over 3 years. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, list[float]]
|
Scenario dict mapping upgrade IDs to per-year adoption fractions. |
Raises:
| Type | Description |
|---|---|
InvalidScenarioError
|
If weights don't sum to 1.0, contain invalid values, or if adoption_trajectory is invalid. |
Example
scenario = uniform_adoption( ... upgrade_ids=[4, 8], ... weights={4: 0.6, 8: 0.4}, ... adoption_trajectory=[0.1, 0.3, 0.5], ... ) scenario {4: [0.06, 0.18, 0.30], 8: [0.04, 0.12, 0.20]}
Source code in buildstock_fetch/scenarios.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |