Skip to content

Commit 0b52f84

Browse files
authored
Merge pull request #622 from EnergySystemsModellingLab/input_docs
Slightly reformat the input data documentation
2 parents 7827181 + 94db7ef commit 0b52f84

19 files changed

Lines changed: 216 additions & 210 deletions

.vscode/extensions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"editorconfig.editorconfig",
66
"esbenp.prettier-vscode",
77
"davidanson.vscode-markdownlint",
8-
"samuelcolvin.jinjahtml"
8+
"samuelcolvin.jinjahtml",
9+
"ms-python.python",
10+
"charliermarsh.ruff"
911
]
1012
}

docs/generate_input_format_doc.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@
2121
}
2222

2323

24-
@dataclass
25-
class Notes:
26-
description: str | None
27-
table: str | None
28-
29-
3024
@dataclass
3125
class File:
3226
name: str
3327
description: str
3428
table: str
35-
notes: Notes | None
29+
notes: str | None
3630

3731

3832
@dataclass
@@ -50,28 +44,28 @@ def generate_markdown() -> str:
5044

5145
def load_sections() -> Iterable[Section]:
5246
for title, patterns in _FILE_ORDER.items():
47+
paths = []
5348
for pattern in patterns:
54-
paths = map(str, _SCHEMA_DIR.glob(f"{pattern}.yaml"))
55-
files = (load_file(Path(path)) for path in sorted(paths))
56-
yield Section(title, files)
49+
paths.extend(map(str, _SCHEMA_DIR.glob(f"{pattern}.yaml")))
50+
files = (load_file(Path(path)) for path in sorted(paths))
51+
yield Section(title, files)
5752

5853

5954
def load_file(path: Path) -> File:
6055
with path.open() as f:
6156
data = yaml.safe_load(f)
6257

6358
try:
64-
table, notes_table = fields2table(data["fields"])
59+
table = fields2table(data["fields"])
6560
except KeyError:
6661
print(f"MISSING VALUE IN {path}")
6762
raise
6863

6964
name = f"{path.stem}.csv"
70-
title = add_full_stop(data["title"])
71-
if desc := data.get("description", None):
72-
desc = add_full_stop(desc)
73-
notes = Notes(desc, notes_table) if desc or notes_table else None
74-
return File(name, title, table, notes)
65+
desc = add_full_stop(data["description"])
66+
if note := data.get("notes", None):
67+
note = format_notes(note)
68+
return File(name, desc, table, note)
7569

7670

7771
def add_full_stop(s: str) -> str:
@@ -84,28 +78,28 @@ def add_full_stop(s: str) -> str:
8478

