Fix more broadcasting errors #533
Closed
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.
Description
This PR fixes a few more bugs caused by automatic broadcasting.
I identified these using the approach suggested by @dalonsoa here, which works beautifully. It essentially turns off automatic broadcasting (I've limited this to the timeslice dimension), and throws an error message when broadcasting would be required to perform the intended operation. I've implemented this in a separate PR/branch (#530). I then ran the code in that branch and went through every place where it complained about automatic broadcasting, and was able to spot a few more places where
convert_timesliceshould be applied to split quantities over the timeslice dimension (rather than automatic broadcasting as was being done previously).I then went back and applied most of these changes here. Long run we'll want to merge #530 to properly turn off automatic broadcasting (rather than just fixing errors like I'm doing here). However, there are lots of places where it ends up complaining about benign things, and it will still take some work to make it completely happy. Right now I just want to fix these bugs as quickly as possible. (#530 is also way ahead of this one and has a completely different
timeslicesmodule which isn't ready yet.)Summary of the changes:
emission_costobjectiveemissionfunction, where emissions for the whole year were being applied to every timeslice. This mostly has implications for models using the carbon budget, as emissions will now be much lower than before. I've updated the carbon budget tutorial to reflect thisgross_marginwith the calculation of consumption and production costsThere's at least one more bug of this type remaining (in the
consumptionfunction), but I'm going to tackle that in a separate PR as it has much larger implicationsFixes # (issue)
Type of change
Key checklist
$ python -m pytest$ python -m sphinx -b html docs docs/buildFurther checks