feat(stebbs): Enable multiple building archetypes (#360)#1036
feat(stebbs): Enable multiple building archetypes (#360)#1036
Conversation
Preview Deployed
Note This preview is ephemeral. It will be lost when:
To restore, push any commit to this PR. |
Phase 1 & 2a of GH#360 implementation: - Change nbtypes from compile-time PARAMETER to runtime variable - Add nbtypes_max=10 as upper bound for archetype count - Add building_archetypes allocatable array to SUEWS_SITE type - Add sfr_bldg_arch for archetype surface fractions - Update allocation/deallocation routines This provides the foundational data structures for multi-archetype support while maintaining backwards compatibility with single-archetype configurations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2b (partial): - Add loop to copy single archetype to all building_archetypes array slots - Add loop to initialise all building archetypes via gen_building - Add i_arch loop variable declaration The physics still uses buildings(1) for calculations. Full loop and aggregation will be implemented when Python multi-archetype config is ready. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 3-6 of multi-archetype implementation:
- Add `sfr` field to ArchetypeProperties for surface fraction
- Add `building_archetypes` dict field to SiteProperties for named archetypes
- Add validator for sfr sum == 1.0 and max 10 archetypes
- Add `effective_archetypes` property and `nbtypes` property
- Add indexed DataFrame serialisation (to_df_state_indexed, from_df_state_indexed)
- Add STEBBS_ARCHETYPE output group for per-archetype variables
- Add generate_archetype_variables() function for dynamic variable generation
- Add comprehensive test suite (19 tests)
YAML config example:
```yaml
building_archetypes:
residential:
sfr: 0.6
stebbs_Height: 8.5
commercial:
sfr: 0.4
stebbs_Height: 25.0
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e974791 to
57e5b42
Compare
- Use modern type hints (dict instead of Dict) - Fix unused loop variables with .values() iteration - Use direct assignment instead of object.__setattr__ - Simplify control flow with elif - Use iterable unpacking for list concatenation - Use next(iter()) instead of list slice - Remove unused numpy/pandas imports in tests - Fix regex patterns with raw strings - Sort imports with ruff All smoke tests and multi-archetype tests pass (33/33).
|
Hi @yiqing1021, please take a look at this and see whether the prototype aligns with our expectations. |
…#360) Add .sort_index(axis=1) after DataFrame creation to ensure MultiIndex columns are lexicographically sorted before access. This eliminates "indexing past lexsort depth" warnings when accessing DataFrame cells. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Hi Ting, Thanks for adding the new STEBBS features — the prototype looks good and the approach is reasonable. A few points I think we should plan to address in future work: 1. yaml inputs for multiple archetypes. 2. aggregated output. |
|
Thanks for the review, Yiqing. Re: YAML inputs for multiple archetypes Agreed - the infrastructure is in place but YAML schema needs extending. The Pydantic model already supports Re: aggregated output Just to clarify - the PR already provides per-archetype outputs (e.g., For STEBBS-SS coupling, the current design stores per-archetype surface temperatures. If SS needs a single aggregated value, we'd compute the weighted average at the coupling interface. This keeps maximum flexibility internally. Shall we merge this first and create follow-up issues to track the remaining work? |
|
To clarify scope: this PR establishes the infrastructure (data model, Fortran arrays, initialisation loop), while the actual per-archetype calculations and output generation are follow-up work. Proposal: let's expand #360 with sub-issues to track the full feature:
We can link this PR to close sub-issue 1, then work through the others. Thoughts? @yiqing1021 |
|
Yes, I agree to merge this infrastructure for multi-archetype. Also we need to let @MatthewPaskin know this change because he designed the STEBBS structure. |
|
This looks good to me @yiqing1021 @sunt05 , however, where is the fraction for each archetype coming in? This has not previously been a parameter for STEBBS (YL correct me if I am wrong). There is however, the surface area and certain datasets contain the count of the archetype. I think a discussion may need to be had with Denise, Stefan and Sue with regarding how STEBBS aggregates across the different archetypes. |
|
Thanks both @yiqing1021 @MatthewPaskin - let's leave this open for now. Good point about the fraction parameter, Matthew. The From a maintenance perspective, STEBBS is becoming a substantial component of SUEWS. Before we proceed further, I'd like to have a clearer picture of how STEBBS should integrate as an organic component - particularly around:
Let's leave this to our next SUEWS catch-up. |
|
Thanks for these useful consideration, @MatthewPaskin ! This PR introduce a parameter “sfr_bldg_arch” for the aggregation, but currently not used. You are right, we should discuss how to do the aggregation of archetypes, but that likely sits outside SUEWS/STEBBS |
Summary
This PR implements GH#360 - enabling multiple building archetypes in STEBBS.
Completed Phases
Phase 1: Made
nbtypesdynamic in FortranPARAMETERto runtime variablenbtypes_max=10as upper boundPhase 2a: Updated Fortran types for multi-archetype arrays
building_archetypes(:)allocatable array toSUEWS_SITEsfr_bldg_arch(:)for archetype surface fractionsPhase 2b: Added archetype initialisation loop in driver
suews_ctrl_driver.f95Phase 3: Updated Python/Pydantic data model
sfrfield toArchetypePropertiesbuilding_archetypesdict field toSitePropertiessfr sum == 1.0and max 10 archetypeseffective_archetypesproperty andnbtypespropertyPhase 4: Extended DataFrame bridge for multi-archetype
to_df_state_indexed,from_df_state_indexed)nbtypesandarchetype_namesin DataFramePhase 5: Added per-archetype output variables
STEBBS_ARCHETYPEoutput groupgenerate_archetype_variables()function for dynamic variable generationPhase 6: Created tests and fixtures
Remaining Work (Future PRs)
DOT_PRODUCTpatternDesign Decisions
STEBBS_ARCHETYPEoutput group{variable}_{archetype_name}format (e.g.,Tair_ind_residential)DOT_PRODUCT(flux_array, sfr_array)patternYAML Configuration Example
Test plan
🤖 Generated with Claude Code