Skip to content

Commit

Permalink
used tables in docs for dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
swillner committed Apr 26, 2017
1 parent 03a01d5 commit 294a5b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ matplotlib
sphinx
sphinx-autobuild
numpydoc
tabulate
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def setup(app):
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#
# html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------
Expand Down
37 changes: 21 additions & 16 deletions docs/pyhector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ the respective component.

.. exec::
from pyhector import emissions
sorted_emissions = sorted(emissions.items())
for item in sorted_emissions:
print("- ``{}``: {}".format(item[0], item[1]))
from tabulate import tabulate
print(tabulate(map(lambda item: ("``%s``" % item[0],
", ".join(map(lambda i: "``%s``" % i, item[1]))),
sorted(emissions.items())),
["component", "emissions"],
tablefmt="grid"))

pyhector.output
---------------

A dictionary with Hector's available output variables
A dictionary with Hector's available output variables::

output = {
'C2F6_halocarbon.hc_concentration': {
Expand All @@ -43,20 +46,18 @@ A dictionary with Hector's available output variables
},
[...]

Full list below, sorted by dictionary key "component.variable", showing
description and the associated unit:

.. exec::
from pyhector import output
template = "- ``{}.{}``, {}, {}"
from tabulate import tabulate
sorted_output = sorted(output.items(),
key=output.get("component"))
for item in sorted_output:
print(template.format(
item[1]["component"],
item[1]["variable"],
item[1]["description"],
item[1]["unit"]))
print(tabulate(map(lambda item: ("``%s``" % item[1]["component"],
"``%s``" % item[1]["variable"],
item[1]["description"],
"``%s``" % item[1]["unit"]),
sorted_output),
["component", "variable", "description", "unit"],
tablefmt="grid"))

pyhector.units
--------------
Expand All @@ -65,5 +66,9 @@ A dictionary with emissions categories and their associated units.

.. exec::
from pyhector import units
for key, value in sorted(units.items()):
print("- ``{}``: {}\n".format(key, value))
from tabulate import tabulate
print(tabulate(map(lambda item: ("``%s``" % item[0],
"``%s``" % item[1]),
sorted(units.items())),
["emissions", "unit"],
tablefmt="grid"))

0 comments on commit 294a5b6

Please sign in to comment.