Skip to content

Exclude un-produced commodities from sector "costs" output#834

Merged
tsmbland merged 4 commits intomainfrom
costs_output
Apr 23, 2026
Merged

Exclude un-produced commodities from sector "costs" output#834
tsmbland merged 4 commits intomainfrom
costs_output

Conversation

@tsmbland
Copy link
Copy Markdown
Collaborator

@tsmbland tsmbland commented Apr 23, 2026

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_quantity related to the sum_over argument which was previously unused

@tsmbland tsmbland changed the title Exclude un-produced commodities from costs output Exclude un-produced commodities from sector "costs" output Apr 23, 2026
@tsmbland tsmbland requested a review from Copilot April 23, 2026 14:23
@tsmbland tsmbland marked this pull request as ready for review April 23, 2026 14:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_quantity to use quantity.dims when applying sum_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.

Comment thread src/muse/outputs/sector.py
Comment on lines +270 to +272
self.outputs(
self.output_data, self.capacity, year=year, commodities=self.commodities
)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/muse/outputs/sector.py Outdated
@tsmbland tsmbland requested a review from martinstringer April 23, 2026 15:36
@tsmbland tsmbland merged commit 331ba3f into main Apr 23, 2026
14 checks passed
@tsmbland tsmbland deleted the costs_output branch April 23, 2026 15:54
@github-project-automation github-project-automation Bot moved this to ✅ Done in MUSE Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants