Skip to content

Commit

Permalink
Fix allowing timeframe and partitions tables to be missing (#674) (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira authored Jun 27, 2024
1 parent b27b7ca commit 88f2d7e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
9 changes: 7 additions & 2 deletions docs/src/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ The meaning of `Missing` data depends on the parameter, for instance:

- `investment_limit`: There is no investment limit.

#### [`assets-timeframe-profiles.csv` and `assets-profiles.csv`] (@id assets-profiles-definition)
#### [`assets-profiles.csv`] (@id assets-profiles-definition)

These files contain information about assets and their associated profiles. Each row lists an asset, the type of profile (e.g., availability, demand, maximum or minimum storage level), and the profile's name. The timeframe profiles are used in the [inter-temporal constraints](@ref concepts-summary), whereas the representative periods profiles are used in the [intra-temporal constraints](@ref concepts-summary).
These files contain information about assets and their associated profiles. Each row lists an asset, the type of profile (e.g., availability, demand, maximum or minimum storage level), and the profile's name.
These profiles are used in the [intra-temporal constraints](@ref concepts-summary).

#### [`flows-profiles.csv`](@id flows-profiles-definition)

Expand All @@ -97,6 +98,10 @@ The `profile_name` is a unique identifier, the `period` and `value` define the p

The profiles are linked to assets and flows in the files [`assets-profiles`](@ref assets-profiles-definition), [`assets-timeframe-profiles`](@ref assets-profiles-definition), and [`flows-profiles`](@ref flows-profiles-definition).

#### `assets-timeframe-profiles.csv`

Like the [`assets-profiles.csv`](@ref assets-profiles-definition), but for the [inter-temporal constraints](@ref concepts-summary).

#### `profiles-timeframe.csv` (optional)

Define all the profiles for the `timeframe`.
Expand Down
4 changes: 2 additions & 2 deletions src/input-schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ const schema_per_file = OrderedDict(
"flows_data" => schemas.flows.data,
"flows_profiles" => schemas.flows.profiles_reference,
"flows_rep_periods_partitions" => schemas.flows.rep_periods_partition,
"profiles_timeframe_<type>" => schemas.timeframe.profiles_data,
"profiles_rep_periods_<type>" => schemas.rep_periods.profiles_data,
"profiles_timeframe" => schemas.timeframe.profiles_data,
"profiles_rep_periods" => schemas.rep_periods.profiles_data,
"rep_periods_data" => schemas.rep_periods.data,
"rep_periods_mapping" => schemas.rep_periods.mapping,
)
21 changes: 8 additions & 13 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ The following tables are expected to exist in the DB.
_ `flows_data`: Following the schema `schemas.flows.data`.
_ `flows_profiles`: Following the schema `schemas.flows.profiles_reference`.
_ `flows_rep_periods_partitions`: Following the schema `schemas.flows.rep_periods_partition`.
_ `profiles_timeframe_<type>`: Following the schema `schemas.timeframe.profiles_data`.
_ `profiles_rep_periods_<type>`: Following the schema `schemas.rep_periods.profiles_data`.
_ `profiles_timeframe`: Following the schema `schemas.timeframe.profiles_data`.
_ `profiles_rep_periods`: Following the schema `schemas.rep_periods.profiles_data`.
_ `rep_periods_data`: Following the schema `schemas.rep_periods.data`.
_ `rep_periods_mapping`: Following the schema `schemas.rep_periods.mapping`.
"""
Expand Down Expand Up @@ -127,11 +127,12 @@ function create_input_dataframes(connection::DuckDB.DB; strict = false)
read_table("assets_$(period_type)_partitions"; allow_missing_table = true) for
period_type in PERIOD_TYPES
)
df_flows_partitions = read_table("flows_rep_periods_partitions")
df_flows_partitions = read_table("flows_rep_periods_partitions"; allow_missing_table = true)

tables_list = DBInterface.execute(connection, "SHOW TABLES")
dfs_profiles =
Dict(period_type => read_table("profiles_$period_type") for period_type in PERIOD_TYPES)
dfs_profiles = Dict(
:rep_periods => read_table("profiles_rep_periods"),
:timeframe => read_table("profiles_timeframe"; allow_missing_table = true),
)

# Error if partition data is missing assets (if strict)
if strict
Expand Down Expand Up @@ -347,13 +348,7 @@ function get_schema(tablename)
if haskey(schema_per_file, tablename)
return schema_per_file[tablename]
else
if startswith("profiles_timeframe")(tablename)
return schema_per_file["profiles_timeframe_<type>"]
elseif startswith("profiles_rep_periods")(tablename)
return schema_per_file["profiles_rep_periods_<type>"]
else
error("No implicit schema for table named $tablename")
end
error("No implicit schema for table named $tablename")
end
end

Expand Down
2 changes: 0 additions & 2 deletions test/inputs/Tiny/assets-rep-periods-partitions.csv

This file was deleted.

2 changes: 0 additions & 2 deletions test/inputs/Tiny/flows-rep-periods-partitions.csv

This file was deleted.

2 changes: 0 additions & 2 deletions test/inputs/Tiny/profiles-timeframe.csv

This file was deleted.

0 comments on commit 88f2d7e

Please sign in to comment.