Composite Functions¶
The eptr2.composite module provides pre-built functions that combine multiple API calls for common analysis tasks.
Overview¶
Composite functions simplify data retrieval by:
- Combining multiple related API calls
- Merging and transforming data
- Handling missing data gracefully
- Providing consistent output formats
Import¶
from eptr2.composite import (
get_hourly_consumption_and_forecast_data,
get_hourly_price_and_cost_data,
get_hourly_production_data,
get_hourly_production_plan_data,
get_imbalance_data,
)
Function Reference¶
Consumption Functions¶
get_hourly_consumption_and_forecast_data
¶
get_hourly_consumption_and_forecast_data(start_date: str, end_date: str, eptr: EPTR2 | None = None, verbose: bool = False, include_contract_symbol: bool = False, **kwargs)
This composite function gets load plan, UECM (settlement consumption), real time and consumption data. If end date is after the last settlement data, UECM is filled with real time consumption under consumption column.
Source code in src/eptr2/composite/consumption.py
Price Functions¶
get_hourly_price_and_cost_data
¶
get_hourly_price_and_cost_data(start_date: str, end_date: str, eptr: EPTR2 | None = None, include_wap: bool = True, add_kupst_cost: bool = True, verbose: bool = False, include_contract_symbol: bool = True, timeout: int = 10, **kwargs)
This composite function gets price and imbalance (kupst included) cost data. Imbalance cost data consists of MCP (PTF), SMP (SMF), system direction (Enerji Açığı - up regulated, Energy Fazlası - down regulated, Dengede - Balanced), positive imbalance cost and negative imbalance cost.
Resulting columns are: - date: Datetime in ISO format and +03:00 timezone - mcp: Market Clearing Price (MCP/PTF) in TL (Turkish Lira) - smp: System Marginal Price (SMP/SMF) in TL (Turkish Lira) - wap: Weighted Average Price (WAP) in TL (Turkish Lira) - system_direction: System direction (Enerji Açığı - up regulated, Energy Fazlası - down regulated, Dengede - Balanced) - sd_sign: System direction sign (1 for Enerji Fazlası, -1 for Enerji Açığı, 0 for Dengede) - pos_imb_price: Positive imbalance price in TL (Turkish Lira) - neg_imb_price: Negative imbalance price in TL (Turkish Lira) (negative value) - pos_imb_cost: Positive imbalance cost in TL (Turkish Lira) (ptf - pos_imb_price) - neg_imb_cost: Negative imbalance cost in TL (Turkish Lira) (neg_imb_price - ptf)
Source code in src/eptr2/composite/price_and_cost.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
Production Functions¶
get_hourly_production_data
¶
get_hourly_production_data(start_date: str, end_date: str, eptr: EPTR2 | None = None, rt_pp_id: str | int | None = None, uevm_pp_id: str | int | None = None, verbose: bool = False, include_contract_symbol: bool = True, skip_uevm: bool = False, skip_rt: bool = False, **kwargs)
This composite function gets production data (Gerçek Zamanlı Üretim, UEVM) and merges them.
It is also possible to enter pp_id to get the production data for a specific production plan. Example ID values are given below.
rt_pp_id=641, ## ATATÜRK HES uevm_pp_id=142, ## ATATÜRK HES
Source code in src/eptr2/composite/production.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
Quick Reference¶
get_hourly_consumption_and_forecast_data¶
Combines load plan, UECM, and real-time consumption data.
from eptr2.composite import get_hourly_consumption_and_forecast_data
df = get_hourly_consumption_and_forecast_data(
start_date="2024-07-01",
end_date="2024-07-31",
verbose=True
)
Returns:
| Column | Type | Description |
|---|---|---|
dt |
datetime | Timestamp |
load_plan |
float | Load plan forecast (MWh) |
uecm |
float | Settlement consumption (MWh) |
rt_cons |
float | Real-time consumption (MWh) |
consumption |
float | Best available consumption |
get_hourly_price_and_cost_data¶
Combines MCP, SMP, and imbalance price data.
from eptr2.composite import get_hourly_price_and_cost_data
df = get_hourly_price_and_cost_data(
start_date="2024-07-01",
end_date="2024-07-31"
)
Returns:
| Column | Type | Description |
|---|---|---|
dt |
datetime | Timestamp |
mcp |
float | Market Clearing Price (TL/MWh) |
smp |
float | System Marginal Price (TL/MWh) |
positive_imbalance |
float | Positive imbalance price |
negative_imbalance |
float | Negative imbalance price |
get_hourly_production_data¶
Retrieves hourly production data by source.
from eptr2.composite import get_hourly_production_data
df = get_hourly_production_data(
start_date="2024-07-01",
end_date="2024-07-31"
)
get_imbalance_data¶
Retrieves imbalance-related data for cost calculations.
from eptr2.composite import get_imbalance_data
df = get_imbalance_data(
start_date="2024-07-01",
end_date="2024-07-31"
)
Common Parameters¶
All composite functions share these parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
start_date |
str |
Required | Start date (YYYY-MM-DD) |
end_date |
str |
Required | End date (YYYY-MM-DD) |
eptr |
EPTR2 |
None |
EPTR2 instance (created if not provided) |
verbose |
bool |
False |
Print progress messages |
**kwargs |
- | - | Additional parameters |
Examples¶
Complete Analysis Pipeline¶
from eptr2 import EPTR2
from eptr2.composite import (
get_hourly_consumption_and_forecast_data,
get_hourly_price_and_cost_data
)
import pandas as pd
# Initialize once
eptr = EPTR2(use_dotenv=True, recycle_tgt=True)
# Get consumption data
consumption = get_hourly_consumption_and_forecast_data(
start_date="2024-07-01",
end_date="2024-07-31",
eptr=eptr,
verbose=True
)
# Get price data
prices = get_hourly_price_and_cost_data(
start_date="2024-07-01",
end_date="2024-07-31",
eptr=eptr
)
# Merge for analysis
analysis = pd.merge(consumption, prices, on='dt')
# Calculate costs
analysis['total_cost'] = analysis['consumption'] * analysis['mcp']
print(f"Total cost: {analysis['total_cost'].sum():,.2f} TL")
With Verbose Output¶
df = get_hourly_consumption_and_forecast_data(
start_date="2024-07-01",
end_date="2024-07-31",
verbose=True
)
Output:
Using Custom EPTR2 Instance¶
from eptr2 import EPTR2
from eptr2.composite import get_hourly_consumption_and_forecast_data
# Custom configuration
eptr = EPTR2(
use_dotenv=True,
recycle_tgt=True,
tgt_path="/custom/path"
)
df = get_hourly_consumption_and_forecast_data(
start_date="2024-07-01",
end_date="2024-07-31",
eptr=eptr
)