Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7cdf4f
Initializing branch for decomposing positive/negative charges (branch…
dalyw Aug 8, 2025
710c62f
Renaming scale_ratios to percent_change_dict in parametrize_charge_di…
dalyw Sep 8, 2025
276c0e6
Simplifying test_decompose_consumption_pyo with approx
dalyw Sep 8, 2025
d9873aa
Changing decompose_exports argument to decomposition_type, which can …
dalyw Sep 10, 2025
ed883c2
Adding missing arguments in test_costs.py
dalyw Sep 12, 2025
00bfa15
COSTS
dalyw Sep 15, 2025
a16404f
Fixing bug with duplicated conversion_factor in calculate_cost
dalyw Sep 15, 2025
39267ea
Since conversion_factor is applied earlier during import/export decom…
dalyw Sep 15, 2025
501308e
Consolidating get_unique_row_name and default_varstr_alias_func
dalyw Sep 15, 2025
695b880
Cleaning up calculate_energy_cost
dalyw Sep 15, 2025
fcbf53d
Reverting changes to default_varstr_alias_func
dalyw Sep 17, 2025
982dd43
Adding test calling max_pos on pyo scalar
dalyw Oct 1, 2025
5b3c611
Reformatted with black
dalyw Oct 1, 2025
08572c0
Add comprehensive test coverage for utils and costs
dalyw Oct 1, 2025
b1a2ab2
Removing uneeded else statements in calculate_cost if conversion / de…
dalyw Oct 1, 2025
8a67db9
Correcting UserWarning syntax in costs.py
dalyw Oct 17, 2025
c50e6c7
Creating new test to address bug with double unit conversions in item…
fletchapin Dec 8, 2025
df561c0
Fixed errors in rebase so that only two tests fail now
fletchapin Dec 9, 2025
399c5cb
Fixing flake8 errors
fletchapin Dec 9, 2025
502009c
Trying to address double unit conversion
fletchapin Dec 15, 2025
dd660b1
Fixed unit conversion errors and all tests now passing
fletchapin Dec 16, 2025
1aa760c
Autoreformatted with black
fletchapin Dec 16, 2025
b1dc01f
Creating codecov.yml file to try to address patch coverage
fletchapin Dec 16, 2025
3b8cadd
Fixed flake8 errors
fletchapin Dec 16, 2025
f26de35
Fixing documentation formatting
fletchapin Dec 16, 2025
03da2db
Fixing whitespace error
fletchapin Dec 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: auto
patch:
default:
enabled: yes
target: 100%
threshold: 5%
91 changes: 75 additions & 16 deletions docs/how_to_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,91 @@ the previous consumption during this billing period in conjunction with `consump
How to Use `demand_scale_factor`
================================

By default `demand_scale_factor=1`, meaning that there will be no modifications applied to the demand or energy charges.
The purpose of the scale factor is to modify the demand charges proportional to energy charges when performing moving horizon optimization.
The `demand_scale_factor` parameter allows you to scale demand charges to reflect shorter optimization horizons or to prioritize demand differently across sequential optimization horizons.

There are various heuristics that could be used to calculate the scale factor (see :ref:`why-scale-demand`),
but for now let's assume that we just want to scale the demand charge down by the length of the horizon window proportional to billing period.
By default, `demand_scale_factor=1.0`. Use values less than 1.0 when solving for a subset of the billing period, or to adjust demand charge weighting in sequential optimization.

When `demand_scale_factor < 1.0`, demand charges are proportionally reduced to reflect the shorter optimization horizon. This is useful for:
- Moving horizon optimization where you solve for sub-periods of the billing cycle
- Sequential optimization where you want to reduce demand charge weighting as time goes on in the month

.. code-block:: python

from eeco import costs
from electric_emission_cost import costs
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an older version using electric_emission_cost name rather than eeco?


# load necessary data
start_dt = np.datetime64("2024-07-10")
end_dt = np.datetime64("2024-07-11")
charge_dict = costs.get_charge_dict(start_dt, end_dt, tariff_df)
num_timesteps_horizon = 96
num_timesteps_billing = 96 * 31
# E.g. solving for 3 days out of a 30-day billing period
demand_scale_factor = 3 / 30

result, model = costs.calculate_cost(
charge_dict,
consumption_data,
demand_scale_factor=demand_scale_factor
# ...
)

# this is just a CVXPY variable, but a user would provide constraints to the optimization problem
consumption_data_dict = {"electric": cp.Variable(num_timesteps), "gas": cp.Variable(num_timesteps)}
For more details on applying the sequential optimization strategy, see:

total_monthly_bill, _ = costs.calculate_costs(
Bolorinos, J., Mauter, M.S. & Rajagopal, R. Integrated Energy Flexibility Management at Wastewater Treatment Facilities. *Environ. Sci. Technol.* **57**, 46, 18362–18371 (2023). DOI: [10.1021/acs.est.3c00365](https://doi.org/10.1021/acs.est.3c00365)

In `bibtex` format:

.. code-block:: bibtex

@Article{Bolorinos2023,
author={Bolorinos, Jose
and Mauter, Meagan S.
and Rajagopal, Ram},
title={Integrated Energy Flexibility Management at Wastewater Treatment Facilities},
journal={Environmental Science & Technology},
year={2023},
month={Jun},
day={16},
volume={57},
number={46},
pages={18362--18371},
doi={10.1021/acs.est.3c00365},
url={https://doi.org/10.1021/acs.est.3c00365}
}


.. _decompose-exports:

How to Use `decomposition_type`
===============================

The `decomposition_type` parameter allows you to decompose consumption data into positive (imports) and negative (exports) components. This is useful when you have export charges or credits in your rate structure.
Options include:

- Default `None`
- `"binary_variable"`: To be implemented
- `"absolute_value"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This formatting isn't working, I think due to indentation?

Should be
Options:

  • Default None
  • "absolute_value"
  • "binary_variable": To be implemented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! There needs to be a blank line before and after the enumerated list


.. code-block:: python

from electric_emission_cost import costs

# Example with export charges
charge_dict = {
"electric_export_0_2024-07-10_2024-07-10_0": np.ones(96) * 0.025,
}

consumption_data = {
"electric": np.concatenate([np.ones(48) * 10, -np.ones(48) * 5]),
"gas": np.ones(96),
}

# Decompose consumption into imports and exports
result, model = costs.calculate_cost(
charge_dict,
consumption_data_dict,
demand_scale_factor=num_timesteps_horizon/num_timesteps_billing
consumption_data,
decomposition_type="absolute_value"
)

When decomposition_type is not None the function creates separate variables for positive consumption (imports) and negative consumption (exports)
and applies export charges only to the export component.
For Pyomo models, decomposition_type adds a constraint total_consumption = imports - exports


.. _varstr-alias:

How to Use `varstr_alias_func`
Expand Down
1 change: 1 addition & 0 deletions docs/how_to_cost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ NumPy
# one month of 15-min intervals
num_timesteps = 24 * 4 * 31
# this is synthetic consumption data, but a user could provide real historical meter data
# Positive values represent imports, negative values represent exports in consumption data
consumption_data_dict = {"electric": np.ones(num_timesteps) * 100, "gas": np.ones(num_timesteps))}
total_monthly_bill, _ = costs.calculate_cost(charge_dict, consumption_data_dict)

Expand Down
Loading
Loading