8579
def fields2table(fields: list[dict[str, str]]) -> tuple[str, str | None]:
8680
data = []
87-
notes = []
8881
for f in fields:
89-
row = {"Field": f"`{f['name']}`", "Description": f["title"]}
90-
data.append(row)
91-
92-
if desc := f.get("description", ""):
93-
# MarkdownTable can't handle newlines, so replace with HTML equivalent
94-
desc = desc.replace("\n\n", "<br /><br />").replace("\n", " ")
95-
row = {"Field": f"`{f['name']}`", "Notes": desc}
96-
notes.append(row)
97-
98-
data = [
99-
{
82+
# MarkdownTable can't handle newlines, so replace with HTML equivalent
83+
notes = f.get("notes", "")
84+
notes = notes.replace("\n\n", "<br /><br />").replace("\n", " ")
85+
row = {
10086
"Field": f"`{f['name']}`",
101-
"Description": f["title"],
87+
"Description": f["description"],
88+
"Notes": notes,
10289
}
103-
for f in fields
104-
]
105-
90+
data.append(row)
10691
table = str(MarkdownTable.from_dicts(data))
107-
notes_table = str(MarkdownTable.from_dicts(notes)) if notes else None
108-
return table, notes_table
92+
return table
93+
94+
95+
def format_notes(notes) -> str:
96+
if isinstance(notes, list):
97+
items = [add_full_stop(item) for item in notes]
98+
elif isinstance(notes, str):
99+
items = [add_full_stop(notes)]
100+
else:
101+
return ""
102+
return "\n".join(f"- {item}" for item in items)
109103

110104

111105
if __name__ == "__main__":

docs/input_format.md.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ This file contains information about the input file format for MUSE 2.0.
2626
(such as a requirement that the value is >=0 etc.). -#}
2727
{%- if file.notes %}
2828
#### Notes
29-
{% if file.notes.description %}
30-
{{ file.notes.description }}{% endif %}
31-
{% if file.notes.table %}
32-
{{ file.notes.table }}{% endif -%}
29+
30+
{{ file.notes }}
3331
{%- endif %}
32+
3433
{% endfor -%}
34+
3535
{% endfor %}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
title: Commodity demand portions for agents
21
description: |
32
Portions of commodity demand for which agents are responsible.
43
5-
If an entry is specified for one agent and commodity, there must be entries covering all milestone
6-
years. For each agent listed in this file, the total portions for each region/commodity/year
7-
combination must sum to one. In addition, there must be entries for every SVD and SED commodity
8-
for all regions and milestone years.
4+
notes:
5+
- If an entry is specified for one agent and commodity, there must be entries covering all
6+
milestone years.
7+
- For each agent listed in this file, the total portions for each region/commodity/year
8+
combination must sum to one.
9+
- In addition, there must be entries for every SVD and SED commodity for all regions and
10+
milestone years.
911

1012
fields:
1113
- name: agent_id
1214
type: string
13-
title: The agent to apply these values to
15+
description: The agent to apply these values to
1416
- name: commodity_id
1517
type: string
16-
title: The commodity for which the agent is responsible
18+
description: The commodity for which the agent is responsible
1719
- name: years
1820
type: string
19-
title: The year(s) to which this entry applies
20-
description: One or more milestone years separated by semicolons or `all`
21+
description: The year(s) to which this entry applies
22+
notes: One or more milestone years separated by semicolons or `all`
2123
- name: commodity_portion
2224
type: number
23-
title: Portion of commodity demand
24-
description: Value must be >0 and <=1. The portion applies only to the specified years.
25+
description: Portion of commodity demand
26+
notes: Value must be >0 and <=1. The portion applies only to the specified years.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
title: Agent cost limits
21
description: |
32
Limits on expenditure for agents.
43
5-
If cost limits are provided for an agent, they must be present for all years.
4+
notes:
5+
- If cost limits are provided for an agent, they must be present for all years.
66

77
fields:
88
- name: agent_id
99
type: string
10-
title: The agent to apply these values to
10+
description: The agent to apply these values to
1111
- name: years
1212
type: string
13-
title: The year(s) to which this entry applies
14-
description: One or more milestone years separated by semicolons or `all`
13+
description: The year(s) to which this entry applies
14+
notes: One or more milestone years separated by semicolons or `all`
1515
- name: capex_limit
1616
type: number
17-
title: Maximum capital cost the agent will pay
18-
description: Must be >0. Optional (defaults to infinity).
17+
description: Maximum capital cost the agent will pay
18+
notes: Must be >0. Optional (defaults to infinity).
1919
- name: annual_cost_limit
2020
type: number
21-
title: Maximum annual operating cost
22-
description: |
21+
description: Maximum annual operating cost
22+
notes: |
2323
The maximum annual operating cost (fuel plus variable operating cost etc.) that the agent will
2424
pay. Must be >0. Optional (defaults to infinity).
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
title: Agent objectives
21
description: |
32
Describes the agents' objectives.
43
5-
Every agent must have one objective for each milestone year. If the weighted sum decision rule is
6-
in use, the `decision_weight` value must be provided, otherwise it must be omitted. If the lexico
7-
decision rule is in use, the `decision_lexico_order` value must be provided, otherwise it must be
8-
omitted.
4+
notes:
5+
- Every agent must have one objective for each milestone year.
6+
- If the weighted sum decision rule is in use, the `decision_weight` value must be provided,
7+
otherwise it must be omitted.
8+
- If the lexico decision rule is in use, the `decision_lexico_order` value must be provided,
9+
otherwise it must be omitted.
910

1011
fields:
1112
- name: agent_id
1213
type: string
13-
title: An agent ID
14+
description: An agent ID
1415
- name: years
1516
type: string
16-
title: The year(s) to which this entry applies
17-
description: One or more milestone years separated by semicolons or `all`
17+
description: The year(s) to which this entry applies
18+
notes: One or more milestone years separated by semicolons or `all`
1819
- name: objective_type
1920
type: string
20-
title: The type of objective
21-
description: Currently only `lcox` is supported
21+
description: The type of objective
22+
notes: Currently only `lcox` is supported
2223
- name: decision_weight
2324
type: number
24-
title: Weight for weighted sum decision rule
25-
description: Currently unused
25+
description: Weight for weighted sum decision rule
26+
notes: Currently unused
2627
- name: decision_lexico_order
2728
type: integer
28-
title: Order in which to consider objectives for lexico decision rule
29-
description: Currently unused
29+
description: Order in which to consider objectives for lexico decision rule
30+
notes: Currently unused
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
title: Agent search space
21
description: |
32
Defines the processes in which an agent will invest for given parameters.
43
5-
If entries are missing for any combination of agent, commodity or milestone year, then it is
6-
assumed that all processes can be considered in this case.
4+
notes:
5+
- If entries are missing for any combination of agent, commodity or milestone year, then it is
6+
assumed that all processes can be considered in this case.
77

88
fields:
99
- name: agent_id
1010
type: string
11-
title: An agent ID
11+
description: An agent ID
1212
- name: commodity_id
1313
type: string
14-
title: The commodity to which this entry applies
14+
description: The commodity to which this entry applies
1515
- name: years
1616
type: string
17-
title: The year(s) to which this entry applies
18-
description: One or more milestone years separated by semicolons or `all`
17+
description: The year(s) to which this entry applies
18+
notes: One or more milestone years separated by semicolons or `all`
1919
- name: search_space
2020
type: string
21-
title: The processes in which this agent will invest
22-
description: |
21+
description: The processes in which this agent will invest
22+
notes: |
2323
One or more process IDs separated by semicolons. If this field is empty or `all`, all
2424
processes will be considered.

schemas/input/agents.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
title: Main agents file
21
description: Describes agents in the system
32
fields:
43
- name: id
54
type: string
6-
title: A unique identifier for an agent
5+
description: A unique identifier for an agent
76
- name: description
87
type: string
9-
title: A human-readable label for the agent
8+
description: A human-readable label for the agent
109
- name: regions
1110
type: string
12-
title: The region(s) in which the agent operates
13-
description: One or more region IDs, separated by semicolons or the string `all`
11+
description: The region(s) in which the agent operates
12+
notes: One or more region IDs, separated by semicolons or the string `all`
1413
- name: decision_rule
1514
type: string
16-
title: The decision rule applied to objectives
17-
description: Currently the only supported rule is `simple`
15+
description: The decision rule applied to objectives
16+
notes: Currently the only supported rule is `simple`
1817
- name: decision_lexico_tolerance
1918
type: number
20-
title: Tolerance for `lexico` decision rule
21-
description: Currently unused
19+
description: Tolerance for `lexico` decision rule
20+
notes: Currently unused

schemas/input/assets.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
title: Main assets file
21
description: Defines assets in the system
32

43
fields:
54
- name: process_id
65
type: string
7-
title: The process of which this asset is an instance
6+
description: The process of which this asset is an instance
87
- name: region_id
98
type: string
10-
title: The region in which this agent operates
9+
description: The region in which this agent operates
1110
- name: agent_id
1211
type: string
13-
title: The agent to which this asset belongs
12+
description: The agent to which this asset belongs
1413
- name: capacity
1514
type: number
16-
title: The capacity of the asset
17-
description: Must be >0
15+
description: The capacity of the asset
16+
notes: Must be >0
1817
- name: commission_year
1918
type: integer
20-
title: The year in which to commission this asset
21-
description: |
19+
description: The year in which to commission this asset
20+
notes: |
2221
This value can be any integer >=0. If it is before the start of the simulation, it will
2322
already be commissioned in the first year and if it after the end of the simulation then it
2423
will never be commissioned.

schemas/input/commodities.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
title: Main commodities file
21
description: |
3-
Every SED (supply equals demand) commodity must have both producer and consumer processes for
4-
every region and milestone year. Every SVD (service demand) commodity must have a producer for
5-
every region and milestone year.
2+
Describes commodities in the system.
3+
4+
notes:
5+
- Every SED (supply equals demand) commodity must have both producer and consumer processes for
6+
every region and milestone year.
7+
- Every SVD (service demand) commodity must have a producer for every region and milestone year.
68

79
fields:
810
- name: id
911
type: string
10-
title: A unique identifier for the commodity
12+
description: A unique identifier for the commodity
1113
- name: description
1214
type: string
13-
title: A human-readable label for the commodity
15+
description: A human-readable label for the commodity
1416
- name: type
1517
type: string
16-
title: The type of commodity
17-
description: |
18+
description: The type of commodity
19+
notes: |
1820
Must be one of `svd` (service demand), `sed` (supply equals demand), `inc` (input
1921
commodity) or `ouc` (output commodity)
2022
- name: time_slice_level
2123
type: string
22-
title: The time slice level at which constraints for this commodity are applied
23-
description: |
24+
description: The time slice level at which constraints for this commodity are applied
25+
notes: |
2426
Must be one of `annual` (whole year), `season` (whole season) or `daynight` (a particular time
2527
of day)

0 commit comments

Comments
 (0)