Skip to content

Commit

Permalink
Renovate market bid curve time series interface
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed May 9, 2024
1 parent 23e46fd commit 0d87770
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export OperationalCost, MarketBidCost, LoadCost, StorageCost
export HydroGenerationCost, RenewableGenerationCost, ThermalGenerationCost
export get_function_data, get_initial_input, get_value_curve, get_power_units
export get_fuel_cost, set_fuel_cost!
export is_market_bid_curve, make_market_bid_curve

export Generator
export HydroGen
Expand Down
12 changes: 4 additions & 8 deletions src/models/cost_function_timeseries.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# MarketBidCost has two variable costs, here we mean the incremental one
get_generation_variable_cost(cost::MarketBidCost) = get_incremental_offer_curves(cost)
# get_generation_variable_cost(cost::OperationalCost) = get_variable_cost(cost)

function _validate_time_series_variable_cost(
time_series_data::IS.TimeSeriesData;
desired_type::Type = PiecewiseStepData,
Expand Down Expand Up @@ -39,7 +35,7 @@ function get_variable_cost(
end
data = IS.get_time_series_array(component, ts, start_time; len = len)
time_stamps = TimeSeries.timestamp(data)
return data
return TimeSeries.TimeArray(time_stamps, map(make_market_bid_curve, TimeSeries.values(data)))
end

"""
Expand All @@ -53,11 +49,11 @@ Returns variable cost bids time-series data for MarketBidCost.
"""
function get_variable_cost(
device::StaticInjection,
cost::OperationalCost;
cost::MarketBidCost;
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
time_series_key = get_generation_variable_cost(cost)
time_series_key = get_incremental_offer_curves(cost)
if isnothing(time_series_key)
error(
"Cost component is empty, please use `set_variable_cost!` to add variable cost forecast.",
Expand Down Expand Up @@ -123,7 +119,7 @@ function get_services_bid(
start_time::Union{Nothing, Dates.DateTime} = nothing,
len::Union{Nothing, Int} = nothing,
)
variable_ts_key = get_generation_variable_cost(cost)
variable_ts_key = get_incremental_offer_curves(cost)
raw_data = get_time_series(
variable_ts_key.time_series_type,
device,
Expand Down
33 changes: 15 additions & 18 deletions test/test_cost_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,10 @@ end
end

test_costs = Dict(
QuadraticFunctionData =>
repeat([QuadraticFunctionData(999.0, 2.0, 1.0)], 24),
PiecewiseLinearData =>
repeat(
[PiecewiseStepData([1.0, 2.0, 3.0], [4.0, 6.0])],
24,
),
CostCurve{QuadraticCurve} =>
repeat([CostCurve(QuadraticCurve(999.0, 2.0, 1.0))], 24),
CostCurve{PiecewiseIncrementalCurve} =>
repeat([make_market_bid_curve([2.0, 3.0], [4.0, 6.0])], 24),
Float64 =>
collect(11.0:34.0),
)
Expand All @@ -163,12 +160,12 @@ test_costs = Dict(
horizon = 24
service_data = Dict(initial_time => rand(horizon))
data_quadratic =
SortedDict(initial_time => test_costs[QuadraticFunctionData])
SortedDict(initial_time => test_costs[CostCurve{QuadraticCurve}])
sys = PSB.build_system(PSITestSystems, "test_RTS_GMLC_sys")
generator = get_component(ThermalStandard, sys, "322_CT_6")
market_bid = MarketBidCost(nothing)
set_operation_cost!(generator, market_bid)
forecast = IS.Deterministic("variable_cost", data_quadratic, resolution)
forecast = IS.Deterministic("variable_cost", Dict(k => get_function_data.(v) for (k, v) in pairs(data_quadratic)), resolution)
@test_throws TypeError set_variable_cost!(sys, generator, forecast)
for s in generator.services
forecast = IS.Deterministic(get_name(s), service_data, resolution)
Expand All @@ -181,25 +178,25 @@ end
resolution = Dates.Hour(1)
name = "test"
horizon = 24
data_pwl = SortedDict(initial_time => test_costs[PiecewiseLinearData])
data_pwl = SortedDict(initial_time => test_costs[CostCurve{PiecewiseIncrementalCurve}])
service_data = data_pwl
sys = PSB.build_system(PSITestSystems, "test_RTS_GMLC_sys")
generator = get_component(ThermalStandard, sys, "322_CT_6")
market_bid = MarketBidCost(nothing)
set_operation_cost!(generator, market_bid)
forecast = IS.Deterministic("variable_cost", data_pwl, resolution)
forecast = IS.Deterministic("variable_cost", Dict(k => get_function_data.(v) for (k, v) in pairs(data_pwl)), resolution)
set_variable_cost!(sys, generator, forecast)
for s in generator.services
forecast = IS.Deterministic(get_name(s), service_data, resolution)
forecast = IS.Deterministic(get_name(s), Dict(k => get_function_data.(v) for (k, v) in pairs(service_data)), resolution)
set_service_bid!(sys, generator, s, forecast)
end

cost_forecast = get_variable_cost(generator, market_bid; start_time = initial_time)
@test first(TimeSeries.values(cost_forecast)) == first(data_pwl[initial_time])
@test isequal(first(TimeSeries.values(cost_forecast)), first(data_pwl[initial_time]))

for s in generator.services
service_cost = get_services_bid(generator, market_bid, s; start_time = initial_time)
@test first(TimeSeries.values(service_cost)) == first(service_data[initial_time])
@test isequal(first(TimeSeries.values(service_cost)), first(service_data[initial_time]))
end
end

Expand All @@ -215,15 +212,15 @@ end
other_time = initial_time + resolution
name = "test"
horizon = 24
data_pwl = SortedDict(initial_time => test_costs[PiecewiseLinearData],
other_time => test_costs[PiecewiseLinearData])
data_pwl = SortedDict(initial_time => test_costs[CostCurve{PiecewiseIncrementalCurve}],
other_time => test_costs[CostCurve{PiecewiseIncrementalCurve}])
sys = System(100.0)
reserve = ReserveDemandCurve{ReserveUp}(nothing)
add_component!(sys, reserve)
forecast = IS.Deterministic("variable_cost", data_pwl, resolution)
forecast = IS.Deterministic("variable_cost", Dict(k => get_function_data.(v) for (k, v) in pairs(data_pwl)), resolution)
set_variable_cost!(sys, reserve, forecast)
cost_forecast = get_variable_cost(reserve; start_time = initial_time)
@test first(TimeSeries.values(cost_forecast)) == first(data_pwl[initial_time])
@test isequal(first(TimeSeries.values(cost_forecast)), first(data_pwl[initial_time]))
end

@testset "Test fuel cost (scalar and time series)" begin
Expand Down

0 comments on commit 0d87770

Please sign in to comment.