-
Notifications
You must be signed in to change notification settings - Fork 0
/
citation_number.py
161 lines (129 loc) · 4.36 KB
/
citation_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/venv/bin python
# citation_number.py
"""Script to generate plots of number of citations per group.
To use:
Copy the source data files to a subfolder.
Edit the settings section.
Activate the virtual environment.
Run this python script.
"""
import os
import glob
import pandas as pd
import plotly.graph_objects as go
# SETTINGS
DATA_PATH = "data/data2022/cite_data" # The relative path to the data files.
OUTPUT_PATH = "reports2022/Plots" # The relative path to the output folder.
YEARS_RANGE = [2017, 2022] # The range of years to consider for processing.
def run():
"""Runs the script for all discovered files in the configured data path."""
years = range(YEARS_RANGE[0], YEARS_RANGE[1] + 1)
filenames = glob.glob(DATA_PATH + "/SciLifeLab-*.xlsx")
if len(filenames) == 0:
print("No input files found. Exiting.")
return
for file in filenames:
print(f"Now processing file {file}")
pub_group = file.split("-")[1]
df = pd.read_excel(
file,
sheet_name="citations_per_year",
header=0,
engine="openpyxl",
keep_default_na=False,
)
# Last 5 years
data_sub = df[
[
f"citations_self_excl_{years[0]}",
f"citations_self_excl_{years[1]}",
f"citations_self_excl_{years[2]}",
f"citations_self_excl_{years[3]}",
f"citations_self_excl_{years[4]}",
f"citations_self_excl_{years[5]}",
]
]
data_sum = data_sub.sum(axis=0, skipna=True)
data_group = data_sum.to_frame(
name="sum_val",
)
data_group["Citation_Year"] = data_group.index
data_group.reset_index(drop=True, inplace=True)
# print(data_group)
__create_citation_graph(data_group, pub_group, years)
print(f"Done. Any generaed plots were saved to output path {OUTPUT_PATH}")
# Private functions
def __create_citation_graph(citations, pub_group, years):
"""Creates a citation graph for a single publication group.
:param dataframe citations: A dataframe containing the input data.
:param string pub_group: The name of the publication group.
:param range years: A range of int of the years to plot.
"""
# # Create graph function
# def Citation_graph_func(input, pub_group):
# Citation = input
# # Make bar chart
# fig = go.Figure(
# go.Bar(
# x=Citation.Citation_Year,
# y=Citation.sum_val,
# marker=dict(color="#A7C947", line=dict(color="#000000", width=1)),
# )
# )
# fig.update_layout(
# plot_bgcolor="white",
# autosize=False,
# font=dict(size=75),
# margin=dict(r=250, t=0, b=0, l=0),
# width=2500,
# height=1700,
# showlegend=False,
# )
# # add more years as needed
# Citation_year = Citation["Citation_Year"].unique()
# fig.update_xaxes(
# title=" ",
# showgrid=True,
# linecolor="black",
# # add more years as needed
# ticktext=[
# "<b>2016</b>",
# "<b>2017</b>",
# "<b>2018</b>",
# "<b>2019</b>",
# "<b>2020</b>",
# "<b>2021</b>",
# ],
# tickvals=[
# Citation_year[0],
# Citation_year[1],
# Citation_year[2],
# Citation_year[3],
# Citation_year[4],
# Citation_year[5],
# ],
# )
# highest_y_value = max(Citation["sum_val"])
# if highest_y_value > 50000:
# yaxis_tick = 10000
# if highest_y_value > 20000:
# yaxis_tick = 5000
# if highest_y_value <= 10000:
# yaxis_tick = 1000
# # modify y-axis
# fig.update_yaxes(
# title=" ",
# showgrid=True,
# gridcolor="lightgrey",
# linecolor="black",
# dtick=yaxis_tick,
# range=[0, float(highest_y_value * 1.15)],
# )
# if not os.path.isdir("Plots/"):
# os.mkdir("Plots/")
# # fig.show()
# fig.write_image("Plots/{}_Citation_eachyear.png".format(pub_group))
# fig.write_image("Plots/{}_Citation_eachyear.svg".format(pub_group))
# Citation_graph_func(Affiliates_data_group, "Affiliates")
# Citation_graph_func(Infra_data_group, "Infra")
# # Citation_graph_func(Fellows_data_group, "Fellows")