Exclude un-produced commodities from sector "costs" output#834
Exclude un-produced commodities from sector "costs" output#834
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates sector “costs” output generation to exclude commodities that aren’t actually produced (zero supply) and to restrict the output to commodities owned by the sector, while also fixing market_quantity so the sum_over argument is applied correctly.
Changes:
- Pass sector-owned commodities into the sector outputs pipeline.
- Fix
market_quantityto usequantity.dimswhen applyingsum_over. - Filter the sector “costs” output by (a) positive total supply and (b) sector-owned commodities.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/muse/sectors/sector.py |
Passes sector commodity list into outputs call to enable downstream filtering. |
src/muse/outputs/sector.py |
Propagates extra kwargs through output factory; fixes sum_over handling; filters “costs” output using supply and owned-commodity list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.outputs( | ||
| self.output_data, self.capacity, year=year, commodities=self.commodities | ||
| ) |
There was a problem hiding this comment.
Sector.save_outputs now always passes commodities=... into self.outputs(...). Since Sector.__init__ allows a custom outputs callable (not necessarily created by muse.outputs.sector.factory), this is a backward-incompatible API change and will raise TypeError for callables that don’t accept that kwarg. Consider either (a) making the call conditional via inspect.signature / checking for **kwargs, or (b) catching TypeError and falling back to calling without commodities, so custom outputters keep working.
This filters the sector "costs" output file (which gives the weighted average cost of production of commodities) to only include commodities that are actually produced. Commodities with supply of zero were previously included as rows with zero costs (just due to a slight quirk in the way that supply costs are calculated, see this function). Now these rows will no longer appear.
I also decided to filter this further to only include commodities "owned" by the sector (i.e. commodities that the sector is trying to meet the demands of). This effectively excludes environmental commodities such as CO2, which may be produced and have a "supply cost", but is pretty meaningless and potentially confusing so probably better to exclude.
Also fixing a bug in
market_quantityrelated to thesum_overargument which was previously unused