Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new plot recipe that plots the RT prices in MWh #14

Open
rafaelamaribeiro opened this issue Jun 16, 2021 · 0 comments
Open

Create a new plot recipe that plots the RT prices in MWh #14

rafaelamaribeiro opened this issue Jun 16, 2021 · 0 comments
Labels
good first issue Good for newcomers

Comments

@rafaelamaribeiro
Copy link
Collaborator

rafaelamaribeiro commented Jun 16, 2021

The idea on this code is to make a graphic where the price for the RT is given as $/MWh and not as, for example, $/MW-5min (because on this example the RT prices are evaluated for 5 in 5 minutes). To do that, the idea is to sum all the evaluated prices for each hour and to plot it.

"""
plot_prices_RT(
market_simulator::MarketSimulator,
results::SimulationResults;
bus_names::AbstractArray=[])

Plot the simulation prices over the time period covered by the results. The bus_names
control which buses we want to include the plot. It evaluates the prices for a Real Time (RT)
example and sums the prices so that it is on $/MWh.
"""

@userplot plot_prices_RT
@recipe function f(p::plot_prices_RT; bus_names::AbstractArray=[])
    market_simulator, system_results, = p.args

    prices = evaluate_prices(market_simulator, system_results)

    values = select(prices, Not(:DateTime))
    n_prev, n_bus = size(values)

    intervals = get_time_series_params(market_simulator.system_rt).interval
    
    n_prev_hour = Int(60/intervals.value)
    n_days = Int(n_prev/n_prev_hour)
    
    names_bus = names(values)
    prices_rt = zeros(n_days,n_bus)

    i = 1
    while i < n_days
        for j in 1:(n_prev_hour):n_prev
            prices_hour = prices[prices[j,:DateTime] .<= prices.DateTime .< prices[j,:DateTime]+Hour(1), :]
            prices_hour = select(prices_hour, Not(:DateTime))
            prices_rt[i,:] = sum(Matrix(prices_hour), dims = 1)
            i = i + 1
        end
    end

    times = prices[1:n_prev_hour:n_prev, 1]
    
    dictionary = Dict()
    n_row, n_col = size(prices_rt)

    for price in 1:n_col
        if !haskey(dictionary, names_bus[price])
            dictionary[names_bus[price]] = prices_rt[:,price]
        else
            dictionary[names_bus[price]] = dictionary[names_bus[price]] + prices_rt[:,price]
        end
    end

    plot_data = DataFrame(dictionary)

    # select rows for the given bus names, default to all buses.
    if !isempty(bus_names)
        bus_names = String.(bus_names)
        @assert issubset(bus_names, names(plot_data))
        select!(plot_data, bus_names)
    end

    label --> reduce(hcat, names(plot_data))
    yguide --> "Prices (\$/MWh)"
    legend --> :outertopright
    seriestype --> :line
    xrotation --> 45

    for i in Base.axes(plot_data, 2)
        @series begin
            times, plot_data[:, i]
        end
    end
end

When it is called as plot_prices_RT(market_simulator, results; xtickfontsize=8, size=(800, 600)) it seems that it does not work because of the the extra arguments (xtickfontsize and size).
ERROR: got unsupported keyword arguments "xtickfontsize", "size"

When it is called as plot_prices_RT(market_simulator, results;) it still does not work.

For now, this graphic was made in the example file using the plot function.

@rafaelamaribeiro rafaelamaribeiro changed the title Create a new plot that plots the RT prices in MWh Create a new plot recipe that plots the RT prices in MWh Jun 18, 2021
@santosbruno85 santosbruno85 added the good first issue Good for newcomers label Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants