{ "cells": [ { "cell_type": "markdown", "id": "a5243371", "metadata": {}, "source": [ "\n", "*This notebook contains material from [CBE60499](https://ndcbe.github.io/CBE60499);\n", "content is available [on Github](git@github.com:ndcbe/CBE60499.git).*\n" ] }, { "cell_type": "markdown", "id": "6ffcc0d6", "metadata": {}, "source": [ "\n", "< [1.0 Getting Started with Pyomo](https://ndcbe.github.io/CBE60499/01.00-Pyomo-Introduction.html) | [Contents](toc.html) | [Tag Index](tag_index.html) | [1.2 Pyomo Mini-Project: Receding Horizon Stochastic Control](https://ndcbe.github.io/CBE60499/01.02-Pyomo-Mini-Project.html) >
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20c75ddf",
"metadata": {},
"outputs": [],
"source": [
"# IMPORT DATA FILES USED BY THIS NOTEBOOK\n",
"import os, requests\n",
"\n",
"file_links = [(\"data/Prices_DAM_ALTA2G_7_B1.csv\", \"https://ndcbe.github.io/CBE60499/data/Prices_DAM_ALTA2G_7_B1.csv\")]\n",
"\n",
"# This cell has been added by nbpages. Run this cell to download data files required for this notebook.\n",
"\n",
"for filepath, fileurl in file_links:\n",
" stem, filename = os.path.split(filepath)\n",
" if stem:\n",
" if not os.path.exists(stem):\n",
" os.mkdir(stem)\n",
" if not os.path.isfile(filepath):\n",
" with open(filepath, 'wb') as f:\n",
" response = requests.get(fileurl)\n",
" f.write(response.content)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1-60-Minutes-to-Pyomo:-An-Energy-Storage-Model-Predictive-Control-Example)",
"section": "1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example"
}
},
"source": [
"# 1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"nbpages": {
"level": 1,
"link": "[1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1-60-Minutes-to-Pyomo:-An-Energy-Storage-Model-Predictive-Control-Example)",
"section": "1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example"
}
},
"outputs": [],
"source": [
"# This code cell installs packages on Colab\n",
"\n",
"import sys\n",
"if \"google.colab\" in sys.modules:\n",
" !wget \"https://raw.githubusercontent.com/ndcbe/CBE60499/main/notebooks/helper.py\"\n",
" import helper\n",
" helper.install_idaes()\n",
" helper.install_ipopt()\n",
" helper.install_glpk()\n",
" helper.download_data(['Prices_DAM_ALTA2G_7_B1.csv'])\n",
" helper.download_figures(['battery.png','pyomo-table-4.1.png',\n",
" 'pyomo-table-4.2.png','pyomo-table-4.3.png',\n",
" 'pyomo-table-4.4.png','pyomo-table-4.6.png'])"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"nbpages": {
"level": 1,
"link": "[1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1-60-Minutes-to-Pyomo:-An-Energy-Storage-Model-Predictive-Control-Example)",
"section": "1.1 60 Minutes to Pyomo: An Energy Storage Model Predictive Control Example"
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import pyomo.environ as pyo\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[1.1.1 Problem Setup](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1-Problem-Setup)",
"section": "1.1.1 Problem Setup"
}
},
"source": [
"## 1.1.1 Problem Setup"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 3,
"link": "[1.1.1.1 Background](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1.1-Background)",
"section": "1.1.1.1 Background"
}
},
"source": [
"### 1.1.1.1 Background"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 3,
"link": "[1.1.1.1 Background](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1.1-Background)",
"section": "1.1.1.1 Background"
}
},
"source": [
"In many regions of the world, including the US, electricity generation is scheduled through wholesale electricity markets. Individual generators (resources) transmit information about their operating costs and constraints to the market via a bid. The market operator then solves an optimization problem (e.g., the unit commitment problem) to minimize the total electricity generator cost. The market operator decides which generators to dispatch during each hour to satisfy the forecasted demand while honoring limitations for each generator (e.g., maximum ramp rate, the required time for start-up/shutdown, etc.).\n",
"\n",
"\n",
"\n",
"Read more information here:\n",
"* https://www.ferc.gov/industries-data/market-assessments/electric-power-markets\n",
"* https://www.sciencedirect.com/science/article/pii/S0306261916318487"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 3,
"link": "[1.1.1.2 Pandas and Energy Prices](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1.2-Pandas-and-Energy-Prices)",
"section": "1.1.1.2 Pandas and Energy Prices"
}
},
"source": [
"### 1.1.1.2 Pandas and Energy Prices"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 3,
"link": "[1.1.1.2 Pandas and Energy Prices](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1.2-Pandas-and-Energy-Prices)",
"section": "1.1.1.2 Pandas and Energy Prices"
}
},
"source": [
"The CSV (comma separated value) file `Prices_DAM_ALTA2G_7_B1.csv` contains price data for a single location in California for an entire year. The prices are set every hour and have units $/MWh. We will use the package `pandas` to import and analyze the data."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"nbpages": {
"level": 3,
"link": "[1.1.1.2 Pandas and Energy Prices](https://ndcbe.github.io/CBE60499/01.01-Pyomo-Nuts-and-Bolts.html#1.1.1.2-Pandas-and-Energy-Prices)",
"section": "1.1.1.2 Pandas and Energy Prices"
}
},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | price | \n", "
---|---|
0 | \n", "36.757 | \n", "
1 | \n", "34.924 | \n", "
2 | \n", "33.389 | \n", "
3 | \n", "32.035 | \n", "
4 | \n", "33.694 | \n", "
\n", " | price | \n", "
---|---|
count | \n", "8760.000000 | \n", "
mean | \n", "32.516994 | \n", "
std | \n", "9.723477 | \n", "
min | \n", "-2.128700 | \n", "
25% | \n", "26.510000 | \n", "
50% | \n", "30.797500 | \n", "
75% | \n", "37.544750 | \n", "
max | \n", "116.340000 | \n", "
"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}