Skip to content

[Econ] Anaerobic Digester CHP and RNG - #3140

Open
allisterakun wants to merge 6 commits into
refactor_preprocessfrom
anaerobic_digester_biogas
Open

[Econ] Anaerobic Digester CHP and RNG#3140
allisterakun wants to merge 6 commits into
refactor_preprocessfrom
anaerobic_digester_biogas

Conversation

@allisterakun

Copy link
Copy Markdown
Collaborator

Context

Issue(s) closed by this pull request: closes #3086

What

Why

How

Test plan

Input Changes

Output Changes

  • N/A

Filter

@allisterakun
allisterakun changed the base branch from economics to refactor_preprocess August 17, 2026 12:22

@bradenlimb bradenlimb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Calculations on the electricity to rng ratios work out for me! So we are good on that front.

However I noticed that the biophysical_aggregate value multiplied by the price_aggregate value doesn't exactly equal the line_item_by_scenario value. In the following image I get the following

495139.0225 * 0.005363327 = 2655.592727

Image

@allisterakun

Copy link
Copy Markdown
Collaborator Author

Calculations on the electricity to rng ratios work out for me! So we are good on that front.

However I noticed that the biophysical_aggregate value multiplied by the price_aggregate value doesn't exactly equal the line_item_by_scenario value. In the following image I get the following

495139.0225 * 0.005363327 = 2655.592727

Image

After a bit of digging, I believe the root cause is we are calculating the "price_aggregate" as simple daily average, rather than a weighted average:

Example

Using this example to demonstrate:

  • bio_values: [a, b, c, d, e]
  • daily_price: [x, y, y, z, z]

Therefore:

  • bio_aggregate: a + b + c + d + e
  • price_aggregate (average daily price): (x + 2y + 2z) / 5
  • line_item_by_scenario (total_revenue): ax + by + cy + dz + ez

Here we can see bio_aggregate * price_aggregate != line_item_by_scenario

Conceptualize

Here are how we are calculating the three values:

line_item_by_scenario

line_item_by_scenario is the day-level dot product:

$$\sum_{d=1}^{\text{total sim days}} (\text{bio quantity}_{day} \cdot price_{day})$$

biophysical_aggregate

biophysical_aggregate is the sum of daily biophysical values (quantities):

$$\sum_{d=1}^{\text{total sim days}} \text{bio quantity}_{day}$$

price_aggregate

price_aggregate is the simple average of the daily price values:

$$\frac{\sum_{d=1}^{\text{total sim days}} \text{price}_{day}}{(\text{total sim days})}$$

If you have $\sum_{i=1}^{N} a_i$ and $\sum_{i=1}^{N} b_i$

$(\sum_{i=1}^{N} a_i)(\sum_{i=1}^{N} b_i)$ is not the same as $\sum_{i=1}^{N} (a_i)(b_i)$.

Therefore, when you multiply biophysical_aggregate and price_aggregate together, it is not the same as the total_revenue.

Proposed Solution

To make sure this equality holds true, we can change how we calculate the price_aggregate to use a quantity-weighted average price instead of the simply daily average:

price_aggregate_quantity_weighted = total_revenue / total_quantity if total_quantity else None

Please let me know if this explanation is easy to understand, and if we want to move forward with the quantity-weighted price average!

@bradenlimb

Copy link
Copy Markdown
Collaborator

Hey @allisterakun - thanks for clarifying. The calculations you have are the ones we want. Let's leave as is. This is just the first variable that I've seen with this issue. I wonder if the others aren't calculating correctly or just aren't doing daily calcs. Probably something we should look into at some point

@bradenlimb
bradenlimb marked this pull request as ready for review August 18, 2026 19:33
@bradenlimb
bradenlimb self-requested a review August 18, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Economics] Calculate Electricity and RNG production from Anaerobic Digester Biogas

2 participants