{ "cells": [ { "cell_type": "markdown", "id": "55cafb4cacb59fae", "metadata": {}, "source": [ "# Ancillary Pull Example" ] }, { "cell_type": "markdown", "id": "fbca5408-ed14-4e4f-9223-963fbbd4a273", "metadata": { "tags": [] }, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "813d463b-a160-4754-a8e4-3877c13545b0", "metadata": { "tags": [] }, "outputs": [], "source": [ "import time\n", "import os\n", "import pandas as pd\n", "from tyba_client.client import Client, Market, AncillaryService\n", "\n", "PAT = os.environ[\"TYBA_PAT\"]\n", "client = Client(PAT)\n", "# client = Client('Your PAT') #Insert your PAT here\n", "\n", "# Relevant Data Classes\n", "services = client.services\n", "lmp = services.lmp\n", "ancillary = services.ancillary" ] }, { "cell_type": "markdown", "id": "dba0dd1e-4a56-46bd-8a4d-7d32f6e3baf6", "metadata": {}, "source": [ "## Pricing Regions" ] }, { "cell_type": "code", "execution_count": 2, "id": "f118909b-9e54-488f-a09c-6d8e87c74e66", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
regionstart_yearend_year
0Pacific Northwest - SP1520102025
1WAPA20102025
2WAPA20102025
3WAPA20102025
4ZP2620102025
............
219ZP2620102025
220Mexico20102025
221SMUD20102025
222Sutter20102025
223NP1520102025
\n", "

224 rows × 3 columns

\n", "
" ], "text/plain": [ " region start_year end_year\n", "0 Pacific Northwest - SP15 2010 2025\n", "1 WAPA 2010 2025\n", "2 WAPA 2010 2025\n", "3 WAPA 2010 2025\n", "4 ZP26 2010 2025\n", ".. ... ... ...\n", "219 ZP26 2010 2025\n", "220 Mexico 2010 2025\n", "221 SMUD 2010 2025\n", "222 Sutter 2010 2025\n", "223 NP15 2010 2025\n", "\n", "[224 rows x 3 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "as_regions = ancillary.get_pricing_regions(\n", " iso=\"CAISO\",\n", " service=AncillaryService.REGULATION_UP,\n", " market=Market.DA).json()\n", "as_regions = pd.DataFrame(as_regions)\n", "as_regions" ] }, { "cell_type": "markdown", "id": "054cfa79-f72f-4e53-90ca-44217f9e9e62", "metadata": {}, "source": [ "## Helper Functions" ] }, { "cell_type": "code", "execution_count": 3, "id": "8ddff24c-1bb3-4972-bae0-faf3cd48844e", "metadata": {}, "outputs": [], "source": [ "def as_pull(services, regions, start_year, end_year):\n", " all_prices = {}\n", " for region in regions:\n", " for name, service in services.items():\n", " print(region,name)\n", " as_prices = ancillary.get_prices(\n", " iso=\"CAISO\",\n", " service=service, \n", " market=Market.DA,\n", " region=region,\n", " start_year=start_year,\n", " end_year=end_year,\n", " ).json()\n", " tdom = pd.to_datetime(as_prices['datetimes']).tz_localize(None)\n", " all_prices[(region,name)] = pd.DataFrame(as_prices['prices'],index=tdom,columns=[name])\n", " return pd.concat(all_prices,axis=1).droplevel(1,axis=1)" ] }, { "cell_type": "markdown", "id": "52c1645f-a643-48c7-b476-5df88492c95e", "metadata": {}, "source": [ "## Pull All Services & Single Region" ] }, { "cell_type": "code", "execution_count": 4, "id": "1d8675e4-bfd2-42f5-8fe8-bbc2aa22123c", "metadata": {}, "outputs": [], "source": [ "services = {\n", " 'reg_up':AncillaryService.REGULATION_UP,\n", " 'reg_down':AncillaryService.REGULATION_DOWN,\n", " 'reserves':AncillaryService.RESERVES,\n", "}\n", "regions = [\n", " 'SP15',\n", "]" ] }, { "cell_type": "code", "execution_count": 5, "id": "1201a1b5-2546-4706-84bc-f215778289ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SP15 reg_up\n", "SP15 reg_down\n", "SP15 reserves\n" ] } ], "source": [ "as_prices = as_pull(services,regions,2019,2023)\n", "as_prices = as_prices.droplevel(0,axis=1)" ] }, { "cell_type": "code", "execution_count": 6, "id": "04ad1612-c4b9-4d87-9807-122139e2bb0d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
reg_upreg_downreserves
2019-01-01 00:00:008.1715.291.00
2019-01-01 01:00:001.661.011.00
2019-01-01 02:00:001.591.010.25
2019-01-01 03:00:001.291.010.25
2019-01-01 04:00:007.421.390.25
\n", "
" ], "text/plain": [ " reg_up reg_down reserves\n", "2019-01-01 00:00:00 8.17 15.29 1.00\n", "2019-01-01 01:00:00 1.66 1.01 1.00\n", "2019-01-01 02:00:00 1.59 1.01 0.25\n", "2019-01-01 03:00:00 1.29 1.01 0.25\n", "2019-01-01 04:00:00 7.42 1.39 0.25" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "as_prices.head()" ] }, { "cell_type": "code", "execution_count": 24, "id": "c468c986-a94f-4bd1-8212-1f4743a6ec05", "metadata": {}, "outputs": [], "source": [ "as_prices.to_csv('example_sp15_ancillary_prices.csv')" ] }, { "cell_type": "markdown", "id": "d27cb795-0123-4349-943f-4fa43f03520c", "metadata": {}, "source": [ "## Pull All Services & Multiple Regions" ] }, { "cell_type": "code", "execution_count": 7, "id": "26d330d4-bc8f-45ed-a1bb-9d901e2d249a", "metadata": {}, "outputs": [], "source": [ "services = {\n", " 'reg_up':AncillaryService.REGULATION_UP,\n", " 'reg_down':AncillaryService.REGULATION_DOWN,\n", " 'reserves':AncillaryService.RESERVES,\n", "}\n", "regions = ['SP15','NP15']" ] }, { "cell_type": "code", "execution_count": 8, "id": "648e2511-9312-403d-aa7d-8a40d1ef74ad", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SP15 reg_up\n", "SP15 reg_down\n", "SP15 reserves\n", "NP15 reg_up\n", "NP15 reg_down\n", "NP15 reserves\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SP15NP15
reg_upreg_downreservesreg_upreg_downreserves
2021-01-01 00:00:001.6311.881.634.233.001.25
2021-01-01 01:00:001.6313.931.634.232.701.25
2021-01-01 02:00:001.6310.581.631.653.501.25
2021-01-01 03:00:001.6310.661.631.653.901.25
2021-01-01 04:00:001.6310.151.631.663.301.25
.....................
2021-12-31 19:00:006.575.006.574.970.996.57
2021-12-31 20:00:006.465.136.466.464.876.46
2021-12-31 21:00:004.750.213.004.752.263.00
2021-12-31 22:00:005.154.005.000.401.995.00
2021-12-31 23:00:007.855.004.427.855.004.42
\n", "

8760 rows × 6 columns

\n", "
" ], "text/plain": [ " SP15 NP15 \n", " reg_up reg_down reserves reg_up reg_down reserves\n", "2021-01-01 00:00:00 1.63 11.88 1.63 4.23 3.00 1.25\n", "2021-01-01 01:00:00 1.63 13.93 1.63 4.23 2.70 1.25\n", "2021-01-01 02:00:00 1.63 10.58 1.63 1.65 3.50 1.25\n", "2021-01-01 03:00:00 1.63 10.66 1.63 1.65 3.90 1.25\n", "2021-01-01 04:00:00 1.63 10.15 1.63 1.66 3.30 1.25\n", "... ... ... ... ... ... ...\n", "2021-12-31 19:00:00 6.57 5.00 6.57 4.97 0.99 6.57\n", "2021-12-31 20:00:00 6.46 5.13 6.46 6.46 4.87 6.46\n", "2021-12-31 21:00:00 4.75 0.21 3.00 4.75 2.26 3.00\n", "2021-12-31 22:00:00 5.15 4.00 5.00 0.40 1.99 5.00\n", "2021-12-31 23:00:00 7.85 5.00 4.42 7.85 5.00 4.42\n", "\n", "[8760 rows x 6 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "as_prices2 = as_pull(services,regions,2021,2021)\n", "as_prices2" ] }, { "cell_type": "code", "execution_count": null, "id": "9f6f715c-5eac-48f1-97d2-dcb647336e6d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.14" } }, "nbformat": 4, "nbformat_minor": 5 }