Skip to content

Commit 7f6408e

Browse files
authored
Doc: Add citations/year figure (#3148)
Add citations/year figure. The figure is created automatically during the sphinx-build.
1 parent de6d34f commit 7f6408e

7 files changed

Lines changed: 91 additions & 8 deletions

File tree

doc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ _exhale_cpp_api/
44
examples/example_presimulation/model_presimulation/
55
generated/
66
build_doxygen/
7+
gfx/usage_by_year.png

doc/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import subprocess
1010
import sys
1111
from enum import EnumType
12+
from pathlib import Path
1213
from unittest import mock
1314

1415
import sphinx
@@ -64,6 +65,16 @@ def install_doxygen():
6465
assert version in res.stdout.decode()
6566

6667

68+
def execute_pre_sphinx_scripts():
69+
"""Execute scripts that need to be run before Sphinx is executed."""
70+
script_dir = Path(__file__).parent / "pre-sphinx.d"
71+
assert script_dir.is_dir()
72+
73+
for script in sorted(script_dir.glob("*.py")):
74+
print(f"Executing pre-Sphinx script {script}")
75+
subprocess.run([sys.executable, str(script)], check=True)
76+
77+
6778
# -- Path setup --------------------------------------------------------------
6879

6980
# If extensions (or modules to document with autodoc) are in another directory,
@@ -78,6 +89,7 @@ def install_doxygen():
7889
if "READTHEDOCS" in os.environ and os.environ["READTHEDOCS"]:
7990
install_doxygen()
8091

92+
execute_pre_sphinx_scripts()
8193

8294
# -- Project information -----------------------------------------------------
8395
# The short X.Y version
@@ -186,6 +198,7 @@ def install_doxygen():
186198
# This pattern also affects html_static_path and html_extra_path .
187199
exclude_patterns = [
188200
"_build",
201+
"pre-sphinx.d",
189202
"Thumbs.db",
190203
".DS_Store",
191204
"**.ipynb_checkpoints",

doc/pre-sphinx.d/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Pre-sphinx scripts
2+
3+
This directory contains scripts that are executed before the documentation is
4+
built by Sphinx.
5+
These scripts are used to generate content that is included in the
6+
documentation, such as tables, figures, or other data that we do not want to
7+
have under version control.
8+
The scripts are executed in lexicographical order,
9+
see [../conf.py](../conf.py) for details.

doc/pre-sphinx.d/usage_by_year.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
"""Create barplot of AMICI publications by year."""
3+
4+
from pathlib import Path
5+
6+
import matplotlib.pyplot as plt
7+
import pandas as pd
8+
9+
10+
def main():
11+
script_path = Path(__file__).parent
12+
outfile = script_path.parent / "gfx" / "usage_by_year.png"
13+
14+
# set rcParams for better readability
15+
plt.rcParams.update(
16+
{
17+
"figure.figsize": (5, 3),
18+
"figure.dpi": 150,
19+
"axes.titlesize": 14,
20+
"axes.labelsize": 12,
21+
"xtick.labelsize": 10,
22+
"ytick.labelsize": 10,
23+
}
24+
)
25+
26+
df = pd.read_csv(script_path.parent / "usage_by_year.csv")
27+
plt.bar(df.year, df.citations)
28+
plt.xlabel("Year")
29+
plt.ylabel("Citations")
30+
plt.tight_layout()
31+
plt.savefig(outfile)
32+
33+
34+
if __name__ == "__main__":
35+
main()

doc/recreate_reference_list.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
Requires pandoc
99
"""
1010

11-
import os
1211
import subprocess
1312
import sys
13+
from pathlib import Path
1414

1515
import biblib.algo
1616
import biblib.bib
1717
import biblib.messages
18+
import pandas as pd
1819

1920

20-
def get_keys_by_year(bibfile):
21+
def get_keys_by_year(bibfile: Path) -> dict[str, list[str]]:
2122
"""Get bibtex entry keys as dict by year"""
2223

2324
with open(bibfile) as f:
@@ -37,10 +38,9 @@ def get_keys_by_year(bibfile):
3738
return by_year
3839

3940

40-
def get_sub_bibliography(year, by_year, bibfile):
41+
def get_sub_bibliography(year, by_year, bibfile: Path):
4142
"""Get HTML bibliography for the given year"""
42-
43-
entries = ",".join(["@" + x for x in by_year[year]])
43+
entries = ",".join([f"@{x}" for x in by_year[year]])
4444
stdin_input = (
4545
f'---\nbibliography: {bibfile}\nnocite: "{entries}"\n...\n# {year}'
4646
)
@@ -58,9 +58,9 @@ def get_sub_bibliography(year, by_year, bibfile):
5858

5959

6060
def main():
61-
script_path = os.path.dirname(os.path.realpath(__file__))
62-
bibfile = os.path.join(script_path, "amici_refs.bib")
63-
outfile = os.path.join(script_path, "references.md")
61+
script_path = Path(__file__).parent
62+
bibfile = script_path / "amici_refs.bib"
63+
outfile = script_path / "references.md"
6464

6565
by_year = get_keys_by_year(bibfile)
6666
num_total = sum(map(len, by_year.values()))
@@ -77,6 +77,7 @@ def main():
7777
"?labels=documentation&title=Add+publication"
7878
"&body=AMICI+was+used+in+this+manuscript:+DOI).\n\n"
7979
)
80+
f.write("![AMICI usage over time](gfx/usage_by_year.png)\n\n")
8081
f.write(
8182
"""
8283
<style>
@@ -86,10 +87,19 @@ def main():
8687
</style>\n
8788
"""
8889
)
90+
8991
for year in reversed(sorted(by_year.keys())):
9092
cur_bib = get_sub_bibliography(year, by_year, bibfile)
9193
f.write(cur_bib)
9294

95+
# Save table with citations / year
96+
years = list(sorted(by_year.keys()))
97+
citations = [len(by_year[year]) for year in years]
98+
99+
pd.DataFrame({"year": years, "citations": citations}).to_csv(
100+
script_path / "usage_by_year.csv", index=False
101+
)
102+
93103

94104
if __name__ == "__main__":
95105
main()

doc/references.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ List of publications using AMICI. Total number is 111.
55
If you applied AMICI in your work and your publication is missing, please let us know via a new
66
[GitHub issue](https://github.com/AMICI-dev/AMICI/issues/new?labels=documentation&title=Add+publication&body=AMICI+was+used+in+this+manuscript:+DOI).
77

8+
![AMICI usage over time](gfx/usage_by_year.png)
9+
810

911
<style>
1012
.csl-entry {

doc/usage_by_year.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
year,citations
2+
2015,1
3+
2016,6
4+
2017,5
5+
2018,11
6+
2019,12
7+
2020,11
8+
2021,13
9+
2022,10
10+
2023,12
11+
2024,15
12+
2025,14
13+
2026,1

0 commit comments

Comments
 (0)