Fix bug defining subsector commodities when zero existing capacity#703
Fix bug defining subsector commodities when zero existing capacity#703
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where subsector commodities defined from the ExistingCapacity file were missing when their initial capacity was zero. The changes update the aggregation logic in the subsector and related tests, and adjust agent factory inputs for consistency.
- Removed the use of agent.assets in aggregate_enduses and now infer commodities directly from technologies.
- Updated the agent factory to require parsed capacity data.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_subsector.py | Updated tests to call aggregate_enduses with technologies only. |
| src/muse/sectors/subsector.py | Revised commodity aggregation and demand filtering; now aggregates directly from technologies. |
| src/muse/agents/factories.py | Refined the capacity parameter type to be a DataArray (removing support for file paths). |
| def agents_factory( | ||
| params_or_path: str | Path | list, | ||
| capacity: xr.DataArray | str | Path, | ||
| capacity: xr.DataArray, |
There was a problem hiding this comment.
Since capacity is now strictly expected to be a DataArray, consider updating related documentation and usages to make it clear that file paths are no longer supported.
dalonsoa
left a comment
There was a problem hiding this comment.
LGTM! What an impact for such small change. I guess that none of the examples and tutorials were affected by this, right?
Doesn't affect any of the examples, but was picked up by a researcher using a more complicated model. (In fact this is a bug that I accidentally introduced in v1.4, which is why it's only being picked up now 🫢) |
Description
MUSE uses subsectors which are in charge of one or more commodities. Users can explicitly pass a list of commodities in the settings file, or MUSE can infer the commodities based on the
ExistingCapacityfile.However, there's a problem with how this is done. MUSE first creates assets from the
ExistingCapacity, then aggregates the end-use commodities from these assets. However, if there are technologies inExistingCapacitywith zero initial capacity, no assets will be created for these, and these won't be included in the end-use aggregation process.E.g. a refineries sector may be in charge of oil and hydrogen. If there's no initial demand for hydrogen, the user will set initial capacity for hydrogen-producing technologies to zero. However, demand for hydrogen may increase in the future, so we still want to include hydrogen in the subsector's
self.commoditiesso that hydrogen demand get's passed to the subsector.I've fixed this by aggregating the enduse commodities from
ExistingCapacitydirectly.I've added another step during investment to remove commodities with zero demand. E.g in the above example we wouldn't want it to perform investments to meet hydrogen demand when demand is zero (there will be no investments, but it's just a waste of computation). This is probably a good thing to do anyway, but seemed especially appropriate now.
Fixes # (issue)
Type of change
Key checklist
$ python -m pytest$ python -m sphinx -b html docs docs/buildFurther checks