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

Add explicit asset timeframe partitions #1012

Merged
merged 4 commits into from
Feb 5, 2025
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
7 changes: 1 addition & 6 deletions docs/src/30-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,7 @@ unstacked_map[!,["k=1", "k=2", "k=3"]] = convert.(Float64, unstacked_map[!,["k=1
unstacked_map # hide
```

The file `assets-timeframe-partitions` has the information on how often we want to evaluate the inter-temporal constraints that combine the information of the representative periods. In this example, we define a uniform distribution of one period, meaning that we will check the inter-storage level every day of the week timeframe.

```@example seasonal-storage
phs_partitions_file = "../../test/inputs/Storage/assets-timeframe-partitions.csv" # hide
phs_partitions = CSV.read(phs_partitions_file, DataFrame, header = 1) # hide
```
The file `assets-timeframe-partitions` has the information on how often we want to evaluate the inter-temporal constraints that combine the information of the representative periods. In this example, the file is missing in the folder, meaning that the default of a `uniform` distribution of one period will be use in the model, see [model parameters](@ref schemas) section. This assumption implies that the model will check the inter-storage level every day of the week timeframe.

!!! info
For the sake of simplicity, we show how using three representative days can recover part of the chronological information of one week. The same method can be applied to more representative periods to analyze the seasonality across a year or longer timeframe.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/50-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ The optimization model parameters with the input data must follow the schema bel

The schemas can be accessed at any time after loading the package by typing `TulipaEnergyModel.schema_per_table_name` in the Julia console. Here is the complete list of model parameters in the schemas per table (or CSV file):

!!! info "Optional tables/files and their defaults"
The following tables/files are allowed to be missing: "assets\_rep\_periods\_partitions", "assets\_timeframe\_partitions", "assets\_timeframe\_profiles", "flows\_rep\_periods\_partitions", "group\_asset", "profiles\_timeframe".
- For the partitions tables/files, the default value are `specification = uniform` and `partition = 1` for each asset/flow and year
- For the profiles tables/files, the default value is a flat profile of value 1.0 p.u.
- If no group table/file is available there will be no group constraints in the model

```@eval
using Markdown, TulipaEnergyModel

Expand Down
21 changes: 20 additions & 1 deletion src/tmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ function tmp_create_partition_tables(connection)
end
DuckDB.close(appender)

DBInterface.execute(
connection,
"CREATE OR REPLACE TABLE explicit_assets_timeframe_partitions AS
SELECT
asset.asset,
asset_commission.commission_year AS year,
COALESCE(atp.specification, 'uniform') AS specification,
COALESCE(atp.partition, '1') AS partition,
FROM asset AS asset
LEFT JOIN asset_commission
ON asset.asset = asset_commission.asset
LEFT JOIN assets_timeframe_partitions AS atp
ON asset.asset = atp.asset
AND asset_commission.commission_year = atp.year
WHERE
asset.is_seasonal
",
)

DBInterface.execute(
connection,
"CREATE OR REPLACE TABLE asset_timeframe_time_resolution(
Expand All @@ -205,7 +224,7 @@ function tmp_create_partition_tables(connection)
for row in DuckDB.query(
connection,
"SELECT asset, sub.year, specification, partition, num_periods AS num_periods
FROM assets_timeframe_partitions AS main
FROM explicit_assets_timeframe_partitions AS main
LEFT JOIN (
SELECT year, MAX(period) AS num_periods
FROM timeframe_data
Expand Down
2 changes: 0 additions & 2 deletions test/inputs/Storage/assets-timeframe-partitions.csv

This file was deleted.

Loading