Skip to content

Commit fd8beab

Browse files
pre-commit-ci[bot]smoia
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 661be73 commit fd8beab

File tree

6 files changed

+60
-52
lines changed

6 files changed

+60
-52
lines changed

phys2bids/cli/run.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ def _get_parser():
190190
default=False,
191191
)
192192
optional.add_argument(
193-
"-report", "--report",
193+
"-report",
194+
"--report",
194195
dest="make_report",
195196
action="store_true",
196197
help="Generate a report with the data and generated folder structure. "
197198
"Default is False.",
198199
default=False,
199200
)
200201
optional.add_argument("-v", "--version", action="version", version=("%(prog)s " + __version__))
201-
202+
202203
parser._action_groups.append(optional)
203204

204205
return parser

phys2bids/reporting/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Visual reporting tools for inspecting phys2bids workflow outputs."""
1+
"""Visual reporting tools for inspecting phys2bids workflow outputs."""

phys2bids/reporting/assets/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ html, body {
9999
.main{
100100
margin-top: 100px;
101101
margin-left: 100px;
102-
}
102+
}

phys2bids/reporting/html_report.py

+53-46
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from os.path import join
55
from pathlib import Path
66
from string import Template
7-
from bokeh.plotting import figure, ColumnDataSource
7+
88
from bokeh.embed import components
99
from bokeh.layouts import gridplot
10+
from bokeh.plotting import ColumnDataSource, figure
1011

1112
from phys2bids import _version
1213

@@ -33,14 +34,17 @@ def _save_as_html(log_html_path, log_content, qc_html_path):
3334
Saves the html file
3435
"""
3536
resource_path = Path(__file__).resolve().parent
36-
head_template_name = 'report_log_template.html'
37+
head_template_name = "report_log_template.html"
3738
head_template_path = resource_path.joinpath(head_template_name)
38-
with open(str(head_template_path), 'r') as head_file:
39+
with open(str(head_template_path), "r") as head_file:
3940
head_tpl = Template(head_file.read())
4041

41-
html = head_tpl.substitute(version=_version.get_versions()['version'],
42-
log_html_path=log_html_path, log_content=log_content,
43-
qc_html_path=qc_html_path)
42+
html = head_tpl.substitute(
43+
version=_version.get_versions()["version"],
44+
log_html_path=log_html_path,
45+
log_content=log_content,
46+
qc_html_path=qc_html_path,
47+
)
4448
return html
4549

4650

