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

Fix handling of results with unknown timestamps #1008

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/core/results_by_time.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct ResultsByTime{T}
mutable struct ResultsByTime{T}
key::OptimizationContainerKey
data::SortedDict{Dates.DateTime, T}
resolution::Dates.Period
Expand Down Expand Up @@ -51,9 +51,16 @@ function _add_timestamps!(
timestamp::Dates.DateTime,
data,
)
time_col =
range(timestamp; length = get_num_rows(results, data), step = results.resolution)
DataFrames.insertcols!(df, 1, :DateTime => time_col)
if results.resolution != Dates.Period(Dates.Millisecond(0))
time_col =
range(
timestamp;
length = get_num_rows(results, data),
step = results.resolution,
)
DataFrames.insertcols!(df, 1, :DateTime => time_col)
end
return
end

function make_dataframe(
Expand Down
14 changes: 14 additions & 0 deletions src/simulation/decision_model_simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
Dict{OptimizationContainerKey, ResultsByTime{DenseAxisArray{Float64, 2}}}()
model_name = Symbol(get_model_name(sim_results))
resolution = get_resolution(sim_results)
horizon = get_forecast_horizon(sim_results)

for key in container_keys
results_by_time = ResultsByTime(
Expand All @@ -146,11 +147,24 @@
resolution,
get_column_names(store, DecisionModelIndexType, model_name, key),
)
array_size::Union{Nothing, Tuple{Int, Int}} = nothing
for ts in timestamps
array = read_result(DenseAxisArray, store, model_name, key, ts)
if isnothing(array_size)
array_size = size(array)
elseif size(array) != array_size
error(

Check warning on line 156 in src/simulation/decision_model_simulation_results.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/decision_model_simulation_results.jl#L156

Added line #L156 was not covered by tests
"Arrays for $(encode_key_as_string(key)) at different timestamps have different sizes",
)
end
if convert_result_to_natural_units(key)
array.data .*= base_power
end
if array_size[2] != horizon
@warn "$(encode_key_as_string(key)) has a different horizon than the " *

Check warning on line 164 in src/simulation/decision_model_simulation_results.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/decision_model_simulation_results.jl#L164

Added line #L164 was not covered by tests
"problem specification. Can't assign timestamps to the resulting DataFrame."
results_by_time.resolution = Dates.Period(Dates.Millisecond(0))

Check warning on line 166 in src/simulation/decision_model_simulation_results.jl

View check run for this annotation

Codecov / codecov/patch

src/simulation/decision_model_simulation_results.jl#L166

Added line #L166 was not covered by tests
end
results_by_time[ts] = array
end
results_by_key[key] = results_by_time
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PowerSimulations = "e690365d-45e2-57bb-ac84-44ba829e73c4"
PowerSystemCaseBuilder = "f00506e0-b84f-492a-93c2-c0a9afc4364e"
PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
Loading