Skip to content

Commit

Permalink
Move units_on from DF to DuckDB (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
clizbe authored Oct 29, 2024
1 parent 4287f3f commit 4d35a79
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/model-preparation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,29 @@ function construct_dataframes(
dataframes[:flows].index = 1:size(dataframes[:flows], 1)

# DataFrame to store the units_on variables
dataframes[:units_on] = DataFrame(
(
(
(asset = a, year = y, rep_period = rp, timesteps_block = timesteps_block) for
timesteps_block in graph[a].rep_periods_partitions[y][rp]
) for y in years for a in Auc[y], rp in RP[y] if get(graph[a].active, y, false)
) |> Iterators.flatten,
dataframes[:units_on] =
DuckDB.query(
connection,
"SELECT
atr.asset,
atr.year,
atr.rep_period,
atr.time_block_start,
atr.time_block_end
FROM asset_time_resolution AS atr
LEFT JOIN assets_data
ON atr.asset=assets_data.name
LEFT JOIN graph_assets_data
ON assets_data.name=graph_assets_data.name
WHERE graph_assets_data.type IN ('producer','conversion')
AND assets_data.unit_commitment=true",
) |> DataFrame

dataframes[:units_on].timesteps_block = map(
r -> r[1]:r[2],
zip(dataframes[:units_on].time_block_start, dataframes[:units_on].time_block_end),
)

dataframes[:units_on].index = 1:size(dataframes[:units_on], 1)

# Dataframe to store the storage level variable between (inter) representative period (e.g., seasonal storage)
Expand Down

0 comments on commit 4d35a79

Please sign in to comment.