-
Notifications
You must be signed in to change notification settings - Fork 70
/
cost_function_timeseries.jl
201 lines (186 loc) · 6.14 KB
/
cost_function_timeseries.jl
1
2
3
4
5
6
7
8
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
"""
Returns variable cost bids time-series data.
# Arguments
- `ts::IS.TimeSeriesData`:TimeSeriesData
- `component::Component`: Component
- `start_time::Union{Nothing, Dates.DateTime} = nothing`: Time when the time-series data starts
- `len::Union{Nothing, Int} = nothing`: Length of the time-series to be returned
"""
function get_variable_cost(
ts::IS.TimeSeriesData,
component::Component,
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
if start_time === nothing
start_time = IS.get_initial_timestamp(ts)
end
data = IS.get_time_series_array(component, ts, start_time; len = len)
time_stamps = TimeSeries.timestamp(data)
return TimeSeries.TimeArray(time_stamps, map(VariableCost, TimeSeries.values(data)))
end
"""
Returns variable cost bids time-series data for MarketBidCost.
# Arguments
- `device::StaticInjection`: Static injection device
- `cost::MarketBidCost`: Operations Cost
- `start_time::Union{Nothing, Dates.DateTime} = nothing`: Time when the time-series data starts
- `len::Union{Nothing, Int} = nothing`: Length of the time-series to be returned
"""
function get_variable_cost(
device::StaticInjection,
cost::OperationalCost;
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
time_series_key = get_variable(cost)
if isnothing(time_series_key)
error(
"Cost component has a `nothing` stored in field `variable`, Please use `set_variable_cost!` to add variable cost forecast.",
)
end
raw_data = IS.get_time_series_by_key(
time_series_key,
device;
start_time = start_time,
len = len,
count = 1,
)
cost = get_variable_cost(raw_data, device, start_time, len)
return cost
end
"""
Returns variable cost time-series data for a ReserveDemandCurve.
# Arguments
- `service::ReserveDemandCurve`: ReserveDemandCurve
- `start_time::Union{Nothing, Dates.DateTime} = nothing`: Time when the time-series data starts
- `len::Union{Nothing, Int} = nothing`: Length of the time-series to be returned
"""
function get_variable_cost(
service::ReserveDemandCurve;
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
time_series_key = get_variable(service)
if isnothing(time_series_key)
error(
"Cost component has a `nothing` stored in field `variable`, Please use `set_variable_cost!` to add variable cost forecast.",
)
end
raw_data = IS.get_time_series_by_key(
time_series_key,
service;
start_time = start_time,
len = len,
count = 1,
)
cost = get_variable_cost(raw_data, service, start_time, len)
return cost
end
"""
Returns service bids time-series data for a device that has MarketBidCost.
# Arguments
- `sys::System`: PowerSystem System
- `cost::MarketBidCost`: Operations Cost
- `service::Service`: Service
- `start_time::Union{Nothing, Dates.DateTime} = nothing`: Time when the time-series data starts
- `len::Union{Nothing, Int} = nothing`: Length of the time-series to be returned
"""
function get_services_bid(
device::StaticInjection,
cost::MarketBidCost,
service::Service;
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
variable_ts_key = get_variable(cost)
service_ts_key = IS.TimeSeriesKey(variable_ts_key.time_series_type, get_name(service))
raw_data = IS.get_time_series_by_key(
service_ts_key,
device;
start_time = start_time,
len = len,
count = 1,
)
cost = get_variable_cost(raw_data, device, start_time, len)
return cost
end
"""
Adds energy market bids time-series to the MarketBidCost.
# Arguments
- `sys::System`: PowerSystem System
- `component::StaticInjection`: Static injection device
- `time_series_data::IS.TimeSeriesData`: TimeSeriesData
"""
function set_variable_cost!(
sys::System,
component::StaticInjection,
time_series_data::IS.TimeSeriesData,
)
add_time_series!(sys, component, time_series_data)
key = IS.TimeSeriesKey(time_series_data)
market_bid_cost = get_operation_cost(component)
set_variable!(market_bid_cost, key)
return
end
"""
Adds energy market bids time-series to the ReserveDemandCurve.
# Arguments
- `sys::System`: PowerSystem System
- `component::StaticInjection`: Static injection device
- `time_series_data::IS.TimeSeriesData`: TimeSeriesData
"""
function set_variable_cost!(
sys::System,
component::ReserveDemandCurve,
time_series_data::IS.TimeSeriesData,
)
add_time_series!(sys, component, time_series_data)
key = IS.TimeSeriesKey(time_series_data)
set_variable!(component, key)
return
end
"""
Adds service bids time-series data to the MarketBidCost.
# Arguments
- `sys::System`: PowerSystem System
- `component::StaticInjection`: Static injection device
- `service::Service,`: Service for which the device is eligible to contribute
- `time_series_data::IS.TimeSeriesData`: TimeSeriesData
"""
function set_service_bid!(
sys::System,
component::StaticInjection,
service::Service,
time_series_data::IS.TimeSeriesData,
)
if get_name(time_series_data) != get_name(service)
error(
"Name provided in the TimeSeries Data $(get_name(time_series_data)), doesn't match the Service $(get_name(service)).",
)
end
verify_device_eligibility(sys, component, service)
add_time_series!(sys, component, time_series_data)
ancillary_services = get_ancillary_services(get_operation_cost(component))
push!(ancillary_services, service)
return
end
"""
Validates if a device is eligible to contribute to a service.
# Arguments
- `sys::System`: PowerSystem System
- `component::StaticInjection`: Static injection device
- `service::Service,`: Service for which the device is eligible to contribute
"""
function verify_device_eligibility(
sys::System,
component::StaticInjection,
service::Service,
)
if !has_service(component, service)
error(
"Device $(get_name(component)) isn't eligible to contribute to service $(get_name(service)).",
)
end
return
end