-
Notifications
You must be signed in to change notification settings - Fork 2
Rebase/decompose #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Rebase/decompose #49
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 710c62f
Renaming scale_ratios to percent_change_dict in parametrize_charge_di…
dalyw 276c0e6
Simplifying test_decompose_consumption_pyo with approx
dalyw d9873aa
Changing decompose_exports argument to decomposition_type, which can …
dalyw ed883c2
Adding missing arguments in test_costs.py
dalyw 00bfa15
COSTS
dalyw a16404f
Fixing bug with duplicated conversion_factor in calculate_cost
dalyw 39267ea
Since conversion_factor is applied earlier during import/export decom…
dalyw 501308e
Consolidating get_unique_row_name and default_varstr_alias_func
dalyw 695b880
Cleaning up calculate_energy_cost
dalyw fcbf53d
Reverting changes to default_varstr_alias_func
dalyw 982dd43
Adding test calling max_pos on pyo scalar
dalyw 5b3c611
Reformatted with black
dalyw 08572c0
Add comprehensive test coverage for utils and costs
dalyw b1a2ab2
Removing uneeded else statements in calculate_cost if conversion / de…
dalyw 8a67db9
Correcting UserWarning syntax in costs.py
dalyw c50e6c7
Creating new test to address bug with double unit conversions in item…
fletchapin df561c0
Fixed errors in rebase so that only two tests fail now
fletchapin 399c5cb
Fixing flake8 errors
fletchapin 502009c
Trying to address double unit conversion
fletchapin dd660b1
Fixed unit conversion errors and all tests now passing
fletchapin 1aa760c
Autoreformatted with black
fletchapin b1dc01f
Creating codecov.yml file to try to address patch coverage
fletchapin 3b8cadd
Fixed flake8 errors
fletchapin f26de35
Fixing documentation formatting
fletchapin 03da2db
Fixing whitespace error
fletchapin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| # 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"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This formatting isn't working, I think due to indentation? Should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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?