Skip to content

Commit b3cc8ef

Browse files
committed
Minimal changes for #277
- Format docstring according to code style, rewrap. - Add type hints. - Ensure the module appears in the docs. - Add (incomplete) tests for all parts of the code.
1 parent b631b56 commit b3cc8ef

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

doc/api/tools.rst

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ General purpose modeling tools (:mod:`.tools`)
66
- Codes for retrieving data from specific data sources and adapting it for use with :mod:`message_ix_models`.
77
- Codes for modifying scenarios; although tools for building models should go in :mod:`message_ix_models.model`.
88

9+
.. currentmodule:: message_ix_models.tools
10+
911
On other pages:
1012

1113
- :doc:`tools-costs`
1214

15+
.. autosummary::
16+
:toctree: _autosummary
17+
:template: autosummary-module.rst
18+
:recursive:
19+
20+
res_marg
21+
1322
On this page:
1423

1524
.. contents::
1625
:local:
1726
:backlinks: none
1827

19-
.. currentmodule:: message_ix_models.tools
20-
21-
.. automodule:: message_ix_models.tools
22-
:members:
23-
2428
.. currentmodule:: message_ix_models.tools.exo_data
2529

2630
Exogenous data (:mod:`.tools.exo_data`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
from message_ix_models.tools.res_marg import main
4+
5+
6+
@pytest.mark.xfail(reason="Incomplete test")
7+
def test_cli() -> None:
8+
# TODO Complete
9+
assert False
10+
11+
12+
@pytest.mark.xfail(reason="Incomplete test")
13+
def test_main() -> None:
14+
# TODO Complete
15+
main()

message_ix_models/tools/res_marg.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1+
"""Update the reserve margin."""
2+
13
import argparse
4+
from typing import TYPE_CHECKING
5+
6+
if TYPE_CHECKING:
7+
from message_ix import Scenario
8+
29

10+
def main(scen: "Scenario", contin: float = 0.2) -> None:
11+
"""Update the reserve margin.
12+
13+
For a given scenario, regional reserve margin (=peak load factor) values are updated
14+
based on the electricity demand in the industry and res/comm sector.
315
4-
def main(scen, contin=0.2):
5-
"""Updates the reserve margin.
6-
For a given scenario, regional reserve margin (=peak load factor) values
7-
are updated based on the electricity demand in the industry and res/comm
8-
sector.
916
This is based on the approach described in Johnsonn et al. (2017):
10-
DOI: https://doi.org/10.1016/j.eneco.2016.07.010
11-
(see section 2.2.1. Firm capacity requirement)
17+
DOI: https://doi.org/10.1016/j.eneco.2016.07.010 (see section 2.2.1. Firm capacity
18+
requirement)
1219
1320
Parameters
1421
----------
15-
scen : :class:`message_ix.Scenario`
16-
scenario to which changes should be applied
17-
contin : float
18-
Backup capacity for contingency reasons as percentage of peak capacity
19-
(default 20%)
22+
scen :
23+
Scenario to which changes should be applied.
24+
contin :
25+
Backup capacity for contingency reasons as percentage of peak capacity (default
26+
20%).
2027
"""
21-
2228
demands = scen.par("demand")
2329
demands = (
2430
demands[demands.commodity.isin(["i_spec", "rc_spec"])]

0 commit comments

Comments
 (0)