@@ -67,16 +71,18 @@ def _update_fpage_template(tree_string, bokeh_id, bokeh_js, log_html_path, qc_ht
6771
"""
6872
resource_path = Path(__file__).resolve().parent
6973

70-
body_template_name = 'report_plots_template.html'
74+
body_template_name = "report_plots_template.html"
7175
body_template_path = resource_path.joinpath(body_template_name)
72-
with open(str(body_template_path), 'r') as body_file:
76+
with open(str(body_template_path), "r") as body_file:
7377
body_tpl = Template(body_file.read())
74-
body = body_tpl.substitute(tree=tree_string,
75-
content=bokeh_id,
76-
javascript=bokeh_js,
77-
version=_version.get_versions()['version'],
78-
log_html_path=log_html_path,
79-
qc_html_path=qc_html_path)
78+
body = body_tpl.substitute(
79+
tree=tree_string,
80+
content=bokeh_id,
81+
javascript=bokeh_js,
82+
version=_version.get_versions()["version"],
83+
log_html_path=log_html_path,
84+
qc_html_path=qc_html_path,
85+
)
8086
return body
8187

8288

@@ -94,13 +100,13 @@ def _generate_file_tree(out_dir):
94100
tree_string: String with the tree of files in directory
95101
"""
96102
# prefix components:
97-
space = ' '
98-
branch = ''
103+
space = " "
104+
branch = ""
99105
# pointers:
100-
tee = '├── '
101-
last = '└── '
106+
tee = "├── "
107+
last = "└── "
102108

103-
def tree(dir_path: Path, prefix: str = ''):
109+
def tree(dir_path: Path, prefix: str = ""):
104110
"""Generate tree structure.
105111
106112
Given a directory Path object
@@ -119,9 +125,9 @@ def tree(dir_path: Path, prefix: str = ''):
119125
# i.e. space because last, └── , above so no more |
120126
yield from tree(path, prefix=prefix + extension)
121127

122-
tree_string = ''
128+
tree_string = ""
123129
for line in tree(Path(out_dir)):
124-
tree_string += line + '<br>'
130+
tree_string += line + "<br>"
125131
return tree_string
126132

127133

@@ -145,7 +151,7 @@ def _generate_bokeh_plots(phys_in, figsize=(250, 500)):
145151
--------
146152
https://phys2bids.readthedocs.io/en/latest/howto.html
147153
"""
148-
colors = ['#ff7a3c', '#008eba', '#ff96d3', '#3c376b', '#ffd439']
154+
colors = ["#ff7a3c", "#008eba", "#ff96d3", "#3c376b", "#ffd439"]
149155

150156
time = phys_in.timeseries.T[0] # assumes first phys_in.timeseries is time
151157
ch_num = len(phys_in.ch_name)
@@ -158,29 +164,30 @@ def _generate_bokeh_plots(phys_in, figsize=(250, 500)):
158164
# build a data source for each plot, with only the data + index (time)
159165
# for the purpose of reporting, data is downsampled 10x
160166
# doesn't make much of a difference to the naked eye, fine for reports
161-
source = ColumnDataSource(data=dict(
162-
x=time[::downsample],
163-
y=timeser[::downsample]))
167+
source = ColumnDataSource(data=dict(x=time[::downsample], y=timeser[::downsample]))
164168

165169
i = row + 1
166170

167-
tools = ['wheel_zoom,pan,reset']
168-
q = figure(plot_height=figsize[0], plot_width=figsize[1],
169-
tools=tools,
170-
title=f' Channel {i}: {phys_in.ch_name[i]}',
171-
sizing_mode='stretch_both')
172-
q.line('x', 'y', color=colors[i - 1], alpha=0.9, source=source)
173-
q.xaxis.axis_label = 'Time (s)'
171+
tools = ["wheel_zoom,pan,reset"]
172+
q = figure(
173+
plot_height=figsize[0],
174+
plot_width=figsize[1],
175+
tools=tools,
176+
title=f" Channel {i}: {phys_in.ch_name[i]}",
177+
sizing_mode="stretch_both",
178+
)
179+
q.line("x", "y", color=colors[i - 1], alpha=0.9, source=source)
180+
q.xaxis.axis_label = "Time (s)"
174181
# hovertool commented for posterity because I (KB) will be triumphant
175182
# eventually
176183
# q.add_tools(HoverTool(tooltips=[
177184
# (phys_in.ch_name[i], '@y{0.000} ' + phys_in.units[i]),
178185
# ('HELP', '100 :D')
179186
# ], mode='vline'))
180187
plot_list.append([q])
181-
p = gridplot(plot_list, toolbar_location='right',
182-
plot_height=250, plot_width=750,
183-
merge_tools=True)
188+
p = gridplot(
189+
plot_list, toolbar_location="right", plot_height=250, plot_width=750, merge_tools=True
190+
)
184191
script, div = components(p)
185192
return script, div
186193

@@ -207,27 +214,27 @@ def generate_report(out_dir, log_path, phys_in):
207214
https://phys2bids.readthedocs.io/en/latest/howto.html
208215
"""
209216
# Copy assets into output folder
210-
pkgdir = sys.modules['phys2bids'].__path__[0]
211-
assets_path = join(pkgdir, 'reporting', 'assets')
212-
copy_tree(assets_path, join(out_dir, 'assets'))
217+
pkgdir = sys.modules["phys2bids"].__path__[0]
218+
assets_path = join(pkgdir, "reporting", "assets")
219+
copy_tree(assets_path, join(out_dir, "assets"))
213220

214221
# Read log
215-
with open(log_path, 'r') as f:
222+
with open(log_path, "r") as f:
216223
log_content = f.read()
217224

218-
log_content = log_content.replace('\n', '<br>')
219-
log_html_path = join(out_dir, 'phys2bids_report_log.html')
220-
qc_html_path = join(out_dir, 'phys2bids_report.html')
225+
log_content = log_content.replace("\n", "<br>")
226+
log_html_path = join(out_dir, "phys2bids_report_log.html")
227+
qc_html_path = join(out_dir, "phys2bids_report.html")
221228

222229
html = _save_as_html(log_html_path, log_content, qc_html_path)
223230

224-
with open(log_html_path, 'wb') as f:
225-
f.write(html.encode('utf-8'))
231+
with open(log_html_path, "wb") as f:
232+
f.write(html.encode("utf-8"))
226233

227234
# Read in output directory structure & create tree
228235
tree_string = _generate_file_tree(out_dir)
229236
bokeh_js, bokeh_div = _generate_bokeh_plots(phys_in, figsize=(250, 750))
230237
html = _update_fpage_template(tree_string, bokeh_div, bokeh_js, log_html_path, qc_html_path)
231238

232-
with open(qc_html_path, 'wb') as f:
233-
f.write(html.encode('utf-8'))
239+
with open(qc_html_path, "wb") as f:
240+
f.write(html.encode("utf-8"))

phys2bids/reporting/report_log_template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
<p>$log_content</p>
3131
</div>
3232
</body>
33-
</html>
33+
</html>

phys2bids/reporting/report_plots_template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ <h2>phys2BIDS Output Directory</h2>
4747
</body>
4848
</html>
4949

50-
$javascript
50+
$javascript

0 commit comments

Comments
 (0)