feat: support comparing buildings across measure packages#31
Open
nllong wants to merge 1 commit into
Open
Conversation
Each ComStock "upgrade" is a different energy-efficiency measure package applied
to the same baseline building sample. Every release also publishes an
upgrades_lookup.json (upgrade id -> package name) and a measure_name_crosswalk.csv
(a stable measure_id crosswalked to the upgrade id/name used for that measure in
that release and earlier releases, since upgrade ids/measures are release-specific
and not stable across releases).
- Add ComStockProcessor.list_upgrades(save_dir) to download/cache
upgrades_lookup.json and return {upgrade_id: package_name} for the configured
release.
- Add ComStockProcessor.get_measure_crosswalk(save_dir) to download/cache
measure_name_crosswalk.csv as a DataFrame, and find_upgrade_id(save_dir,
measure_id, target_release=None) to look up the upgrade id for a stable
measure_id in a specific release, raising a clear error if that release isn't
covered by the currently loaded crosswalk (a release's crosswalk only covers
itself and earlier releases -- release_3's crosswalk covers all three
currently-supported releases).
- Refactor process_metadata() into a thin wrapper around a new
_download_metadata_for_upgrade(save_dir, upgrade) helper parameterized by
upgrade instead of hardcoded self.upgrade, and add
process_metadata_for_upgrades(save_dir, upgrades=None) which downloads and
combines metadata for multiple upgrades (defaulting to every upgrade from
list_upgrades()) into one DataFrame. Every partition already includes an
`upgrade` id and `in.upgrade_name` column, so grouping the combined result by
bldg_id lets you compare a building's results across packages.
- Add unit tests (release validation, mocked default-to-every-upgrade behavior)
and integration tests (list_upgrades, get_measure_crosswalk, find_upgrade_id
across releases, and process_metadata_for_upgrades with an explicit small
upgrade list for Delaware/SmallOffice).
- Document the new methods and a building-comparison usage example in
README.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for downloading ComStock's measure/upgrade package definitions and comparing a building's results across those packages.
Background
Each ComStock "upgrade" represents a different energy-efficiency measure package (e.g. a heat pump RTU, a VRF system, envelope upgrades, etc.) applied to the same baseline building sample. Every release also publishes:
upgrades_lookup.json— maps upgrade id → human-readable package name for that release.measure_name_crosswalk.csv— maps a stablemeasure_id(e.g.hvac_0005) to the upgrade id/name used for that measure in that release and every earlier release — because upgrade ids are not stable across releases (e.g. "Heat Pump RTU" happens to be upgrade1in all three currently-supported releases, but that's not guaranteed for every measure, and I verified several measures do shift ids release to release).What changed
list_upgrades(save_dir)— downloads/cachesupgrades_lookup.json, returns{upgrade_id: package_name}for the processor's configured release.get_measure_crosswalk(save_dir)— downloads/cachesmeasure_name_crosswalk.csvas a DataFrame.find_upgrade_id(save_dir, measure_id, target_release=None)— looks up the upgrade id for a stablemeasure_idin a specific release (defaults to the processor's own release). ReturnsNoneif the measure wasn't included in that release, and raises a clearValueErrorif the target release isn't covered by the currently-loaded crosswalk (a release's crosswalk only covers itself + earlier releases —release_3's crosswalk covers all three currently-supported releases, so it's the one to use for full cross-release comparisons).process_metadata_for_upgrades(save_dir, upgrades=None)— downloads and combines metadata for multiple upgrades into one DataFrame (defaults to every upgrade available for the release). Refactoredprocess_metadata()into a thin wrapper around a new_download_metadata_for_upgrade(save_dir, upgrade)helper so both share the same download/caching logic, just parameterized by upgrade instead of hardcoded toself.upgrade. Every partition already includes anupgradeid andin.upgrade_namecolumn, so grouping the combined result bybldg_idlets you compare a building's simulated performance across packages.Note: a building can appear more than once per upgrade in the "full" metadata (reused across census tracts, each with its own
weight) — this is a pre-existing characteristic of the underlying dataset, not something introduced here. Documented in the docstring/README.Validation
uv run pytest tests/ -m unit✅ (8 passed — release/crosswalk validation, mocked default-upgrades behavior)uv run pytest tests/ -m integration✅ (17 passed, ~2 min — list_upgrades, get_measure_crosswalk, find_upgrade_id across releases, process_metadata_for_upgrades with an explicit upgrade list for DE/SmallOffice)uv run mypy✅uv run pre-commit run --all-files✅